This repository demonstrates an issue with the cypress-plugin-last-failed
npm package (version 2.0.8
).
When a test fails inside a before
hook, the generated last-run.json
file includes only the first test from the spec file. As a result, rerunning failed tests (npm run cy:rerun:failed
) only re-executes that first test, even when the spec contains multiple tests.
This behavior poses a risk of unintentionally skipping tests that should have been rerun.
-
Install dependencies:
npm install
-
Run the Cypress tests:
npm run cy:run
-
Check the output:
- This will generate
test-results/last-run.json
- You'll see it includes only one test, even though
cypress/e2e/example.cy.ts
defines two tests
- This will generate
-
Remove the failing line:
- Open
cypress/e2e/example.cy.ts
and remove line 15 (which causes the failure in thebefore
hook).
- Open
-
Rerun failed tests:
npm run cy:rerun:failed
-
Check the result:
- Only the first test is executed and the second test is skipped even though it’s in the same spec.
If a failure occurs in a shared before hook, all tests in that spec file should be rerun, not just the first one. This would prevent unintentionally skipping tests that may also be affected by the shared setup.