cypress-plugin-last-failed 1.1.0 โ†’ 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ jobs:
18
18
  - name: Output the file contents ๐Ÿ“
19
19
  if: always()
20
20
  run: |
21
- cat ./test-results/last-run.txt
21
+ cat ./test-results/last-run.json
22
22
  - name: Custom tests ๐Ÿงช
23
23
  if: always()
24
24
  uses: cypress-io/github-action@v6
package/README.md CHANGED
@@ -201,7 +201,7 @@ jobs:
201
201
  - name: Output the file contents ๐Ÿ“
202
202
  if: always()
203
203
  run: |
204
- cat ./test-results/last-run.txt
204
+ cat ./test-results/last-run.json
205
205
  - name: Custom tests ๐Ÿงช
206
206
  if: always()
207
207
  uses: cypress-io/github-action@v6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-plugin-last-failed",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Cypress plugin to rerun last failed tests in cypress run and open mode",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/runFailed.js CHANGED
@@ -10,20 +10,37 @@ async function runLastFailed() {
10
10
  Ensure you are in the directory of your cypress config
11
11
  Try running tests again with cypress run`;
12
12
 
13
- const failedTestFilePath = `${appDir}/test-results/last-run.txt`;
13
+ const failedTestFilePath = `${appDir}/test-results/last-run.json`;
14
14
 
15
15
  if (fs.existsSync(failedTestFilePath)) {
16
16
  // Retrieve the failedTests from the file
17
17
  const failedTests = await fs.promises.readFile(failedTestFilePath, 'utf8');
18
18
 
19
- if (failedTests.length > 0) {
19
+ // Retrieve the parent suite and tests in the results from test-results/last-run
20
+ const parentAndTest = JSON.parse(failedTests).map(({ parent, test }) => ({
21
+ parent,
22
+ test,
23
+ }));
24
+ // Combine parent suite and test together
25
+ const resultSet = new Set(
26
+ Object.values(parentAndTest).flatMap(
27
+ (parent) => parent.parent + ',' + parent.test + ';'
28
+ )
29
+ );
30
+ // Format string for use in grep functionality
31
+ const stringedTests = Array.from(resultSet)
32
+ .toString()
33
+ .replaceAll(',', ' ')
34
+ .slice(0, -1);
35
+
36
+ if (stringedTests.length > 0) {
20
37
  // Allow for additional cli arguments to be passed to the run command
21
38
  const runOptions = await cypress.cli.parseRunArguments(
22
39
  process.argv.slice(2)
23
40
  );
24
41
 
25
42
  // Set cypress environment variables needed for running last failed tests
26
- process.env.CYPRESS_grep = `${failedTests}`;
43
+ process.env.CYPRESS_grep = `${stringedTests}`;
27
44
  process.env.CYPRESS_grepFilterSpecs = true;
28
45
  process.env.CYPRESS_grepOmitFiltered = true;
29
46
 
package/src/index.js CHANGED
@@ -21,18 +21,23 @@ const collectFailingTests = (on, config) => {
21
21
  for (i in results.runs) {
22
22
  const tests = results.runs[i].tests
23
23
  .filter((test) => test.state === 'failed')
24
- .map((test) => test.title[test.title.length - 1]);
24
+ .map((test) => test.title);
25
25
 
26
- // Only store non empty test titles
27
- if (tests != '') {
28
- failedTests.push(tests);
26
+ const spec = results.runs[i].spec.relative;
27
+
28
+ for (i in tests) {
29
+ let report = {
30
+ spec: spec,
31
+ parent: [...tests[i].slice(0, -1)],
32
+ test: tests[i].pop(),
33
+ };
34
+ // Only store non empty test titles
35
+ if (tests != '') {
36
+ failedTests.push(report);
37
+ }
29
38
  }
30
39
  }
31
40
 
32
- const stringedTests = failedTests.toString();
33
- // Prepare a string that can be read from cy-grep
34
- const greppedTestFormat = stringedTests.replaceAll(',', '; ');
35
-
36
41
  // Use the cypress.config directory for path for storing test-results
37
42
  const failedTestFileDirectory = `${path.dirname(
38
43
  config.configFile
@@ -44,9 +49,9 @@ const collectFailingTests = (on, config) => {
44
49
  });
45
50
  const lastRunReportFile = path.join(
46
51
  `${failedTestFileDirectory}`,
47
- 'last-run.txt'
52
+ 'last-run.json'
48
53
  );
49
- await fs.promises.writeFile(lastRunReportFile, greppedTestFormat);
54
+ await fs.promises.writeFile(lastRunReportFile, JSON.stringify(failedTests));
50
55
  });
51
56
 
52
57
  return collectFailingTests;