cypress-plugin-last-failed 3.1.2 → 4.1.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/toggle.js +31 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-plugin-last-failed",
3
- "version": "3.1.2",
3
+ "version": "4.1.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": {
@@ -17,8 +17,8 @@
17
17
  "cypress-plugin"
18
18
  ],
19
19
  "devDependencies": {
20
- "@bahmutov/cy-grep": "^3.0.4",
21
- "cypress": "^15.18.1"
20
+ "@bahmutov/cy-grep": "^3.0.5",
21
+ "cypress": "^15.21.1"
22
22
  },
23
23
  "publishConfig": {
24
24
  "registry": "https://registry.npmjs.org/"
package/src/toggle.js CHANGED
@@ -10,9 +10,9 @@ const grepFailed = () => {
10
10
  // @ts-ignore
11
11
  const failedTestTitles = [];
12
12
 
13
- const failedTests = window.top?.document.querySelectorAll(
14
- '.test.runnable.runnable-failed'
15
- );
13
+ const failedTests = window.top?.document
14
+ .querySelector('iframe')
15
+ ?.contentDocument?.querySelectorAll('.test.runnable.runnable-failed');
16
16
 
17
17
  [...failedTests].forEach((test) => {
18
18
  failedTestTitles.push(test.innerText.split('\n')[0]);
@@ -23,6 +23,7 @@ const grepFailed = () => {
23
23
  } else {
24
24
  console.log('running only the failed tests');
25
25
  const grepTitles = failedTestTitles.join('; ');
26
+
26
27
  // @ts-ignore
27
28
  Cypress.grep(grepTitles);
28
29
  }
@@ -33,8 +34,12 @@ const grepFailed = () => {
33
34
  */
34
35
 
35
36
  const failedTestToggle = () => {
36
- const hasStyles = top?.document.querySelector('#runFailedStyle');
37
- const hasToggleButton = top?.document.querySelector('#runFailedToggle');
37
+ const hasStyles = top?.document
38
+ .querySelector('iframe')
39
+ ?.contentDocument?.querySelector('#runFailedStyle');
40
+ const hasToggleButton = top?.document
41
+ .querySelector('iframe')
42
+ ?.contentDocument?.querySelector('#runFailedToggle');
38
43
  const defaultStyles = `
39
44
  .reporter header {
40
45
  overflow: visible;
@@ -110,11 +115,9 @@ const failedTestToggle = () => {
110
115
  if (!hasStyles) {
111
116
  let reporterEl;
112
117
  const reporterStyleEl = document.createElement('style');
113
- if (Cypress.version >= '15.0.0') {
114
- reporterEl = window.top?.document.querySelector('.runnable-header');
115
- } else {
116
- reporterEl = window.top?.document.querySelector('#unified-reporter');
117
- }
118
+ reporterEl = window.top?.document
119
+ .querySelector('iframe')
120
+ ?.contentDocument?.querySelector('.runnable-header');
118
121
  reporterStyleEl.setAttribute('id', 'runFailedStyle');
119
122
  reporterStyleEl.innerHTML = defaultStyles;
120
123
  reporterEl?.appendChild(reporterStyleEl);
@@ -122,13 +125,9 @@ const failedTestToggle = () => {
122
125
 
123
126
  if (!hasToggleButton) {
124
127
  let header;
125
- if (Cypress.version >= '15.0.0') {
126
- // TODO: Cypress v15 GUI provides option for Cypress Studio which pushes the grep toggle button around the UI
127
- // For simplicity, moving the toggle button to the spec container above the stop button
128
- header = window.top?.document.querySelector('.runnable-header');
129
- } else {
130
- header = window.top?.document.querySelector('#unified-reporter header');
131
- }
128
+ header = window.top?.document
129
+ .querySelector('iframe')
130
+ ?.contentDocument?.querySelector('.runnable-header');
132
131
  const headerToggleDiv = document.createElement('div');
133
132
  const headerToggleSpan = document.createElement('span');
134
133
  const headerToggleTooltip = document.createElement('span');
@@ -158,16 +157,20 @@ const failedTestToggle = () => {
158
157
  headerToggleButton?.appendChild(headerToggleLabel);
159
158
  }
160
159
 
161
- const runFailedElement = top.document.querySelector('#runFailedToggle');
162
- const runFailedLabelElement = top.document.querySelector(
163
- '[for=runFailedToggle]'
164
- );
165
- const runFailedTooltipElement =
166
- top.document.querySelector('#runFailedTooltip');
160
+ const runFailedElement = top.document
161
+ .querySelector('iframe')
162
+ ?.contentDocument?.querySelector('#runFailedToggle');
163
+ const runFailedLabelElement = top.document
164
+ .querySelector('iframe')
165
+ ?.contentDocument?.querySelector('[for=runFailedToggle]');
166
+ const runFailedTooltipElement = top.document
167
+ .querySelector('iframe')
168
+ ?.contentDocument?.querySelector('#runFailedTooltip');
167
169
 
168
170
  runFailedElement?.addEventListener('change', (e) => {
169
- const stopBtn = window.top.document.querySelector('.reporter .stop');
170
-
171
+ const stopBtn = window.top.document
172
+ .querySelector('iframe')
173
+ ?.contentDocument?.querySelector('.reporter .stop');
171
174
  if (e.target.checked) {
172
175
  if (stopBtn) {
173
176
  stopBtn.click();
@@ -197,8 +200,9 @@ const failedTestToggle = () => {
197
200
  const sidebarRunsLinkPage = window.top?.document.querySelector(
198
201
  '[data-cy="sidebar-link-runs-page"]'
199
202
  );
200
- const runFailedToggleElement =
201
- window.top?.document.querySelector('#runFailedToggle');
203
+ const runFailedToggleElement = window.top?.document
204
+ .querySelector('iframe')
205
+ ?.contentDocument?.querySelector('#runFailedToggle');
202
206
 
203
207
  if (
204
208
  window.top?.document.URL !=