Skip to content

Commit

Permalink
fix(reporter): report progress of failed check results only once (#3472)
Browse files Browse the repository at this point in the history
Share the replay of failed check results across all subscribers using the `shareReplay()` rxjs operator.
  • Loading branch information
nicojs committed Mar 30, 2022
1 parent ec63d93 commit dce5882
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/process/4-mutation-test-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export class MutationTestExecutor {
let passedMutant$ = input$;
for (const checkerName of this.options.checkers) {
// Use this checker
const [checkFailedResult$, checkPassedResult$] = partition(this.executeSingleChecker(checkerName, passedMutant$), isEarlyResult);
const [checkFailedResult$, checkPassedResult$] = partition(
this.executeSingleChecker(checkerName, passedMutant$).pipe(shareReplay()),
isEarlyResult
);

// Prepare for the next one
passedMutant$ = checkPassedResult$;
Expand Down Expand Up @@ -159,7 +162,6 @@ export class MutationTestExecutor {
.schedule(group$, (checker, group) => checker.check(checkerName, group))
.pipe(
mergeMap((mutantGroupResults) => mutantGroupResults),
shareReplay(),
map(([mutantRunPlan, checkResult]) =>
checkResult.status === CheckStatus.Passed
? mutantRunPlan
Expand Down
19 changes: 19 additions & 0 deletions packages/core/test/unit/process/4-mutation-test-executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,25 @@ describe(MutationTestExecutor.name, () => {
sinon.assert.calledWithExactly(checker.check, 'foo', [plan2]);
});

it('should report failed check mutants only once (#3461)', async () => {
// Arrange
const plan1 = mutantRunPlan({ id: '1' });
const plan2 = mutantRunPlan({ id: '2' });
const failedCheckResult = factory.failedCheckResult();
arrangeScenario({ checkResult: failedCheckResult });
checker.group.resolves([[plan1], [plan2]]);
mutantTestPlans.push(plan1);
mutantTestPlans.push(plan2);

// Act
await sut.execute();

// Assert
expect(mutationTestReportHelperMock.reportCheckFailed).calledTwice;
sinon.assert.calledWithExactly(mutationTestReportHelperMock.reportCheckFailed, plan1.mutant, failedCheckResult);
sinon.assert.calledWithExactly(mutationTestReportHelperMock.reportCheckFailed, plan1.mutant, failedCheckResult);
});

it('should free checker resources after checking stage is complete', async () => {
// Arrange
const plan = mutantRunPlan({ id: '1' });
Expand Down

0 comments on commit dce5882

Please sign in to comment.