Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ exports = module.exports = function ( urlOrOpts ) {
url = urlOrOpts.uri;
}
opts = urlOrOpts;
} else if ( typeof urlOrOpts === String ) {
} else if ( typeof urlOrOpts === 'string' ) {
url = urlOrOpts;
}
if ( !url ) {
reject( 'No uri supplied in argument' );
reject( new Error( 'No uri supplied in argument' ) );
} else {
resolve(
// eslint-disable-next-line n/no-unsupported-features/node-builtins
Expand Down
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-metadata",
"version": "3.0.0",
"version": "3.0.1",
"description": "Scrapes metadata of several different standards",
"main": "index.js",
"dependencies": {
Expand Down
39 changes: 36 additions & 3 deletions test/scraping.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe( 'scraping', function () {
}

describe( 'parseAll function', () => {
it( 'should resolve promise from woorank', () => {
it( 'should resolve promise from woorank with headers', () => {
const url = 'https://www.woorank.com/en/blog/dublin-core-metadata-for-seo-and-usability';
return meta( { uri: url, headers: { 'User-Agent': userAgent, Accept: acceptHeader } } )
.then( ( result ) => {
Expand All @@ -39,9 +39,9 @@ describe( 'scraping', function () {
} );
} );

it( 'should resolve promise from blog.schema.org', () => {
it( 'should resolve promise from blog.schema.org without headers', () => {
const url = 'http://blog.schema.org';
return meta( { uri: url, headers: { 'User-Agent': userAgent, Accept: acceptHeader } } )
return meta( url )
.then( ( result ) => {
assert.ok( result, 'Expected result to be truthy' );
} )
Expand All @@ -50,6 +50,39 @@ describe( 'scraping', function () {
throw e;
} );
} );

it( 'should throw error if no uri supplied', () => meta()
.then( () => {
assert.fail( 'Should have rejected the promise' );
} )
.catch( ( e ) => {
assert.ok( e instanceof Error, 'Error should be an Error object' );
assert.strictEqual( e.message, 'No uri supplied in argument', 'Error message should match expected message' );
} )
);

it( 'should support await implementation with headers', async () => {
const url = 'http://blog.schema.org';
const result = await meta( { uri: url, headers: { 'User-Agent': userAgent, Accept: acceptHeader } } );
assert.ok( result, 'Expected result to be truthy' );
} );

it( 'should support await implementation without headers', async () => {
const url = 'http://blog.schema.org';
const result = await meta( url );
assert.ok( result, 'Expected result to be truthy' );
} );

it( 'should throw error if no uri is supplied with async/await', async () => {
try {
await meta();
assert.fail( 'Should have thrown an error' );
} catch ( e ) {
assert.ok( e instanceof Error, 'Error should be an Error object' );
assert.strictEqual( e.message, 'No uri supplied in argument', 'Error message should match expected message' );
}
} );

} );

describe( 'parseBEPress function', () => {
Expand Down