Skip to content
Permalink
Browse files
fix(mocha): mark scenarios as retriable only if they are being retried
  • Loading branch information
jan-molak committed Jul 8, 2020
1 parent a57bc2c commit c876263daf79aafc97d1eb507850c5588174ff60
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
@@ -51,4 +51,16 @@ describe('@serenity-js/mocha', function () {
.next(SceneFinished, event => expect(event.outcome).to.equal(new ExecutionSuccessful()))
;
}));

it(`doesn't announce retries if the scenario is not being retried`, () =>
mocha('examples/passing.spec.js')
.then(ifExitCodeIsOtherThan(0, logOutput))
.then(res => {

const sceneTaggedEvents = res.events.filter(e => e instanceof SceneTagged) as SceneTagged[];

expect(sceneTaggedEvents).to.have.lengthOf(1);

expect(sceneTaggedEvents[0].tag).to.equal(new FeatureTag('Mocha reporting'))
}));
});
@@ -38,23 +38,23 @@ export class SerenityReporterForMocha extends reporters.Base {

runner.on(Runner.constants.EVENT_TEST_PASS,
(test: Test) => {
this.announceRetryOf(test);
this.announceRetryIfNeeded(test);

this.recorder.finished(!! test.ctx ? test.ctx.currentTest : test, this.outcomeMapper.outcomeOf(test))
},
);

runner.on(Runner.constants.EVENT_TEST_FAIL,
(test: Test, err: Error) => {
this.announceRetryOf(test);
this.announceRetryIfNeeded(test);

this.recorder.finished(!! test.ctx ? test.ctx.currentTest : test, this.outcomeMapper.outcomeOf(test, err))
},
);

runner.on(Runner.constants.EVENT_TEST_RETRY,
(test: Test, err: Error) => {
this.announceRetryOf(test);
this.announceRetryIfNeeded(test);

this.recorder.finished(
!! test.ctx && test.ctx.currentTest ? test.ctx.currentTest : test,
@@ -152,7 +152,11 @@ export class SerenityReporterForMocha extends reporters.Base {
);
}

private announceRetryOf(test: Test): void {
private announceRetryIfNeeded(test: Test): void {
if (! this.isRetriable(test)) {
return void 0;
}

const scenario = this.testMapper.detailsOf(test)

this.emit(
@@ -174,6 +178,10 @@ export class SerenityReporterForMocha extends reporters.Base {
}
}

private isRetriable(test: Test): boolean {
return (test as any).retries() >= 0;
}

private currentRetryOf(test: Test): number {
return (test as any).currentRetry();
}
@@ -151,8 +151,6 @@ export interface MochaConfig {
* @desc
* Retry failed tests this many times.
*
* @todo: will this work with Protractor?
*
* @type {number | undefined}
* @public
*/

0 comments on commit c876263

Please sign in to comment.