Skip to content

Commit 4a19a42

Browse files
author
Willian Cardoso
committed
fix: new method to check if received all suite results
1 parent a30d660 commit 4a19a42

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

lib/reporter/global-reporter.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = class GlobalReporter {
3131
endTimestamp: null
3232
};
3333
}
34+
static totalSuites = 0;
3435

3536
constructor(reporter = DefaultSettings.default_reporter, settings, {openReport = false, reportFileName = null} = {}) {
3637
this.suiteResults = [];
@@ -67,6 +68,8 @@ module.exports = class GlobalReporter {
6768
}
6869

6970
addTestSuiteResults(testResults, httpOutput) {
71+
GlobalReporter.totalSuites += 1;
72+
7073
testResults = testResults || {};
7174
const loggerOutput = httpOutput || Logger.collectOutput();
7275
testResults.httpOutput = loggerOutput.map(item => {
@@ -459,6 +462,25 @@ module.exports = class GlobalReporter {
459462
return Promise.all(results);
460463
}
461464

465+
delay = ms => new Promise(resolve => setTimeout(resolve, ms));
466+
467+
async waitResultForAllSuites(totalSuitesExpected){
468+
const timeout = 30000;
469+
const pollInterval = 500;
470+
let elapsedTime = 0;
471+
472+
while (elapsedTime < timeout) {
473+
if (GlobalReporter.totalSuites >= totalSuitesExpected) {
474+
return;
475+
}
476+
477+
await this.delay(pollInterval);
478+
elapsedTime += pollInterval;
479+
}
480+
481+
return;
482+
}
483+
462484
save() {
463485
if (Concurrency.isWorker()) {
464486
return Promise.resolve();

lib/runner/test-runners/default.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ class DefaultRunner {
130130
/**
131131
* @return {Promise<boolean>}
132132
*/
133-
async reportResults() {
133+
async reportResults(totalSuitesExpected) {
134134
if (!this.isTestWorker()) {
135+
if (totalSuitesExpected){
136+
await this.globalReporter.waitResultForAllSuites(totalSuitesExpected);
137+
}
138+
135139
this.printGlobalResults();
136140
await this.globalReporter.save();
137141
}
@@ -144,11 +148,12 @@ class DefaultRunner {
144148
* @return {Promise<number>}
145149
*/
146150
async runConcurrent(testEnvArray, modules, isTestWorkerEnabled, isSafariEnvPresent) {
151+
const totalSuitesExpected = Object.values(modules).reduce((total, currentArray) => total + currentArray.length, 0);
147152
this.concurrency = new Concurrency(this.settings, this.argv, isTestWorkerEnabled, isSafariEnvPresent);
148153
this.globalReporter.setupChildProcessListener(this.concurrency);
149154

150155
const exitCode = await this.concurrency.runMultiple(testEnvArray, modules);
151-
await this.reportResults();
156+
await this.reportResults(totalSuitesExpected);
152157

153158
return exitCode;
154159
}

0 commit comments

Comments
 (0)