Skip to content

Commit a66114f

Browse files
Merge pull request #16 from dennisbergevin/fix/remove-burn
fix: Adding logic around burning tests via cy-grep
2 parents 5ba7d38 + 4d69bfc commit a66114f

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

.github/workflows/main.yml

+25-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch:
88

99
jobs:
10-
default-test-results:
10+
default-dir-test-results:
1111
runs-on: ubuntu-22.04
1212
steps:
1313
- name: Checkout 📦
@@ -26,7 +26,30 @@ jobs:
2626
# environment variable used for CI/CD tests in this repo
2727
command: npx cypress-plugin-last-failed run --env shouldPass=true
2828
working-directory: ${{ github.workspace }}
29-
custom-test-results:
29+
burn-test-results:
30+
runs-on: ubuntu-22.04
31+
steps:
32+
- name: Checkout 📦
33+
uses: actions/checkout@v4
34+
- name: Cypress run - run burn=10 🔥
35+
uses: cypress-io/github-action@v6
36+
with:
37+
# using cy-grep plugin burn test feature
38+
command: npx cypress run --env burn=10
39+
working-directory: ${{ github.workspace }}
40+
continue-on-error: true
41+
- name: Output the file contents 📝
42+
if: always()
43+
run: |
44+
cat ./test-results/last-run.json
45+
- name: Run failed tests from default directory 🧪
46+
if: always()
47+
uses: cypress-io/github-action@v6
48+
with:
49+
# environment variable used for CI/CD tests in this repo
50+
command: npx cypress-plugin-last-failed run --env shouldPass=true
51+
working-directory: ${{ github.workspace }}
52+
custom-dir-test-results:
3053
runs-on: ubuntu-22.04
3154
steps:
3255
- name: Checkout 📦

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"semi": true,
4+
"singleQuote": true
5+
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cypress-plugin-last-failed",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "Cypress plugin to rerun last failed tests in cypress run and open mode",
55
"main": "./src/index.js",
66
"types": "./src/index.d.ts",

src/index.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const collectFailingTests = (on, config) => {
2626

2727
const spec = run.spec.relative;
2828

29-
failedTests = failedTests.concat(generateReports(tests, spec));
29+
failedTests = failedTests.concat(generateReports(tests, spec, config));
3030
}
3131
}
3232

@@ -48,12 +48,16 @@ const collectFailingTests = (on, config) => {
4848
return collectFailingTests;
4949
};
5050

51-
const generateReports = (tests, spec) => {
52-
const reports = [];
51+
const generateReports = (tests, spec, config) => {
52+
let reports = [];
5353
for (const test of tests) {
5454
const testCopy = [...test]; // Create a copy of the array to avoid mutation
55-
const testTitle = testCopy.pop(); // Extract the test title
55+
let testTitle = testCopy.pop(); // Extract the test title
5656
if (testTitle) {
57+
// If --env burn=X is set from cy-grep, remove the ": burning X of X"
58+
testTitle = config.env.burn
59+
? testTitle.replace(/: burning .* of .*/, '')
60+
: testTitle;
5761
const report = {
5862
spec: spec,
5963
parent: testCopy, // Parent titles
@@ -62,7 +66,18 @@ const generateReports = (tests, spec) => {
6266
reports.push(report);
6367
}
6468
}
65-
return reports;
69+
// If --env burn=X is set from cy-grep, remove the duplicate test objects
70+
if (config.env.burn) {
71+
const seen = new Set();
72+
const filteredReports = reports.filter((el) => {
73+
const duplicate = seen.has(el.test);
74+
seen.add(el.test);
75+
return !duplicate;
76+
});
77+
return filteredReports;
78+
} else {
79+
return reports;
80+
}
6681
};
6782

6883
module.exports = { collectFailingTests, failedTestToggle };

0 commit comments

Comments
 (0)