cypress-plugin-last-failed 3.1.2 → 4.0.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.
- package/package.json +2 -2
- package/src/toggle.js +59 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cypress-plugin-last-failed",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.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": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@bahmutov/cy-grep": "^3.0.4",
|
|
21
|
-
"cypress": "^15.
|
|
21
|
+
"cypress": "^15.21.0"
|
|
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
|
|
14
|
-
|
|
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,8 +23,22 @@ const grepFailed = () => {
|
|
|
23
23
|
} else {
|
|
24
24
|
console.log('running only the failed tests');
|
|
25
25
|
const grepTitles = failedTestTitles.join('; ');
|
|
26
|
+
const stopBtn = window.top?.document
|
|
27
|
+
.querySelector('iframe')
|
|
28
|
+
?.contentDocument?.querySelector('.statsAndControls .stop');
|
|
29
|
+
// TODO: The cy-grep package has not been updated to handle the new Cypress runner UI iframe
|
|
30
|
+
// Remove this restartBtn handling once that package has been updated
|
|
31
|
+
const restartBtn = window.top?.document
|
|
32
|
+
.querySelector('iframe')
|
|
33
|
+
?.contentDocument?.querySelector('.statsAndControls .restart');
|
|
34
|
+
|
|
26
35
|
// @ts-ignore
|
|
27
36
|
Cypress.grep(grepTitles);
|
|
37
|
+
if (stopBtn) {
|
|
38
|
+
stopBtn.click();
|
|
39
|
+
} else {
|
|
40
|
+
restartBtn.click();
|
|
41
|
+
}
|
|
28
42
|
}
|
|
29
43
|
};
|
|
30
44
|
|
|
@@ -33,8 +47,12 @@ const grepFailed = () => {
|
|
|
33
47
|
*/
|
|
34
48
|
|
|
35
49
|
const failedTestToggle = () => {
|
|
36
|
-
const hasStyles = top?.document
|
|
37
|
-
|
|
50
|
+
const hasStyles = top?.document
|
|
51
|
+
.querySelector('iframe')
|
|
52
|
+
?.contentDocument?.querySelector('#runFailedStyle');
|
|
53
|
+
const hasToggleButton = top?.document
|
|
54
|
+
.querySelector('iframe')
|
|
55
|
+
?.contentDocument?.querySelector('#runFailedToggle');
|
|
38
56
|
const defaultStyles = `
|
|
39
57
|
.reporter header {
|
|
40
58
|
overflow: visible;
|
|
@@ -111,9 +129,13 @@ const failedTestToggle = () => {
|
|
|
111
129
|
let reporterEl;
|
|
112
130
|
const reporterStyleEl = document.createElement('style');
|
|
113
131
|
if (Cypress.version >= '15.0.0') {
|
|
114
|
-
reporterEl = window.top?.document
|
|
132
|
+
reporterEl = window.top?.document
|
|
133
|
+
.querySelector('iframe')
|
|
134
|
+
?.contentDocument?.querySelector('.runnable-header');
|
|
115
135
|
} else {
|
|
116
|
-
reporterEl = window.top?.document
|
|
136
|
+
reporterEl = window.top?.document
|
|
137
|
+
.querySelector('iframe')
|
|
138
|
+
?.contentDocument?.querySelector('#unified-reporter');
|
|
117
139
|
}
|
|
118
140
|
reporterStyleEl.setAttribute('id', 'runFailedStyle');
|
|
119
141
|
reporterStyleEl.innerHTML = defaultStyles;
|
|
@@ -122,13 +144,9 @@ const failedTestToggle = () => {
|
|
|
122
144
|
|
|
123
145
|
if (!hasToggleButton) {
|
|
124
146
|
let header;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
header = window.top?.document.querySelector('.runnable-header');
|
|
129
|
-
} else {
|
|
130
|
-
header = window.top?.document.querySelector('#unified-reporter header');
|
|
131
|
-
}
|
|
147
|
+
header = window.top?.document
|
|
148
|
+
.querySelector('iframe')
|
|
149
|
+
?.contentDocument?.querySelector('.runnable-header');
|
|
132
150
|
const headerToggleDiv = document.createElement('div');
|
|
133
151
|
const headerToggleSpan = document.createElement('span');
|
|
134
152
|
const headerToggleTooltip = document.createElement('span');
|
|
@@ -158,19 +176,31 @@ const failedTestToggle = () => {
|
|
|
158
176
|
headerToggleButton?.appendChild(headerToggleLabel);
|
|
159
177
|
}
|
|
160
178
|
|
|
161
|
-
const runFailedElement = top.document
|
|
162
|
-
|
|
163
|
-
'
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
const runFailedElement = top.document
|
|
180
|
+
.querySelector('iframe')
|
|
181
|
+
?.contentDocument?.querySelector('#runFailedToggle');
|
|
182
|
+
const runFailedLabelElement = top.document
|
|
183
|
+
.querySelector('iframe')
|
|
184
|
+
?.contentDocument?.querySelector('[for=runFailedToggle]');
|
|
185
|
+
const runFailedTooltipElement = top.document
|
|
186
|
+
.querySelector('iframe')
|
|
187
|
+
?.contentDocument?.querySelector('#runFailedTooltip');
|
|
167
188
|
|
|
168
189
|
runFailedElement?.addEventListener('change', (e) => {
|
|
169
|
-
const stopBtn = window.top.document
|
|
190
|
+
const stopBtn = window.top.document
|
|
191
|
+
.querySelector('iframe')
|
|
192
|
+
?.contentDocument?.querySelector('.reporter .stop');
|
|
193
|
+
// TODO: The cy-grep package has not been updated to handle the new Cypress runner UI iframe
|
|
194
|
+
// Remove this restartBtn handling once that package has been updated
|
|
195
|
+
const restartBtn = window.top?.document
|
|
196
|
+
.querySelector('iframe')
|
|
197
|
+
?.contentDocument?.querySelector('.statsAndControls .restart');
|
|
170
198
|
|
|
171
199
|
if (e.target.checked) {
|
|
172
200
|
if (stopBtn) {
|
|
173
201
|
stopBtn.click();
|
|
202
|
+
} else {
|
|
203
|
+
restartBtn.click();
|
|
174
204
|
}
|
|
175
205
|
// when checked, grep only failed tests in spec
|
|
176
206
|
grepFailed();
|
|
@@ -183,6 +213,11 @@ const failedTestToggle = () => {
|
|
|
183
213
|
}
|
|
184
214
|
// when unchecked, ungrep and show all tests in spec
|
|
185
215
|
Cypress.grep();
|
|
216
|
+
// TODO: The cy-grep package has not been updated to handle the new Cypress runner UI iframe
|
|
217
|
+
// Remove this restartBtn handling once that package has been updated
|
|
218
|
+
if (restartBtn) {
|
|
219
|
+
restartBtn.click();
|
|
220
|
+
}
|
|
186
221
|
runFailedLabelElement.innerHTML = turnOffRunFailedIcon;
|
|
187
222
|
runFailedTooltipElement.innerHTML = turnOffRunFailedDescription;
|
|
188
223
|
}
|
|
@@ -197,8 +232,9 @@ const failedTestToggle = () => {
|
|
|
197
232
|
const sidebarRunsLinkPage = window.top?.document.querySelector(
|
|
198
233
|
'[data-cy="sidebar-link-runs-page"]'
|
|
199
234
|
);
|
|
200
|
-
const runFailedToggleElement =
|
|
201
|
-
|
|
235
|
+
const runFailedToggleElement = window.top?.document
|
|
236
|
+
.querySelector('iframe')
|
|
237
|
+
?.contentDocument?.querySelector('#runFailedToggle');
|
|
202
238
|
|
|
203
239
|
if (
|
|
204
240
|
window.top?.document.URL !=
|