cypress-plugin-filter-runnables 1.0.0 → 1.2.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 (3) hide show
  1. package/README.md +6 -1
  2. package/index.js +55 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -8,7 +8,6 @@ Cypress plugin that allows user to filter suites/tests in Cypress Test Runner.
8
8
 
9
9
  ![cypress-plugin-filter-runnables-demo-1](https://github.com/user-attachments/assets/fc9f3a8a-5de2-4ca1-8b73-2e26bacb3bf6)
10
10
 
11
-
12
11
  ## Features
13
12
 
14
13
  - 🔍 A new UI search bar within `cypress open` to filter suites/tests in a given spec
@@ -44,6 +43,12 @@ Run `npx cypress open` to launch Cypress in `open` mode.
44
43
 
45
44
  Choose a spec file to run and you will be able to filter by suite/test title at the top of the reporter.
46
45
 
46
+ You can combine multiple searches by separating them with a semicolon (`;`).
47
+
48
+ Example:
49
+
50
+ `@smoke; can add todo`
51
+
47
52
  ### Pairing with `cypress-plugin-grep-boxes`
48
53
 
49
54
  The [cypress-plugin-grep-boxes](https://github.com/dennisbergevin/cypress-plugin-grep-boxes) is a great companion for this plugin.
package/index.js CHANGED
@@ -135,26 +135,66 @@ clearBtn?.addEventListener('click', function () {
135
135
 
136
136
  searchInput?.addEventListener('input', (event) => {
137
137
  const searchTerm = event.target.value.toLowerCase();
138
+
139
+ scanRunnables(searchTerm);
140
+ });
141
+
142
+ const scanRunnables = (searchInput) => {
138
143
  const testsAndSuites = window.top?.document.querySelectorAll(
139
144
  '.test.runnable, .suite.runnable'
140
145
  );
146
+ if (!testsAndSuites) return;
141
147
 
142
- for (let i = 0; i < testsAndSuites.length; i++) {
143
- const itemText = testsAndSuites[i].textContent.toLowerCase();
148
+ // Split search groups by ";"
149
+ const groups = searchInput
150
+ .toLowerCase()
151
+ .split(';')
152
+ .map((group) => group.replace(/,/g, ' ').split(/\s+/).filter(Boolean))
153
+ .filter((group) => group.length > 0); // Remove empty groups
144
154
 
145
- if (itemText.includes(searchTerm)) {
146
- testsAndSuites[i].style.display = '';
155
+ for (let i = 0; i < testsAndSuites.length; i++) {
156
+ const el = testsAndSuites[i];
157
+ const itemText = el.textContent.toLowerCase();
158
+ const suiteText = el
159
+ .closest('.suite.runnable')
160
+ ?.innerText.split('\n')[0]
161
+ .toLowerCase();
162
+
163
+ // A test matches if it satisfies ANY group
164
+ const matchesAnyGroup = groups.some((group) =>
165
+ group.every((term) => {
166
+ return itemText.includes(term) || suiteText.includes(term);
167
+ })
168
+ );
169
+
170
+ if (searchInput === '') {
171
+ el.style.display = '';
147
172
  } else {
148
- const closestSuiteText = testsAndSuites[i]
149
- .closest('.suite.runnable')
150
- .innerText.split('\n')[0]
151
- .toLowerCase();
152
- if (closestSuiteText.includes(searchTerm)) {
153
- testsAndSuites[i].style.display = '';
154
- } else {
155
- testsAndSuites[i].click;
156
- testsAndSuites[i].style.display = 'none';
157
- }
173
+ el.style.display = matchesAnyGroup ? '' : 'none';
158
174
  }
159
175
  }
160
- });
176
+ };
177
+
178
+ // Wrapping logic within isInteractive check
179
+ // This targets cypress open mode where user can switch specs
180
+ if (Cypress.config('isInteractive')) {
181
+ Cypress.on('window:unload', () => {
182
+ const searchTerm = searchInput.value.toLowerCase();
183
+ // Store the current Cypress test runner url
184
+ // This is to check against any spec change in test runner while a filter search is entered
185
+ // If a user does switch spec while filter is active, the filter search will be reset
186
+ const sidebarDebugLinkPage = window.top?.document.querySelector(
187
+ '[data-cy="sidebar-link-debug-page"]'
188
+ );
189
+ if (
190
+ window.top?.document.URL !=
191
+ sidebarDebugLinkPage.getAttribute('data-url') &&
192
+ searchInput.value !== ''
193
+ ) {
194
+ clearBtn.click();
195
+ }
196
+ sidebarDebugLinkPage.setAttribute('data-url', window.top?.document.URL);
197
+
198
+ scanRunnables(searchTerm);
199
+ });
200
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress-plugin-filter-runnables",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Cypress plugin that allows user to filter suites/tests in Cypress Test Runner.",
5
5
  "main": "./index.js",
6
6
  "keywords": [