diff --git a/src/integration/utils/customResourceLoader.js b/src/integration/utils/customResourceLoader.js new file mode 100644 index 00000000000..e334a243a2f --- /dev/null +++ b/src/integration/utils/customResourceLoader.js @@ -0,0 +1,16 @@ +const jsdom = require('jsdom'); + +class CustomResourceLoader extends jsdom.ResourceLoader { + fetch(url, options) { + if ( + url === + 'https://mybbc-analytics.files.bbci.co.uk/reverb-client-js/reverb-3.9.2.js' + ) { + return super.fetch(url, options); + } + + return null; + } +} + +module.exports = CustomResourceLoader; diff --git a/src/integration/utils/fetchDom.js b/src/integration/utils/fetchDom.js index 6b831795058..00a68be1a7c 100644 --- a/src/integration/utils/fetchDom.js +++ b/src/integration/utils/fetchDom.js @@ -8,6 +8,8 @@ dns.setDefaultResultOrder('ipv4first'); const { JSDOM } = require('jsdom'); const retry = require('retry'); +const CustomResourceLoader = require('./customResourceLoader'); + const faultTolerantDomFetch = ({ url, runScripts, headers }) => new Promise((resolve, reject) => { const oneSecond = 1000; @@ -31,7 +33,12 @@ const faultTolerantDomFetch = ({ url, runScripts, headers }) => const html = await response.text(); const dom = new JSDOM(html, { url, - ...(runScripts ? { runScripts: 'dangerously' } : {}), + ...(runScripts + ? { + runScripts: 'dangerously', + resources: new CustomResourceLoader(), + } + : {}), }); resolve(dom);