cypress-plugin-last-failed 2.0.0 โ†’ 2.0.2

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.
@@ -7,7 +7,7 @@ on:
7
7
  workflow_dispatch:
8
8
 
9
9
  jobs:
10
- node-script:
10
+ default-test-results:
11
11
  runs-on: ubuntu-22.04
12
12
  steps:
13
13
  - name: Checkout ๐Ÿ“ฆ
@@ -19,10 +19,31 @@ jobs:
19
19
  if: always()
20
20
  run: |
21
21
  cat ./test-results/last-run.json
22
- - name: Custom tests ๐Ÿงช
22
+ - name: Run failed tests from default directory ๐Ÿงช
23
23
  if: always()
24
24
  uses: cypress-io/github-action@v6
25
25
  with:
26
26
  # environment variable used for CI/CD tests in this repo
27
27
  command: npx cypress-plugin-last-failed run --env shouldPass=true
28
28
  working-directory: ${{ github.workspace }}
29
+ custom-test-results:
30
+ runs-on: ubuntu-22.04
31
+ steps:
32
+ - name: Checkout ๐Ÿ“ฆ
33
+ uses: actions/checkout@v4
34
+ - name: Cypress run - store failed tests in custom directory ๐Ÿ‘Ÿ
35
+ uses: cypress-io/github-action@v6
36
+ with:
37
+ command: npm run custom-dir-run
38
+ working-directory: ${{ github.workspace }}
39
+ continue-on-error: true
40
+ - name: Output the file contents ๐Ÿ“
41
+ if: always()
42
+ run: |
43
+ cat ./cypress/config/test-results/last-run.json
44
+ - name: Run failed tests from custom directory ๐Ÿงช
45
+ if: always()
46
+ uses: cypress-io/github-action@v6
47
+ with:
48
+ command: npm run custom-dir-last-failed
49
+ working-directory: ${{ github.workspace }}
package/README.md CHANGED
@@ -19,9 +19,10 @@ A companion Cypress plugin for <code>cy-grep</code> that re-runs the last failed
19
19
  #### Table of Contents
20
20
 
21
21
  - [Features](#features)
22
- - [Table of Contents](#table-of-contents)
22
+ - [Table of Contents](#table-of-contents)
23
23
  - [๐Ÿ“ฆ Installation](#-installation)
24
24
  - [๐Ÿ‘Ÿ Run mode](#-run-mode)
25
+ - [Specify a custom test-results directory](#specify-a-custom-test-results-directory)
25
26
  - [Add rule to gitignore](#add-rule-to-gitignore)
26
27
  - [๐Ÿ“ƒ Setting up a `npm` script](#-setting-up-a-npm-script)
27
28
  - [โŒ› Open mode](#-open-mode)
@@ -45,9 +46,9 @@ npm install --save-dev cypress-plugin-last-failed
45
46
  2. In `cypress/support/e2e.js` (For E2E tests) and/or `cypress/support/component.js` (For Component tests),
46
47
 
47
48
  ```js
48
- import { failedTestToggle } from "cypress-plugin-last-failed";
49
+ import { failedTestToggle } from 'cypress-plugin-last-failed';
49
50
 
50
- const registerCypressGrep = require("@bahmutov/cy-grep");
51
+ const registerCypressGrep = require('@bahmutov/cy-grep');
51
52
  registerCypressGrep();
52
53
 
53
54
  failedTestToggle();
@@ -56,8 +57,8 @@ failedTestToggle();
56
57
  3. In `cypress.config`, include the following within `setupNodeEvents` for `e2e` and/or `component` testing:
57
58
 
58
59
  ```js
59
- const { defineConfig } = require("cypress");
60
- const { collectFailingTests } = require("cypress-plugin-last-failed");
60
+ const { defineConfig } = require('cypress');
61
+ const { collectFailingTests } = require('cypress-plugin-last-failed');
61
62
 
62
63
  module.exports = defineConfig({
63
64
  screenshotOnRunFailure: false,
@@ -69,7 +70,7 @@ module.exports = defineConfig({
69
70
  setupNodeEvents(on, config) {
70
71
  collectFailingTests(on, config);
71
72
 
72
- require("@bahmutov/cy-grep/src/plugin")(config);
73
+ require('@bahmutov/cy-grep/src/plugin')(config);
73
74
  return config;
74
75
  },
75
76
  },
@@ -77,7 +78,7 @@ module.exports = defineConfig({
77
78
  setupNodeEvents(on, config) {
78
79
  collectFailingTests(on, config);
79
80
 
80
- require("@bahmutov/cy-grep/src/plugin")(config);
81
+ require('@bahmutov/cy-grep/src/plugin')(config);
81
82
  return config;
82
83
  },
83
84
  },
@@ -108,6 +109,8 @@ You can also include more cli arguments similar to `cypress run`, as the command
108
109
  npx cypress-plugin-last-failed run --e2e --browser chrome
109
110
  ```
110
111
 
112
+ ### Specify a custom test-results directory
113
+
111
114
  There will be a folder called test-results created in the directory of the cypress.config. If you would like to specify a different folder for test results, use the LAST_FAILED_RESULTS_PATH environment variable:
112
115
 
113
116
  ```bash
@@ -171,7 +174,7 @@ Normally, any Cypress test or suite of tests marked with a `.skip` will be shown
171
174
  Since this plugin uses `@bahmutov/cy-grep` plugin, we can instead designate skipped tests using a **required tag**:
172
175
 
173
176
  ```js
174
- it("deletes an item", { requiredTags: "@skip" }, () => {
177
+ it('deletes an item', { requiredTags: '@skip' }, () => {
175
178
  expect(1).to.equal(2);
176
179
  });
177
180
  ```
@@ -195,7 +198,7 @@ name: test-last-failed-node-script
195
198
  on:
196
199
  push:
197
200
  branches:
198
- - "main"
201
+ - 'main'
199
202
  pull_request:
200
203
  workflow_dispatch:
201
204
 
@@ -1,5 +1,5 @@
1
- const { defineConfig } = require("cypress");
2
- const { collectFailingTests } = require("../../src/index");
1
+ const { defineConfig } = require('cypress');
2
+ const { collectFailingTests } = require('../../src/index');
3
3
 
4
4
  module.exports = defineConfig({
5
5
  env: {
@@ -9,7 +9,7 @@ module.exports = defineConfig({
9
9
  screenshotOnRunFailure: false,
10
10
  e2e: {
11
11
  setupNodeEvents(on, config) {
12
- require("@bahmutov/cy-grep/src/plugin")(config);
12
+ require('@bahmutov/cy-grep/src/plugin')(config);
13
13
  collectFailingTests(on, config);
14
14
 
15
15
  return config;
@@ -17,7 +17,7 @@ module.exports = defineConfig({
17
17
  },
18
18
  component: {
19
19
  setupNodeEvents(on, config) {
20
- require("@bahmutov/cy-grep/src/plugin")(config);
20
+ require('@bahmutov/cy-grep/src/plugin')(config);
21
21
  collectFailingTests(on, config);
22
22
 
23
23
  return config;
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "cypress-plugin-last-failed",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Cypress plugin to rerun last failed tests in cypress run and open mode",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
7
7
  "scripts": {
8
- "last-failed": "npx cypress-plugin-last-failed run --e2e --browser electron"
8
+ "last-failed": "npx cypress-plugin-last-failed run --e2e --browser electron",
9
+ "custom-dir-run": "LAST_FAILED_RESULTS_PATH=cypress/config npx cypress run",
10
+ "custom-dir-last-failed": "LAST_FAILED_RESULTS_PATH=cypress/config npx cypress-plugin-last-failed run --env shouldPass=true"
9
11
  },
10
12
  "bin": {
11
13
  "cypress-plugin-last-failed": "runFailed.js"
package/runFailed.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const cypress = require("cypress");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const appDir = process.env.INIT_CWD ? process.env.INIT_CWD : path.resolve(".");
3
+ const cypress = require('cypress');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const appDir = process.env.INIT_CWD ? process.env.INIT_CWD : path.resolve('.');
7
7
 
8
8
  async function runLastFailed() {
9
9
  const noFailedTestsMessage = `No previous failed tests detected
@@ -14,14 +14,14 @@ Try running tests again with cypress run`;
14
14
  ? path.join(
15
15
  appDir,
16
16
  process.env.LAST_FAILED_RESULTS_PATH,
17
- "test-results",
18
- "last-run.json"
17
+ 'test-results',
18
+ 'last-run.json'
19
19
  )
20
- : path.join(appDir, "test-results", "last-run.json");
20
+ : path.join(appDir, 'test-results', 'last-run.json');
21
21
 
22
22
  if (fs.existsSync(failedTestFilePath)) {
23
23
  // Retrieve the failedTests from the file
24
- const failedTests = await fs.promises.readFile(failedTestFilePath, "utf8");
24
+ const failedTests = await fs.promises.readFile(failedTestFilePath, 'utf8');
25
25
 
26
26
  // Retrieve the parent suite and tests in the results from test-results/last-run
27
27
  const parentAndTest = JSON.parse(failedTests).map(({ parent, test }) => ({
@@ -31,13 +31,13 @@ Try running tests again with cypress run`;
31
31
  // Combine parent suite and test together
32
32
  const resultSet = new Set(
33
33
  Object.values(parentAndTest).flatMap(
34
- (parent) => parent.parent + "," + parent.test + ";"
34
+ (parent) => parent.parent + ',' + parent.test + ';'
35
35
  )
36
36
  );
37
37
  // Format string for use in grep functionality
38
38
  const stringedTests = Array.from(resultSet)
39
39
  .toString()
40
- .replaceAll(",", " ")
40
+ .replaceAll(',', ' ')
41
41
  .slice(0, -1);
42
42
 
43
43
  if (stringedTests.length > 0) {
package/src/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // index.d.ts
2
- declare module "cypress-plugin-last-failed" {
2
+ declare module 'cypress-plugin-last-failed' {
3
3
  /**
4
4
  * Collects failed tests from the most recent Cypress test run.
5
5
  *
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const failedTestToggle = require("./toggle");
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const failedTestToggle = require('./toggle');
4
4
 
5
5
  /**
6
6
  * Collects failed tests from the most recent Cypress test run
@@ -15,13 +15,13 @@ const failedTestToggle = require("./toggle");
15
15
  * @returns
16
16
  */
17
17
  const collectFailingTests = (on, config) => {
18
- on("after:run", async (results) => {
18
+ on('after:run', async (results) => {
19
19
  let failedTests = [];
20
20
 
21
21
  for (const run of results.runs) {
22
22
  if (run.tests && run.spec) {
23
23
  const tests = run.tests
24
- .filter((test) => test.state === "failed")
24
+ .filter((test) => test.state === 'failed')
25
25
  .map((test) => test.title);
26
26
 
27
27
  const spec = run.spec.relative;
@@ -35,13 +35,13 @@ const collectFailingTests = (on, config) => {
35
35
  ? path.join(
36
36
  process.env.INIT_CWD,
37
37
  process.env.LAST_FAILED_RESULTS_PATH,
38
- "test-results"
38
+ 'test-results'
39
39
  )
40
40
  : `${path.dirname(config.configFile)}/test-results/`;
41
41
 
42
42
  // Create the directory and last-run file where failed tests will be written to
43
43
  await fs.promises.mkdir(failedTestFilePath, { recursive: true });
44
- const lastRunReportFile = path.join(failedTestFilePath, "last-run.json");
44
+ const lastRunReportFile = path.join(failedTestFilePath, 'last-run.json');
45
45
  await fs.promises.writeFile(lastRunReportFile, JSON.stringify(failedTests));
46
46
  });
47
47