cypress-plugin-filter-runnables 1.2.0 → 1.3.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.
- package/README.md +1 -1
- package/index.js +36 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Example:
|
|
|
53
53
|
|
|
54
54
|
The [cypress-plugin-grep-boxes](https://github.com/dennisbergevin/cypress-plugin-grep-boxes) is a great companion for this plugin.
|
|
55
55
|
|
|
56
|
-
Paired with `cypress-plugin-grep-boxes` (`@bahmutov/cy-grep` is also required), you can filter suites/tests and use the checkboxes to run only
|
|
56
|
+
Paired with `cypress-plugin-grep-boxes` (`@bahmutov/cy-grep` is also required), you can filter suites/tests and use the main toggle (v2.1.0 of cypress-plugin-grep-boxes) or individual checkboxes to run only the tests you've filtered:
|
|
57
57
|
|
|
58
58
|

|
|
59
59
|
|
package/index.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
if (
|
|
6
|
+
Cypress.config('isInteractive') &&
|
|
6
7
|
window.top?.document.querySelectorAll('#test-suite-filter-search').length ===
|
|
7
|
-
|
|
8
|
+
0
|
|
8
9
|
) {
|
|
9
10
|
const style = document.createElement('style');
|
|
10
11
|
style.textContent = `
|
|
@@ -139,21 +140,19 @@ searchInput?.addEventListener('input', (event) => {
|
|
|
139
140
|
scanRunnables(searchTerm);
|
|
140
141
|
});
|
|
141
142
|
|
|
142
|
-
const scanRunnables = (
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
);
|
|
146
|
-
if (!testsAndSuites) return;
|
|
143
|
+
const scanRunnables = (searchTerm) => {
|
|
144
|
+
const testRunnables = window.top?.document.querySelectorAll('.test.runnable');
|
|
145
|
+
if (!testRunnables) return;
|
|
147
146
|
|
|
148
147
|
// Split search groups by ";"
|
|
149
|
-
const groups =
|
|
150
|
-
|
|
148
|
+
const groups = searchTerm
|
|
149
|
+
?.toLowerCase()
|
|
151
150
|
.split(';')
|
|
152
151
|
.map((group) => group.replace(/,/g, ' ').split(/\s+/).filter(Boolean))
|
|
153
152
|
.filter((group) => group.length > 0); // Remove empty groups
|
|
154
153
|
|
|
155
|
-
for (let i = 0; i <
|
|
156
|
-
const el =
|
|
154
|
+
for (let i = 0; i < testRunnables.length; i++) {
|
|
155
|
+
const el = testRunnables[i];
|
|
157
156
|
const itemText = el.textContent.toLowerCase();
|
|
158
157
|
const suiteText = el
|
|
159
158
|
.closest('.suite.runnable')
|
|
@@ -161,13 +160,13 @@ const scanRunnables = (searchInput) => {
|
|
|
161
160
|
.toLowerCase();
|
|
162
161
|
|
|
163
162
|
// A test matches if it satisfies ANY group
|
|
164
|
-
const matchesAnyGroup = groups
|
|
163
|
+
const matchesAnyGroup = groups?.some((group) =>
|
|
165
164
|
group.every((term) => {
|
|
166
165
|
return itemText.includes(term) || suiteText.includes(term);
|
|
167
166
|
})
|
|
168
167
|
);
|
|
169
168
|
|
|
170
|
-
if (
|
|
169
|
+
if (searchTerm === '') {
|
|
171
170
|
el.style.display = '';
|
|
172
171
|
} else {
|
|
173
172
|
el.style.display = matchesAnyGroup ? '' : 'none';
|
|
@@ -179,7 +178,10 @@ const scanRunnables = (searchInput) => {
|
|
|
179
178
|
// This targets cypress open mode where user can switch specs
|
|
180
179
|
if (Cypress.config('isInteractive')) {
|
|
181
180
|
Cypress.on('window:unload', () => {
|
|
182
|
-
const
|
|
181
|
+
const searchInput = window.top?.document.querySelector(
|
|
182
|
+
'#test-suite-filter-search'
|
|
183
|
+
);
|
|
184
|
+
const searchTerm = searchInput?.value.toLowerCase();
|
|
183
185
|
// Store the current Cypress test runner url
|
|
184
186
|
// This is to check against any spec change in test runner while a filter search is entered
|
|
185
187
|
// If a user does switch spec while filter is active, the filter search will be reset
|
|
@@ -189,7 +191,7 @@ if (Cypress.config('isInteractive')) {
|
|
|
189
191
|
if (
|
|
190
192
|
window.top?.document.URL !=
|
|
191
193
|
sidebarDebugLinkPage.getAttribute('data-url') &&
|
|
192
|
-
searchInput
|
|
194
|
+
searchInput?.value !== ''
|
|
193
195
|
) {
|
|
194
196
|
clearBtn.click();
|
|
195
197
|
}
|
|
@@ -198,3 +200,23 @@ if (Cypress.config('isInteractive')) {
|
|
|
198
200
|
scanRunnables(searchTerm);
|
|
199
201
|
});
|
|
200
202
|
}
|
|
203
|
+
|
|
204
|
+
if (Cypress.config('isInteractive')) {
|
|
205
|
+
// To account for when the collapsible runnables are removed, persist filtered runnables
|
|
206
|
+
// watching for changes to DOM structure
|
|
207
|
+
MutationObserver = window.MutationObserver;
|
|
208
|
+
|
|
209
|
+
var observer = new MutationObserver(function () {
|
|
210
|
+
const searchInput = window.top?.document.querySelector(
|
|
211
|
+
'#test-suite-filter-search'
|
|
212
|
+
);
|
|
213
|
+
// fired when a mutation occurs
|
|
214
|
+
scanRunnables(searchInput?.value);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// defining the window.top?.document to be observed by the observer
|
|
218
|
+
observer.observe(window.top?.document, {
|
|
219
|
+
subtree: true,
|
|
220
|
+
attributes: true,
|
|
221
|
+
});
|
|
222
|
+
}
|