cypress-plugin-last-failed 1.0.0 → 1.0.1

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.
@@ -24,5 +24,5 @@ jobs:
24
24
  uses: cypress-io/github-action@v6
25
25
  with:
26
26
  # environment variable used for CI/CD tests in this repo
27
- command: npx cypress-last-failed run --env shouldPass=true
27
+ command: npx cypress-plugin-last-failed run --env shouldPass=true
28
28
  working-directory: ${{ github.workspace }}
package/README.md CHANGED
@@ -20,7 +20,6 @@ A companion Cypress plugin for <code>cy-grep</code> that re-runs the last failed
20
20
 
21
21
  - [Installation](#-installation)
22
22
  - [Run mode](#-run-mode)
23
- - [Optional custom `failedTestDirectory`](#optional-custom-failedtestdirectory)
24
23
  - [Add rule to gitignore](#add-rule-to-gitignore)
25
24
  - [Setting up a `npm` script](#-setting-up-a-npm-script)
26
25
  - [Open mode](#-open-mode)
@@ -54,10 +53,12 @@ failedTestToggle();
54
53
  3. In `cypress.config`, include the following within `setupNodeEvents` for `e2e` and/or `component` testing:
55
54
 
56
55
  ```js
56
+ const { defineConfig } = require('cypress');
57
+ const { collectFailingTests } = require('cypress-plugin-last-failed');
58
+
57
59
  module.exports = defineConfig({
58
60
  screenshotOnRunFailure: false,
59
61
  env: {
60
- failedTestDirectory: './',
61
62
  grepOmitFiltered: true,
62
63
  grepFilterSpecs: true,
63
64
  },
@@ -94,34 +95,17 @@ npx cypress run
94
95
  2. If there are failed tests, run the following command from the **directory of the project's `cypress.config`**:
95
96
 
96
97
  ```bash
97
- npx cypress-last-failed run
98
+ npx cypress-plugin-last-failed run
98
99
  ```
99
100
 
100
101
  You can also include more cli arguments similar to `cypress run`, as the command harnesses the power of [Cypress module API](https://docs.cypress.io/guides/guides/module-api):
101
102
 
102
103
  ```bash
103
104
  # Example
104
- npx cypress-last-failed run --e2e --browser chrome
105
+ npx cypress-plugin-last-failed run --e2e --browser chrome
105
106
  ```
106
107
 
107
- ### Optional custom `failedTestDirectory`
108
-
109
- By default, there will be a folder called `test-results` created in the directory of the `cypress.config`.
110
-
111
- - To customize where the `test-results` folder should be stored, add the `failedTestDirectory` environment variable:
112
-
113
- ```js
114
- // Example using a fixtures folder path relative to the cypress.config
115
-
116
- module.exports = defineConfig({
117
- env: {
118
- failedTestDirectory: './cypress/fixtures',
119
- },
120
- e2e: {
121
- setupNodeEvents(on, config) {},
122
- },
123
- });
124
- ```
108
+ There will be a folder called `test-results` created in the directory of the `cypress.config`.
125
109
 
126
110
  ### Add rule to gitignore
127
111
 
@@ -141,7 +125,7 @@ For convenience, you may desire to house the `npx` command within an npm script
141
125
 
142
126
  ```json
143
127
  "scripts": {
144
- "last-failed": "npx cypress-run-last-failed run --e2e --browser electron"
128
+ "last-failed": "npx cypress-plugin-last-failed run --e2e --browser electron"
145
129
  }
146
130
  ```
147
131
 
@@ -198,7 +182,7 @@ jobs:
198
182
  if: always()
199
183
  uses: cypress-io/github-action@v6
200
184
  with:
201
- command: npx cypress-last-failed run
185
+ command: npx cypress-plugin-last-failed run
202
186
  working-directory: ${{ github.workspace }}
203
187
  ```
204
188
 
Binary file
package/cypress.config.js CHANGED
@@ -3,7 +3,6 @@ const { collectFailingTests } = require('./src/index');
3
3
 
4
4
  module.exports = defineConfig({
5
5
  env: {
6
- failedTestDirectory: './',
7
6
  grepOmitFiltered: true,
8
7
  grepFilterSpecs: true,
9
8
  },
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "cypress-plugin-last-failed",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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": {
7
- "last-failed": "node runFailed.js run --e2e --browser electron"
7
+ "last-failed": "npx cypress-plugin-last-failed run --e2e --browser electron"
8
8
  },
9
9
  "bin": {
10
- "cypress-last-failed": "runFailed.js"
10
+ "cypress-plugin-last-failed": "runFailed.js"
11
11
  },
12
12
  "keywords": [
13
13
  "cypress",
package/runFailed.js CHANGED
@@ -4,18 +4,13 @@ const cypress = require('cypress');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const appDir = process.env.INIT_CWD ? process.env.INIT_CWD : path.resolve('.');
7
- const cypressConfig = require(`${appDir}/cypress.config`);
8
7
 
9
8
  async function runLastFailed() {
10
- const noFailedTestsMessage =
11
- 'No previous failed tests detected\nTry running tests again with cypress run';
12
-
13
- // Use the cypress environment variable failedTestDirectory for where to store failed tests
14
- // If not set then use the directory of the project's cypress.config where the test-results defaults to
15
- const failedTestFilePath =
16
- cypressConfig.env?.failedTestDirectory === undefined
17
- ? `${appDir}/test-results/last-run.txt`
18
- : `${cypressConfig.env.failedTestDirectory}/test-results/last-run.txt`;
9
+ const noFailedTestsMessage = `No previous failed tests detected
10
+ Ensure you are in the directory of your cypress config
11
+ Try running tests again with cypress run`;
12
+
13
+ const failedTestFilePath = `${appDir}/test-results/last-run.txt`;
19
14
 
20
15
  if (fs.existsSync(failedTestFilePath)) {
21
16
  // Retrieve the failedTests from the file
package/src/index.js CHANGED
@@ -6,9 +6,7 @@ const path = require('path');
6
6
  *
7
7
  * After each run, a file will store failed test titles within a test-results directory
8
8
  *
9
- * Environment variable `failedTestDirectory` can be used to set a specific directory to store test-results
10
- *
11
- * If failedTestDirectory env var is unset, test-results will be stored in cypress.config directory
9
+ * The test-results directory will be stored in cypress.config directory
12
10
  *
13
11
  * Subsequent test runs containing failed tests will overwrite this file
14
12
  * @param {*} on
@@ -17,7 +15,6 @@ const path = require('path');
17
15
  */
18
16
 
19
17
  const collectFailingTests = (on, config) => {
20
- // Check for environment variable `collectFailingTests` to be true
21
18
  on('after:run', async (results) => {
22
19
  let failedTests = [];
23
20
  // Grab every failed test's title
@@ -36,13 +33,12 @@ const collectFailingTests = (on, config) => {
36
33
  // Prepare a string that can be read from cy-grep
37
34
  const greppedTestFormat = stringedTests.replaceAll(',', '; ');
38
35
 
39
- // Use the cypress.config environment variable for failedTestDirectory
40
- // If not set then use the cypress.config directory
41
- const failedTestFileDirectory =
42
- config.env.failedTestDirectory === undefined
43
- ? `${path.dirname(config.configFile)}/test-results/`
44
- : `${config.env.failedTestDirectory}/test-results/`;
36
+ // Use the cypress.config directory for path for storing test-results
37
+ const failedTestFileDirectory = `${path.dirname(
38
+ config.configFile
39
+ )}/test-results/`;
45
40
 
41
+ // Create the directory and last-run file where failed tests will be written to
46
42
  await fs.promises.mkdir(`${failedTestFileDirectory}`, {
47
43
  recursive: true,
48
44
  });