diff --git a/index.js b/index.js index 8ee376d..2d6e5c0 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/package-lock.json b/package-lock.json index 6187533..e97517f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "html-metadata", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "html-metadata", - "version": "3.0.0", + "version": "3.0.1", "license": "MIT", "dependencies": { "cheerio": "1.0.0-rc.12", @@ -228,27 +228,27 @@ } }, "node_modules/@babel/helpers": { - "version": "7.26.9", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.26.9.tgz", - "integrity": "sha512-Mz/4+y8udxBKdmzt/UjPACs4G3j5SshJJEFFKxlCGPydG4JAHXxjWjAwjd09tf6oINvl1VfMJo+nB7H2YKQ0dA==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.27.0.tgz", + "integrity": "sha512-U5eyP/CTFPuNE3qk+WZMxFkp/4zUzdceQlfzf7DdGdhp+Fezd7HD+i8Y24ZuTMKX3wQBld449jijbGq6OdGNQg==", "dev": true, "license": "MIT", "dependencies": { - "@babel/template": "^7.26.9", - "@babel/types": "^7.26.9" + "@babel/template": "^7.27.0", + "@babel/types": "^7.27.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/parser": { - "version": "7.26.9", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.9.tgz", - "integrity": "sha512-81NWa1njQblgZbQHxWHpxxCzNsa3ZwvFqpUg7P+NNUU6f3UU2jBEg4OlF/J6rl8+PQGh1q6/zWScd001YwcA5A==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.0.tgz", + "integrity": "sha512-iaepho73/2Pz7w2eMS0Q5f83+0RKI7i4xmiYeBmDzfRVbQtTOG7Ts0S4HzJVsTMGI9keU8rNfuZr8DKfSt7Yyg==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.26.9" + "@babel/types": "^7.27.0" }, "bin": { "parser": "bin/babel-parser.js" @@ -258,15 +258,15 @@ } }, "node_modules/@babel/template": { - "version": "7.26.9", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.26.9.tgz", - "integrity": "sha512-qyRplbeIpNZhmzOysF/wFMuP9sctmh2cFzRAZOn1YapxBsE1i9bJIY586R/WBLfLcmcBlM8ROBiQURnnNy+zfA==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.0.tgz", + "integrity": "sha512-2ncevenBqXI6qRMukPlXwHKHchC7RyMuu4xv5JBXRfOGVcTy1mXCD12qrp7Jsoxll1EV3+9sE4GugBVRjT2jFA==", "dev": true, "license": "MIT", "dependencies": { "@babel/code-frame": "^7.26.2", - "@babel/parser": "^7.26.9", - "@babel/types": "^7.26.9" + "@babel/parser": "^7.27.0", + "@babel/types": "^7.27.0" }, "engines": { "node": ">=6.9.0" @@ -302,9 +302,9 @@ } }, "node_modules/@babel/types": { - "version": "7.26.9", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.9.tgz", - "integrity": "sha512-Y3IR1cRnOxOCDvMmNiym7XpXQ93iGDDPHx+Zj+NM+rg0fBaShfQLkg+hKPaZCEvg5N/LeCo4+Rj/i3FuJsIQaw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.27.0.tgz", + "integrity": "sha512-H45s8fVLYjbhFH62dIJ3WtmJ6RSPt/3DRO0ZcT2SUiYiQyz3BLVb9ADEnLl91m74aQPS3AzzeajZHYOalWe3bg==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 917b810..4018877 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/scraping.js b/test/scraping.js index d9bdb2a..4475919 100644 --- a/test/scraping.js +++ b/test/scraping.js @@ -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 ) => { @@ -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' ); } ) @@ -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', () => {