Skip to content

Commit

Permalink
Correctly set willBeRetried for non-retried tests
Browse files Browse the repository at this point in the history
This ensures that they can be found in JSON reports and fixes #977 [1].

[1] #977
  • Loading branch information
badeball committed Mar 29, 2023
1 parent 684e98e commit b7ac418
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## Unreleased

- Correctly set `willBeRetried` non-retried tests, fixes [#977](https://github.com/badeball/cypress-cucumber-preprocessor/issues/977).

## v16.0.0

- Correctly set `willBeRetried` in messages reports, fixes [#849](https://github.com/badeball/cypress-cucumber-preprocessor/issues/849).
Expand Down
27 changes: 27 additions & 0 deletions features/issues/977.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://github.com/badeball/cypress-cucumber-preprocessor/issues/977

Feature: JSON report
Scenario: a successful test not being retried
Given additional preprocessor configuration
"""
{
"json": {
"enabled": true
}
}
"""
And a file named "cypress/e2e/a.feature" with:
"""
@retries(1)
Feature: a feature
Scenario: a scenario
Given a step
"""
And a file named "cypress/support/step_definitions/steps.js" with:
"""
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
Given("a step", function() {})
"""
When I run cypress
Then it passes
And the JSON report should contain a spec
14 changes: 14 additions & 0 deletions features/step_definitions/json_steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ Then(
}
);

Then("the JSON report should contain a spec", async function () {
const absolutejsonPath = path.join(this.tmpDir, "cucumber-report.json");

const jsonFile = await fs.readFile(absolutejsonPath);

const actualJsonOutput = JSON.parse(jsonFile.toString());

if (actualJsonOutput.length !== 1) {
throw new Error(
`Expected to find a single spec, but found ${actualJsonOutput.length}`
);
}
});

Then("the JSON report shouldn't contain any specs", async function () {
const absolutejsonPath = path.join(this.tmpDir, "cucumber-report.json");

Expand Down
5 changes: 4 additions & 1 deletion lib/create-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,11 +825,14 @@ export default function createTests(
"Expected to find an attribute _retries"
);

const willBeRetried =
this.currentTest?.state === "failed" ? currentRetry < retries : false;

messages.push({
testCaseFinished: {
testCaseStartedId,
timestamp: endTimestamp,
willBeRetried: currentRetry < retries,
willBeRetried,
},
});

Expand Down

0 comments on commit b7ac418

Please sign in to comment.