Skip to content

Commit 5ba5db8

Browse files
author
NarrowsProjects
committed
test push
1 parent 4cd301a commit 5ba5db8

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"sequelize": "sequelize-cli",
1515
"start:dev": "nodemon --ignore 'lib/public/**/*.js' lib/main.js",
1616
"start:prod": "node lib/main.js",
17-
"test": "mocha --exit --timeout 0",
17+
"test": "mocha --exit --timeout 0 --require ./test/hooks.js",
1818
"test:subset": "nyc -- mocha --exit --timeout 0 test/scripts/test-${TEST_TYPE}.js && nyc report --report-dir=/usr/src/app/coverage/${TEST_TYPE} --reporter=json",
1919
"test:subset-local": "mocha --exit --timeout 0 --reporter test/scripts/parallel-local/custom-mocha-reporter.js test/scripts/test-${TEST_TYPE}.js",
2020
"docker-run": "docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build",

test/hooks.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { takeScreenshot, getActivePage } = require("./public/defaults");
2+
3+
exports.mochaHooks = {
4+
afterEach: async function () {
5+
if (this.currentTest.state === 'failed') {
6+
const testName = this.currentTest.fullTitle().replace(/[\s/:"]+/g, '_').replace('Bookkeeping_Integration_Suite_UI_', '');
7+
const page = getActivePage();
8+
if (page) {
9+
const imageName = `FAILED_${testName}`;
10+
console.error(`Error caught in afterEach hook, saving a screenshot to ${imageName}`);
11+
const html = await page.content();
12+
13+
console.log(html);
14+
15+
}
16+
}
17+
},
18+
};

test/public/defaults.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ const authenticateUrl = (url) => {
5050
*/
5151
const getUrl = () => `http://localhost:${server.address().port}`;
5252

53+
let _page = null;
54+
module.exports.getActivePage = () => _page;
55+
5356
/**
5457
* Constructor to build elements before tests start.
5558
*
@@ -66,6 +69,8 @@ module.exports.defaultBefore = async () => {
6669
page.coverage.startCSSCoverage(),
6770
]);
6871

72+
_page = page;
73+
6974
return [page, browser, getUrl()];
7075
};
7176

@@ -85,6 +90,8 @@ module.exports.defaultAfter = async (page, browser) => {
8590
includeHostname: false,
8691
storagePath: './.nyc_output/lib/public',
8792
});
93+
94+
_page = null;
8895
await browser.close();
8996

9097
return [page, browser];

0 commit comments

Comments
 (0)