cypress-plugin-last-failed 1.0.1 → 1.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.
package/CONTRIBUTING.md CHANGED
@@ -30,7 +30,7 @@ Thanks for being willing to contribute!
30
30
  Please make sure to run the node script before you commit your changes:
31
31
 
32
32
  ```bash
33
- npx cypress-last-failed run
33
+ npx cypress-plugin-last-failed run
34
34
  ```
35
35
 
36
36
  For changes related to the `cypress open` toggle, you can run `npx cypress open` to test functionality in the Cypress Test Runner UI. Make sure to include any test changes (if they exist) in your commit.
package/README.md CHANGED
@@ -24,6 +24,7 @@ A companion Cypress plugin for <code>cy-grep</code> that re-runs the last failed
24
24
  - [Setting up a `npm` script](#-setting-up-a-npm-script)
25
25
  - [Open mode](#-open-mode)
26
26
  - [Recommended open mode env variables](#recommended-open-mode-env-variables)
27
+ - [Use Required Test Tags Instead Of Skipping Tests](#use-required-test-tags-instead-of-skipping-tests)
27
28
  - [CI support](#continuous-integration-support)
28
29
  - [Typescript support](#typescript-support)
29
30
  - [Contributions](#contributions)
@@ -151,6 +152,29 @@ Toggling the filter will run any previously failed tests on the particular spec
151
152
  > [!NOTE]
152
153
  > More information on `grepOmitFiltered` and `grepFilterSpecs` can be read within the [README for `@bahmutov/cy-grep`](https://github.com/bahmutov/cy-grep?tab=readme-ov-file#pre-filter-specs-grepfilterspecs).
153
154
 
155
+ ### Use Required Test Tags Instead Of Skipping Tests
156
+
157
+ > [!NOTE]
158
+ > Read more about this topic within a blog post [Use Required Test Tags Instead Of Skipping Tests](https://glebbahmutov.com/blog/required-tags-instead-of-skipped-tests/) and within the [README for `@bahmutov/cy-grep`](https://github.com/bahmutov/cy-grep#required-tags).
159
+
160
+ Normally, any Cypress test or suite of tests marked with a `.skip` will be shown when running tests or within the Cypress test runner UI.
161
+
162
+ Since this plugin uses `@bahmutov/cy-grep` plugin, we can instead designate skipped tests using a **required tag**:
163
+
164
+ ```js
165
+ it('deletes an item', { requiredTags: '@skip' }, () => {
166
+ expect(1).to.equal(2);
167
+ });
168
+ ```
169
+
170
+ Now running or opening Cypress in interactive mode, **you will not see any tests with `requiredTags` including `@skip`** (unless setting environment variable `grepTags=@skip`).
171
+
172
+ To run just those tests with the required tag `@skip` in interactive mode:
173
+
174
+ ```bash
175
+ npx cypress open --env grepTags=@skip
176
+ ```
177
+
154
178
  ---
155
179
 
156
180
  ## Continuous integration support
@@ -6,9 +6,11 @@ describe('Should run expected tests', () => {
6
6
  expect(true).to.eq(false);
7
7
  }
8
8
  });
9
+
9
10
  it('should not run', () => {
10
11
  expect(true).to.eq(true);
11
12
  });
13
+
12
14
  it('needs to run', () => {
13
15
  if (Cypress.env('shouldPass')) {
14
16
  expect(1).to.eq(1);
@@ -16,6 +18,7 @@ describe('Should run expected tests', () => {
16
18
  expect(1).to.eq(2);
17
19
  }
18
20
  });
21
+
19
22
  it('will be included in failed tests', () => {
20
23
  if (Cypress.env('shouldPass')) {
21
24
  expect(10).to.eq(10);
@@ -23,4 +26,16 @@ describe('Should run expected tests', () => {
23
26
  expect(10).to.eq(2);
24
27
  }
25
28
  });
29
+
30
+ it('retry', { requiredTags: '@skip', retries: 1 }, () => {
31
+ if (Cypress.currentRetry === 0) {
32
+ expect(10).to.eq(2);
33
+ } else {
34
+ expect(10).to.eq(10);
35
+ }
36
+ });
37
+
38
+ it('skipped', { requiredTags: '@skip' }, () => {
39
+ expect(10).to.eq(10);
40
+ });
26
41
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-plugin-last-failed",
3
- "version": "1.0.1",
3
+ "version": "1.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
  "scripts": {
package/src/index.js CHANGED
@@ -52,6 +52,37 @@ const collectFailingTests = (on, config) => {
52
52
  return collectFailingTests;
53
53
  };
54
54
 
55
+ /**
56
+ * Find and grep all the failed test titles designated within the Cypress Test Runner UI.
57
+ *
58
+ * Any retried tests that failed but ultimately passed will not be included.
59
+ *
60
+ * See README for recommendation on handling skipped tests ordinarily seen within the Cypress Test Runner UI.
61
+ */
62
+
63
+ const grepFailed = () => {
64
+ // @ts-ignore
65
+ const failedTestTitles = [];
66
+
67
+ const failedTests = window.top?.document.querySelectorAll(
68
+ '.test.runnable.runnable-failed'
69
+ );
70
+
71
+ [...failedTests].forEach((test) => {
72
+ failedTestTitles.push(test.innerText.split('\n')[0]);
73
+ });
74
+
75
+ if (!failedTestTitles.length) {
76
+ console.log('No failed tests found');
77
+ } else {
78
+ console.log('running only the failed tests');
79
+ const grepTitles = failedTestTitles.join('; ');
80
+ console.log(grepTitles);
81
+ // @ts-ignore
82
+ Cypress.grep(grepTitles);
83
+ }
84
+ };
85
+
55
86
  /**
56
87
  * Toggle for use within a spec file during `cypress open`
57
88
  */
@@ -176,7 +207,8 @@ const failedTestToggle = () => {
176
207
  stopBtn.click();
177
208
  }
178
209
  // when checked, grep only failed tests in spec
179
- Cypress.grepFailed();
210
+ grepFailed();
211
+
180
212
  runFailedLabelElement.innerHTML = turnOnRunFailedIcon;
181
213
  runFailedTooltipElement.innerHTML = turnOnRunFailedDescription;
182
214
  } else {