Skip to content

Commit

Permalink
review 2
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Mar 3, 2021
1 parent 94bb357 commit 03a6ccd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 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": "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": "cross-env NODE_ENV=production yarn test:regressions:build && 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
28 changes: 13 additions & 15 deletions test/regressions/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fse from 'fs-extra';
import { expect } from 'chai';
import * as path from 'path';
import * as playwright from 'playwright';

Expand Down Expand Up @@ -28,7 +29,7 @@ async function main() {

let errorConsole;

page.on('console', async (msg) => {
page.on('console', (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 = msg.text();
Expand Down Expand Up @@ -65,6 +66,12 @@ async function main() {
await browser.close();
});

it('should have no errors after the initial render', () => {
const msg = errorConsole;
errorConsole = undefined;
expect(msg).to.equal(undefined);
});

routes.forEach((route, index) => {
const pathURL = route.replace(baseUrl, '');

Expand All @@ -91,21 +98,12 @@ async function main() {
const screenshotPath = path.resolve(screenshotDir, `${route.replace(baseUrl, '.')}.png`);
await fse.ensureDir(path.dirname(screenshotPath));
await testcase.screenshot({ path: screenshotPath, type: 'png' });
});

if (errorConsole) {
const msg = errorConsole;
errorConsole = undefined;

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);
}
}
it(`should have no errors rendering ${pathURL}`, () => {
const msg = errorConsole;
errorConsole = undefined;
expect(msg).to.equal(undefined);
});
});
});
Expand Down

0 comments on commit 03a6ccd

Please sign in to comment.