Skip to content

Commit

Permalink
Sebastian's review
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Mar 2, 2021
1 parent 2075605 commit 94bb357
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
36 changes: 13 additions & 23 deletions test/regressions/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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();
}
});

Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 94bb357

Please sign in to comment.