Skip to content

Commit 3dbb234

Browse files
debug
1 parent 2eda982 commit 3dbb234

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

tests/zenko_tests/node_tests/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"reporterEnabled": "spec, mocha-junit-reporter",
33
"mochaJunitReporterReporterOptions": {
44
"mochaFile": "junit-node-[hash].xml"
5-
}
5+
},
6+
"require": "hooks.js"
67
}

tests/zenko_tests/node_tests/hooks.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const console = require('console');
2+
3+
const currentTests = {};
4+
5+
function onInterrupt(reason) {
6+
console.error(`\n\n${reason} with ${Object.keys(currentTests).length} running tests:`);
7+
Object.entries(currentTests).forEach(([test, startTime]) => {
8+
const duration = Date.now() - startTime.getTime();
9+
console.error(` - ${test}: started at ${startTime}, duration so far: ${duration}ms`);
10+
});
11+
process.exit(1);
12+
}
13+
14+
// --> not working... maybe due to run-p or containerized environment? (no root process)
15+
process.on('SIGINT', () => onInterrupt('ABORTED'));
16+
process.on('SIGKILL', () => onInterrupt('KILLED'));
17+
process.on('SIGTERM', () => onInterrupt('TERMINATED'));
18+
19+
setInterval(() => {
20+
Object.entries(currentTests).forEach(([test, startTime]) => {
21+
const duration = Date.now() - startTime.getTime();
22+
if (duration > 300000) {
23+
console.error(` ${test}: started at ${startTime}, duration so far: ${duration}ms`);
24+
}
25+
});
26+
}, 300000);
27+
28+
exports.mochaHooks = {
29+
beforeEach(done) {
30+
// TODO: allocate a UUID for the test (trace id) ; which should be added to **every** outgoing request
31+
32+
const currentTest = this.currentTest.fullTitle();
33+
currentTests[currentTest] = new Date();
34+
console.log(`Starting: ${currentTest}`);
35+
36+
done();
37+
},
38+
afterEach(done) {
39+
// TODO: if the test failed, log this tests' traceID
40+
// TODO: also gather the logs and print them? (or generate a report, so that GHA can extract
41+
// and display these logs)
42+
43+
const currentTest = this.currentTest.fullTitle();
44+
delete currentTests[currentTest];
45+
46+
done();
47+
},
48+
};

0 commit comments

Comments
 (0)