diff --git a/packages/metascraper-audio/package.json b/packages/metascraper-audio/package.json index 903936e6b..7488e36a1 100644 --- a/packages/metascraper-audio/package.json +++ b/packages/metascraper-audio/package.json @@ -40,5 +40,11 @@ "scripts": { "test": "NODE_PATH=.. TZ=UTC ava --timeout 15s" }, - "license": "MIT" + "license": "MIT", + "ava": { + "files": [ + "test/**/*.js", + "!test/helpers.js" + ] + } } diff --git a/packages/metascraper-audio/test/helpers.js b/packages/metascraper-audio/test/helpers.js new file mode 100644 index 000000000..f8e39b93b --- /dev/null +++ b/packages/metascraper-audio/test/helpers.js @@ -0,0 +1,24 @@ +'use strict' + +const { default: listen } = require('async-listen') +const { createServer } = require('http') + +const closeServer = server => + require('util').promisify(server.close.bind(server))() + +const runServer = async (t, handler, opts) => { + const server = createServer(async (req, res) => { + try { + await handler({ req, res }) + } catch (error) { + console.error(error) + res.statusCode = 500 + res.end() + } + }) + const url = await listen(server, { port: 0, host: '0.0.0.0', ...opts }) + t.teardown(() => closeServer(server)) + return url.toString() +} + +module.exports = { runServer } diff --git a/packages/metascraper-audio/test/iframe.js b/packages/metascraper-audio/test/iframe.js index 88678a4d8..9418d8259 100644 --- a/packages/metascraper-audio/test/iframe.js +++ b/packages/metascraper-audio/test/iframe.js @@ -1,25 +1,19 @@ 'use strict' -const { default: listen } = require('async-listen') -const { createServer } = require('http') const test = require('ava') -const closeServer = server => - require('util').promisify(server.close.bind(server))() +const { runServer } = require('./helpers') const createMetascraper = (...args) => require('metascraper')([require('../src')(...args)]) test('absolute http', async t => { - const server = createServer((_, res) => { + const url = await runServer(t, ({ res }) => { res.setHeader('Content-Type', 'text/html') res.end( '' ) }) - - t.teardown(() => closeServer(server)) - const url = (await listen(server, { port: 0, host: '0.0.0.0' })).toString() const html = ` - - - -
Recommended
-
- - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - You've successfully subscribed to Geektime! -
- -
- - -
- - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/packages/metascraper/test/integration/geek-time/snapshots/index.js.md b/packages/metascraper/test/integration/geek-time/snapshots/index.js.md deleted file mode 100644 index 03273c9bc..000000000 --- a/packages/metascraper/test/integration/geek-time/snapshots/index.js.md +++ /dev/null @@ -1,23 +0,0 @@ -# Snapshot report for `test/integration/geek-time/index.js` - -The actual snapshot is saved in `index.js.snap`. - -Generated by [AVA](https://avajs.dev). - -## geek-time - -> Snapshot 1 - - { - audio: null, - author: 'Guest Contributor', - date: '2023-01-12T12:07:56.000Z', - description: 'The global markets are experiencing close to a 1-year long turmoil that involves high inflation rates, increasing interest rates, a bear stock market, and growing expectations for a recession, as demonstrated by inverse US-bond yield curves.', - image: 'https://images.unsplash.com/photo-1542751371-adc38448a05e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fGdhbWluZ3xlbnwwfHx8fDE2NzMyNzE0NDE&ixlib=rb-4.0.3&q=80&w=2000content/images/size/w1200', - lang: 'en', - logo: 'https://www.geektime.com/content/images/size/w256h256/2022/04/icon-andro.png', - publisher: 'Geektime', - title: 'Have the bells tolled for the game market or is it a false alarm?', - url: 'https://www.geektime.com/gaming-market-2023/', - video: null, - } diff --git a/packages/metascraper/test/integration/geek-time/snapshots/index.js.snap b/packages/metascraper/test/integration/geek-time/snapshots/index.js.snap deleted file mode 100644 index e3a2dcafd..000000000 Binary files a/packages/metascraper/test/integration/geek-time/snapshots/index.js.snap and /dev/null differ diff --git a/packages/metascraper/test/integration/postplanner/snapshots/index.js.md b/packages/metascraper/test/integration/postplanner/snapshots/index.js.md index 544ad810a..f4924d8d9 100644 --- a/packages/metascraper/test/integration/postplanner/snapshots/index.js.md +++ b/packages/metascraper/test/integration/postplanner/snapshots/index.js.md @@ -15,7 +15,7 @@ Generated by [AVA](https://avajs.dev). description: 'Want to get more Likes on Facebook in 2021? No problem. To increase Likes on your FB page, you need to boost Likes on your FB posts. Here’s how to do that.', image: 'https://www.postplanner.com/hubfs/blog/11_Ways_to_Get_Lots_of_Likes_on_Facebook_(the_right_way)/11%20Ways%20to%20Get%20Lots%20of%20Likes%20on%20Facebook%20(the%20right%20way!!)%20hero.png#keepProtocol', lang: null, - logo: 'https://www.postplanner.com/favicon.ico', + logo: 'https://cdn2.hubspot.net/hubfs/513577/v2/global/favicon.ico', publisher: 'Post Planner', title: 'Here’s How to Get More Likes on Facebook in 2021 (and Reach Millions)', url: 'https://www.postplanner.com/get-more-likes-fans-facebook-page/', diff --git a/packages/metascraper/test/integration/postplanner/snapshots/index.js.snap b/packages/metascraper/test/integration/postplanner/snapshots/index.js.snap index b11d77998..a28312b7f 100644 Binary files a/packages/metascraper/test/integration/postplanner/snapshots/index.js.snap and b/packages/metascraper/test/integration/postplanner/snapshots/index.js.snap differ diff --git a/packages/metascraper/test/integration/segment/index.js b/packages/metascraper/test/integration/segment/index.js index fd6e52a5f..453482418 100644 --- a/packages/metascraper/test/integration/segment/index.js +++ b/packages/metascraper/test/integration/segment/index.js @@ -26,5 +26,6 @@ const url = 'https://segment.com/blog/scaling-nsq' test('segment', async t => { const html = await readFile(resolve(__dirname, 'input.html')) const metadata = await metascraper({ html, url }) + metadata.logo.replace('t3.gstatic.com', 't1.gstatic.com') t.snapshot(metadata) }) diff --git a/packages/metascraper/test/integration/segment/snapshots/index.js.md b/packages/metascraper/test/integration/segment/snapshots/index.js.md index 4a2fcdd4b..430450f8f 100644 --- a/packages/metascraper/test/integration/segment/snapshots/index.js.md +++ b/packages/metascraper/test/integration/segment/snapshots/index.js.md @@ -15,7 +15,7 @@ Generated by [AVA](https://avajs.dev). description: 'Segment is the analytics API you’ve always wanted. It’s the easiest way to install all of your favorite analytics tools at once!', image: 'https://c19f7be2e84987e7904e-bf41efcb49679c193a4ec0f3210da86f.ssl.cf1.rackcdn.com/photos/40528-1-1.jpg', lang: null, - logo: 'https://segment.com/favicon.ico', + logo: 'https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://segment.com/blog/scaling-nsq&size=128', publisher: 'Segment Blog', title: 'Scaling NSQ to 750 Billion Messages', url: 'https://segment.com/blog/scaling-nsq', diff --git a/packages/metascraper/test/integration/segment/snapshots/index.js.snap b/packages/metascraper/test/integration/segment/snapshots/index.js.snap index 5482935a0..41945f377 100644 Binary files a/packages/metascraper/test/integration/segment/snapshots/index.js.snap and b/packages/metascraper/test/integration/segment/snapshots/index.js.snap differ