Skip to content

Commit

Permalink
remove duplicate events
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Oct 29, 2023
1 parent 696c7f0 commit ef5d709
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions lib/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const simplifyObject = (object) => {
};

const repackTest = (test) => {
test = Object.assign(new Test(test.title || '', () => { }), test);
test = Object.assign(new Test(test.title || '', () => {
}), test);
test.parent = Object.assign(new Suite(test.parent.title), test.parent);
return test;
};
Expand Down Expand Up @@ -224,6 +225,12 @@ class Workers extends EventEmitter {
pending: 0,
};
this.testGroups = [];
this.suiteArr = [];
this.passedTestArr = [];
this.failedTestArr = [];
this.skippedTestArr = [];
this.passedStepArr = [];
this.failedStepArr = [];

createOutputDir(config.testConfig);
if (numberOfWorkers) this._initWorkers(numberOfWorkers, config);
Expand Down Expand Up @@ -338,7 +345,6 @@ class Workers extends EventEmitter {
this.stats.start = new Date();
recorder.startUnlessRunning();
event.dispatcher.emit(event.workers.before);
// expose this to manage events better when using run-workers command
process.env.RUNS_WITH_WORKERS = 'true';
recorder.add('starting workers', () => {
for (const worker of this.workers) {
Expand Down Expand Up @@ -380,56 +386,52 @@ class Workers extends EventEmitter {
this._appendStats(message.data.stats);
break;
case event.suite.before:
event.dispatcher.emit(event.suite.before, repackTest(message.data));
this.suiteArr.push(repackTest(message.data));
this.emit(event.suite.before, repackTest(message.data));
break;
case event.suite.after:
this.emit(event.suite.after, repackTest(message.data));
break;
case event.hook.failed:
event.dispatcher.emit(event.hook.failed, repackTest(message.data));
this.emit(event.hook.failed, repackTest(message.data));
this.errors.push(message.data.err);
break;
case event.test.before:
event.dispatcher.emit(event.test.before, repackTest(message.data));
this.emit(event.test.before, repackTest(message.data));
break;
case event.test.started:
event.dispatcher.emit(event.test.started, repackTest(message.data));
this.emit(event.test.started, repackTest(message.data));
break;
case event.test.failed:
event.dispatcher.emit(event.test.failed, repackTest(message.data));
this.failedTestArr.push(repackTest(message.data));
this.emit(event.test.failed, repackTest(message.data));
break;
case event.test.passed:
event.dispatcher.emit(event.test.passed, repackTest(message.data));
this.passedTestArr.push(repackTest(message.data));
this.emit(event.test.passed, repackTest(message.data));
break;
case event.test.skipped:
event.dispatcher.emit(event.test.skipped, repackTest(message.data));
this.skippedTestArr.push(repackTest(message.data));
this.emit(event.test.skipped, repackTest(message.data));
break;
case event.test.finished:
event.dispatcher.emit(event.test.finished, repackTest(message.data));
this.emit(event.test.finished, repackTest(message.data));
break;
case event.test.after:
event.dispatcher.emit(event.test.after, repackTest(message.data));
this.emit(event.test.after, repackTest(message.data));
break;
case event.step.finished:
event.dispatcher.emit(event.step.finished, message.data);
this.emit(event.step.finished, message.data);
break;
case event.step.started:
event.dispatcher.emit(event.step.started, message.data);
this.emit(event.step.started, message.data);
break;
case event.step.passed:
event.dispatcher.emit(event.step.passed, message.data);
this.passedStepArr.push(message.data);
this.emit(event.step.passed, message.data);
break;
case event.step.failed:
event.dispatcher.emit(event.step.failed, message.data);
this.failedStepArr.push(message.data);
this.emit(event.step.failed, message.data);
break;
}
Expand Down Expand Up @@ -487,9 +489,19 @@ class Workers extends EventEmitter {

output.result(this.stats.passes, this.stats.failures, this.stats.pending, ms(this.stats.duration));
// expose test stats after all workers finished their execution
event.dispatcher.emit(event.workers.result, this.stats);
// reset this after the run-workers finished
process.env.RUN_WITH_WORKERS = 'false';
event.dispatcher.emit(event.workers.result, {
suites: this.suiteArr,
tests: {
passed: this.passedTestArr,
failed: this.failedTestArr,
skipped: this.skippedTestArr,
},
steps: {
passed: this.passedStepArr,
failed: this.failedStepArr,
},
});
process.env.RUNS_WITH_WORKERS = 'false';
}
}

Expand Down

0 comments on commit ef5d709

Please sign in to comment.