Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Adding error handling to the test setup (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
axelssonHakan committed Jan 29, 2019
1 parent e281e7e commit ddb4cfe
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/e2e/_setup.spec.js
@@ -1,9 +1,12 @@
/* global before, after */
/* eslint no-plusplus: ["error", { "allowForLoopAfterthoughts": true }] */

const fs = require('fs-extra');
const NYC = require('nyc');
const wsHelper = require('./test-helper');

let coverageFlag = false;

before(async () => {
await fs.emptyDir('.nyc_output');
});
Expand Down Expand Up @@ -33,11 +36,37 @@ beforeEach(async () => {
/* eslint-disable-next-line */
afterEach(async function () {
const coverage = await page.evaluate(() => window.__coverage__);
return fs.writeJson(`.nyc_output/${new Date().getTime()}.json`, coverage);
if (coverage) {
coverageFlag = true;
await fs.writeJson(`.nyc_output/${new Date().getTime()}.json`, coverage);
}

const ignoreAsserts = (message) => {
const errors2skip = ['No baseline found!', 'equality to be less than'];
let found = false;

for (let index = 0; index < errors2skip.length; index++) {
if (message.includes(errors2skip[index])) {
found = true;
break;
}
}

return found;
};

if (this.currentTest.state === 'failed' && !ignoreAsserts(this.currentTest.err.message)) {
const fullname = await this.currentTest.fullTitle();
await page.screenshot({ fullPage: true, path: `${OPTS.artifactsPath}${fullname}.png` });
}
});

after(async () => {
const nyc = new NYC();
await nyc.report();
if (!coverageFlag) {
console.log('\u001b[31m The code hasn´t been instrumented! Please start the server with `npm run start:cov`\u001b[0m'); // eslint-disable-line no-console
}

await browser.close();
});

0 comments on commit ddb4cfe

Please sign in to comment.