diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d147e65..48736085 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/features/issues/977.feature b/features/issues/977.feature new file mode 100644 index 00000000..d93d137c --- /dev/null +++ b/features/issues/977.feature @@ -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 diff --git a/features/step_definitions/json_steps.ts b/features/step_definitions/json_steps.ts index 83976d48..6912f377 100644 --- a/features/step_definitions/json_steps.ts +++ b/features/step_definitions/json_steps.ts @@ -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"); diff --git a/lib/create-tests.ts b/lib/create-tests.ts index b6757692..8e043a52 100644 --- a/lib/create-tests.ts +++ b/lib/create-tests.ts @@ -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, }, });