|
1 | 1 | const fs = require('fs');
|
2 | 2 | const path = require('path');
|
3 |
| - |
| 3 | +const failedTestToggle = require('./toggle'); |
4 | 4 | /**
|
5 | 5 | * Collects failed tests from the most recent Cypress test run
|
6 | 6 | *
|
@@ -52,175 +52,4 @@ 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 |
| - |
86 |
| -/** |
87 |
| - * Toggle for use within a spec file during `cypress open` |
88 |
| - */ |
89 |
| - |
90 |
| -const failedTestToggle = () => { |
91 |
| - const hasStyles = top?.document.querySelector('#runFailedStyle'); |
92 |
| - const hasToggleButton = top?.document.querySelector('#runFailedToggle'); |
93 |
| - const defaultStyles = ` |
94 |
| - .reporter header { |
95 |
| - overflow: visible; |
96 |
| - z-index: 2; |
97 |
| - } |
98 |
| - #runFailedControls { |
99 |
| - position: relative; |
100 |
| - display: inline-block; |
101 |
| - } |
102 |
| - #runFailedToggle { |
103 |
| - display: none; |
104 |
| - } |
105 |
| - #runFailedControls label { |
106 |
| - background-color: transparent; |
107 |
| - padding-top: 5px; |
108 |
| - } |
109 |
| - #runFailedControls #runFailedTooltip { |
110 |
| - visibility: hidden; |
111 |
| - width: 134px; |
112 |
| - background-color: #f3f4fa; |
113 |
| - color: #1b1e2e; |
114 |
| - text-align: center; |
115 |
| - padding: 5px; |
116 |
| - border-radius: 3px; |
117 |
| - position: absolute; |
118 |
| - z-index: 1; |
119 |
| - top: 27px; |
120 |
| - left: 0px; |
121 |
| - height: 28px; |
122 |
| - } |
123 |
| - #runFailedControls:hover #runFailedTooltip { |
124 |
| - visibility: visible; |
125 |
| - } |
126 |
| - #runFailedButton #runFailedLabel { |
127 |
| - cursor: pointer; |
128 |
| - } |
129 |
| - #runFailedTooltip::after { |
130 |
| - content: " "; |
131 |
| - position: absolute; |
132 |
| - bottom: 100%; /* At the top of the tooltip */ |
133 |
| - right: 85%; |
134 |
| - margin-left: -5px; |
135 |
| - border-width: 5px; |
136 |
| - border-style: solid; |
137 |
| - border-color: transparent transparent #f3f4fa transparent; |
138 |
| - } |
139 |
| - .reporter:has(#runFailed:checked) .command.command-name-request:has(.command-is-event) { |
140 |
| - display:none |
141 |
| - } |
142 |
| - `; |
143 |
| - const turnOffRunFailedIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#f59aa9" class="bi bi-filter-circle" viewBox="0 0 16 16"> |
144 |
| - <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/> |
145 |
| - <path d="M7 11.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 0 1h-1a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m-2-3a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5"/> |
146 |
| - </svg>`; |
147 |
| - |
148 |
| - const turnOnRunFailedIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#f59aa9" class="bi bi-filter-circle-fill" viewBox="0 0 16 16"> |
149 |
| - <path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16M3.5 5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1 0-1M5 8.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5m2 3a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 0 1h-1a.5.5 0 0 1-.5-.5"/> |
150 |
| - </svg>`; |
151 |
| - |
152 |
| - const turnOffRunFailedDescription = 'Filter failed tests'; |
153 |
| - const turnOnRunFailedDescription = 'Unfilter failed tests'; |
154 |
| - |
155 |
| - // append styles |
156 |
| - if (!hasStyles) { |
157 |
| - const reporterEl = top?.document.querySelector('#unified-reporter'); |
158 |
| - const reporterStyleEl = document.createElement('style'); |
159 |
| - reporterStyleEl.setAttribute('id', 'runFailedStyle'); |
160 |
| - reporterStyleEl.innerHTML = defaultStyles; |
161 |
| - reporterEl?.appendChild(reporterStyleEl); |
162 |
| - } |
163 |
| - |
164 |
| - if (!hasToggleButton) { |
165 |
| - const header = top?.document.querySelector('#unified-reporter header'); |
166 |
| - const headerToggleDiv = document.createElement('div'); |
167 |
| - const headerToggleSpan = document.createElement('span'); |
168 |
| - const headerToggleTooltip = document.createElement('span'); |
169 |
| - const headerToggleButton = document.createElement('button'); |
170 |
| - const headerToggleInput = document.createElement('input'); |
171 |
| - const headerToggleLabel = document.createElement('label'); |
172 |
| - |
173 |
| - headerToggleInput.setAttribute('type', 'checkbox'); |
174 |
| - |
175 |
| - headerToggleInput.setAttribute('id', 'runFailedToggle'); |
176 |
| - headerToggleLabel.setAttribute('for', 'runFailedToggle'); |
177 |
| - headerToggleLabel.setAttribute('id', 'runFailedLabel'); |
178 |
| - headerToggleLabel.innerHTML = turnOffRunFailedIcon; |
179 |
| - |
180 |
| - headerToggleDiv.setAttribute('class', 'controls'); |
181 |
| - headerToggleDiv.setAttribute('id', 'runFailedControls'); |
182 |
| - headerToggleTooltip.setAttribute('id', 'runFailedTooltip'); |
183 |
| - headerToggleTooltip.innerText = turnOffRunFailedDescription; |
184 |
| - headerToggleButton.setAttribute('aria-label', turnOffRunFailedDescription); |
185 |
| - headerToggleButton.setAttribute('id', 'runFailedButton'); |
186 |
| - |
187 |
| - header?.appendChild(headerToggleDiv); |
188 |
| - headerToggleDiv?.appendChild(headerToggleSpan); |
189 |
| - headerToggleDiv?.appendChild(headerToggleTooltip); |
190 |
| - headerToggleSpan?.appendChild(headerToggleButton); |
191 |
| - headerToggleButton?.appendChild(headerToggleInput); |
192 |
| - headerToggleButton?.appendChild(headerToggleLabel); |
193 |
| - } |
194 |
| - |
195 |
| - const runFailedElement = top.document.querySelector('#runFailedToggle'); |
196 |
| - const runFailedLabelElement = top.document.querySelector( |
197 |
| - '[for=runFailedToggle]' |
198 |
| - ); |
199 |
| - const runFailedTooltipElement = |
200 |
| - top.document.querySelector('#runFailedTooltip'); |
201 |
| - |
202 |
| - runFailedElement?.addEventListener('change', (e) => { |
203 |
| - const stopBtn = window.top.document.querySelector('.reporter .stop'); |
204 |
| - |
205 |
| - if (e.target.checked) { |
206 |
| - if (stopBtn) { |
207 |
| - stopBtn.click(); |
208 |
| - } |
209 |
| - // when checked, grep only failed tests in spec |
210 |
| - grepFailed(); |
211 |
| - |
212 |
| - runFailedLabelElement.innerHTML = turnOnRunFailedIcon; |
213 |
| - runFailedTooltipElement.innerHTML = turnOnRunFailedDescription; |
214 |
| - } else { |
215 |
| - if (stopBtn) { |
216 |
| - stopBtn.click(); |
217 |
| - } |
218 |
| - // when unchecked, ungrep and show all tests in spec |
219 |
| - Cypress.grep(); |
220 |
| - runFailedLabelElement.innerHTML = turnOffRunFailedIcon; |
221 |
| - runFailedTooltipElement.innerHTML = turnOffRunFailedDescription; |
222 |
| - } |
223 |
| - }); |
224 |
| -}; |
225 |
| - |
226 | 55 | module.exports = { collectFailingTests, failedTestToggle };
|
0 commit comments