diff --git a/package.json b/package.json index 75456caf7a25f7..2b626da0439d4a 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=html mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}' 'scripts/**/*.test.{js,ts,tsx}' 'test/utils/**/*.test.{js,ts,tsx}'", "test:karma": "cross-env NODE_ENV=test karma start test/karma.conf.js", "test:karma:profile": "cross-env NODE_ENV=test karma start test/karma.conf.profile.js", - "test:regressions": "yarn test:regressions:build && concurrently --success first --kill-others \"yarn test:regressions:run\" \"yarn test:regressions:server\"", + "test:regressions": "cross-env NODE_ENV=production yarn test:regressions:build && cross-env NODE_ENV=production concurrently --success first --kill-others \"yarn test:regressions:run\" \"yarn test:regressions:server\"", "test:regressions:build": "webpack --config test/regressions/webpack.config.js", "test:regressions:dev": "concurrently \"yarn test:regressions:build --watch\" \"yarn test:regressions:server\"", "test:regressions:run": "mocha --config test/regressions/.mocharc.js --delay 'test/regressions/**/*.test.js'", diff --git a/test/regressions/index.test.js b/test/regressions/index.test.js index 3052ecaba7e11b..a06a48052f3271 100644 --- a/test/regressions/index.test.js +++ b/test/regressions/index.test.js @@ -2,8 +2,6 @@ import * as fse from 'fs-extra'; import * as path from 'path'; import * as playwright from 'playwright'; -const ERROR_THRESHOLD = 2; - async function main() { const baseUrl = 'http://localhost:5000'; const screenshotDir = path.resolve(__dirname, './screenshots/chrome'); @@ -29,11 +27,11 @@ async function main() { }); let errorConsole; - let errorConsoleCounter = 0; page.on('console', async (msg) => { + // Filter out native user-agent errors e.g. "Failed to load resource: net::ERR_FAILED" if (msg.args().length > 0 && (msg.type() === 'error' || msg.type() === 'warning')) { - errorConsole = Promise.all(msg.args().map((x) => x.jsonValue())); + errorConsole = msg.text(); } }); @@ -95,31 +93,23 @@ async function main() { await testcase.screenshot({ path: screenshotPath, type: 'png' }); if (errorConsole) { - const msg = await errorConsole; + const msg = errorConsole; errorConsole = undefined; - // eslint-disable-next-line no-console - console.log(`⚠️ Error logged in the console in ${pathURL}:\n`); - // eslint-disable-next-line no-console - console.log(msg.join('\n')); - errorConsoleCounter += 1; + + if (process.env.NODE_ENV === 'production') { + // It can only throw in production mode as some errors are only logged in development mode. + throw new Error(msg); + } else { + // eslint-disable-next-line no-console + console.log(`⚠️ Error logged in the console in ${pathURL}:\n`); + // eslint-disable-next-line no-console + console.log(msg); + } } }); }); }); - describe('no console errors', () => { - it(`should have fewer than ${ERROR_THRESHOLD} console errors`, () => { - if (errorConsoleCounter > 0) { - // eslint-disable-next-line no-console - console.log(`${errorConsoleCounter} errors have been logged in the console.`); - } - - if (errorConsoleCounter > ERROR_THRESHOLD) { - throw new Error(`More than ${ERROR_THRESHOLD} errors have been logged in the console.`); - } - }); - }); - run(); }