From c521b85b82c154ace3d81067d33b4a223cac67f2 Mon Sep 17 00:00:00 2001 From: Timur Shemsedinov Date: Tue, 10 Oct 2023 13:17:50 +0300 Subject: [PATCH] Run tests on `ready` (all workers started) Closes: https://github.com/metarhia/impress/issues/1919 --- lib/application.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/application.js b/lib/application.js index 2c796705..635c269e 100644 --- a/lib/application.js +++ b/lib/application.js @@ -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() {