Skip to content

Commit

Permalink
Run tests on ready (all workers started)
Browse files Browse the repository at this point in the history
Closes: #1919
  • Loading branch information
tshemsedinov committed Oct 10, 2023
1 parent 9324d9b commit c521b85
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,23 @@ class Application extends EventEmitter {
if (mode === 'test' && threadId === 1) this.runTests();
}

runTests() {
async runTests() {
const { test, tests, config, console } = this;
const timer = setTimeout(() => {
console.error('🔴 Test execution timed out');
wt.parentPort.postMessage({ name: 'terminate', code: 1 });
}, config.server.timeouts.test);
await node.events.once(this, 'ready');
const cases = tests.map((t) => node.test(t.name, t.run));
this.parallel(cases, ERR_TEST).then(() => {
clearTimeout(timer);
setTimeout(() => {
const { passed, failed } = test;
const msg = `Passed ${passed}, Failed: ${failed}`;
if (failed > 0) console.error('🔴 ' + msg);
else console.debug('🟢 ' + msg);
const code = failed === 0 ? 0 : 1;
wt.parentPort.postMessage({ name: 'terminate', code });
}, TEST_DELAY);
});
await this.parallel(cases, ERR_TEST);
await metarhia.metautil.delay(TEST_DELAY);
clearTimeout(timer);
const { passed, failed } = test;
const msg = `Passed ${passed}, Failed: ${failed}`;
if (failed > 0) console.error('🔴 ' + msg);
else console.debug('🟢 ' + msg);
const code = failed === 0 ? 0 : 1;
wt.parentPort.postMessage({ name: 'terminate', code });
}

async shutdown() {
Expand Down

0 comments on commit c521b85

Please sign in to comment.