cypress-plugin-filter-runnables 1.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.
@@ -0,0 +1,14 @@
1
+ name: Cypress Tests
2
+
3
+ on: push
4
+
5
+ jobs:
6
+ cypress-run:
7
+ runs-on: ubuntu-22.04
8
+ steps:
9
+ - name: Checkout
10
+ uses: actions/checkout@v4
11
+ # Install npm dependencies, cache them correctly
12
+ # and run all Cypress tests
13
+ - name: Cypress run
14
+ uses: cypress-io/github-action@v6
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "semi": true,
4
+ "singleQuote": true
5
+ }
@@ -0,0 +1,43 @@
1
+ # Contributing
2
+
3
+ Thanks for being willing to contribute!
4
+
5
+ **Working on your first Pull Request?** You can learn more from [Your First Pull Request on GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)
6
+
7
+ ## Project setup
8
+
9
+ 1. Fork and clone the repo
10
+ 2. Run `npm install` to install dependencies
11
+ 3. Create a branch for your PR with `git checkout -b pr/your-branch-name`
12
+
13
+ > Tip: Keep your `main` branch pointing at the original repository and make
14
+ > pull requests from branches on your fork. To do this, run:
15
+ >
16
+ > ```
17
+ > git remote add upstream https://github.com/dennisbergevin/cypress-plugin-filter-runnables
18
+ > git fetch upstream
19
+ > git branch --set-upstream-to=upstream/main main
20
+ > ```
21
+ >
22
+ > This will add the original repository as a "remote" called "upstream," Then
23
+ > fetch the git information from that remote, then set your local `main`
24
+ > branch to use the upstream main branch whenever you run `git pull`. Then you
25
+ > can make all of your pull request branches based on this `main` branch.
26
+ > Whenever you want to update your version of `main`, do a regular `git pull`.
27
+
28
+ ## Committing and Pushing changes
29
+
30
+ Please make sure to run tests in `open` mode to verify functionality before you commit your changes:
31
+
32
+ ```bash
33
+ npx cypress open
34
+ ```
35
+
36
+ Make sure to include any test changes (if they exist) in your commit.
37
+
38
+ ## Help needed
39
+
40
+ Please checkout the [the open issues](https://github.com/dennisbergevin/cypress-plugin-filter-runnables/issues)
41
+
42
+ Also, please watch the repo and respond to questions/bug reports/feature
43
+ requests! Thanks!
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Dennis Bergevin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ <h2 align=center>Cypress plugin filter-runnables</h2>
2
+ <p align="center">
3
+ </p>
4
+
5
+ <p align="center">
6
+ Cypress plugin that allows user to filter suites/tests in Cypress Test Runner.
7
+ </p>
8
+
9
+ ![cypress-plugin-filter-runnables-demo-1](https://github.com/user-attachments/assets/fc9f3a8a-5de2-4ca1-8b73-2e26bacb3bf6)
10
+
11
+
12
+ ## Features
13
+
14
+ - 🔍 A new UI search bar within `cypress open` to filter suites/tests in a given spec
15
+
16
+ #### Table of Contents
17
+
18
+ - [Installation](#-installation)
19
+ - [Open mode](#-open-mode)
20
+ - [Pairing with cypress-plugin-grep-boxes](#pairing-with-cypress-plugin-grep-boxes)
21
+ - [Contributions](#contributions)
22
+
23
+ ---
24
+
25
+ ## 📦 Installation
26
+
27
+ 1. Install the following packages:
28
+
29
+ ```sh
30
+ npm install --save-dev cypress-plugin-filter-runnables
31
+ ```
32
+
33
+ 2. In `cypress/support/e2e.js` (For E2E tests) and/or `cypress/support/component.js` (For Component tests),
34
+
35
+ ```js
36
+ import 'cypress-plugin-filter-runnables';
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 🔍 Open mode
42
+
43
+ Run `npx cypress open` to launch Cypress in `open` mode.
44
+
45
+ Choose a spec file to run and you will be able to filter by suite/test title at the top of the reporter.
46
+
47
+ ### Pairing with `cypress-plugin-grep-boxes`
48
+
49
+ The [cypress-plugin-grep-boxes](https://github.com/dennisbergevin/cypress-plugin-grep-boxes) is a great companion for this plugin.
50
+
51
+ Paired with `cypress-plugin-grep-boxes` (`@bahmutov/cy-grep` is also required), you can filter suites/tests and use the checkboxes to run only selected tests:
52
+
53
+ ![cypress-plugin-filter-runnables-demo-2](https://github.com/user-attachments/assets/59053e87-cbfa-4a49-81a0-6212abc94ba8)
54
+
55
+ Additionally, you can filter tags when paired with `cypress-plugin-grep-boxes` (version `2.1.0` of `@bahmutov/cy-grep` required):
56
+
57
+ ![filter-runnables-grep-boxes-tags](https://github.com/user-attachments/assets/2c359ddf-cf54-4f48-a34a-b9cae4620acd)
58
+
59
+ In addition, `cypress-plugin-grep-boxes` supports a [disableInitialAutoRun feature](https://github.com/dennisbergevin/cypress-plugin-grep-boxes/blob/main/README.md#disableinitialautorun) that will prevent Cypress Test Runner from automatically running available tests once a spec file is open.
60
+
61
+ This gives you a moment to filter down to whichever tests to select before running them:
62
+
63
+ ![cypress-plugin-filter-runnables-demo-3](https://github.com/user-attachments/assets/e10262db-7f88-4852-9cc8-1b4626e13f45)
64
+
65
+ ## Contributions
66
+
67
+ Feel free to open a pull request or drop any feature request or bug in the [issues](https://github.com/dennisbergevin/cypress-plugin-filter-runnables/issues).
68
+
69
+ Please see more details in the [contributing doc](./CONTRIBUTING.md).
@@ -0,0 +1,143 @@
1
+ /// <reference types="cypress" />
2
+
3
+ // Welcome to Cypress!
4
+ //
5
+ // This spec file contains a variety of sample tests
6
+ // for a todo list app that are designed to demonstrate
7
+ // the power of writing tests in Cypress.
8
+ //
9
+ // To learn more about how Cypress works and
10
+ // what makes it such an awesome testing tool,
11
+ // please read our getting started guide:
12
+ // https://on.cypress.io/introduction-to-cypress
13
+
14
+ describe('example to-do app', () => {
15
+ beforeEach(() => {
16
+ // Cypress starts out with a blank slate for each test
17
+ // so we must tell it to visit our website with the `cy.visit()` command.
18
+ // Since we want to visit the same URL at the start of all our tests,
19
+ // we include it in our beforeEach function so that it runs before each test
20
+ cy.visit('https://example.cypress.io/todo');
21
+ });
22
+
23
+ it('displays two todo items by default', { tags: '@smoke' }, () => {
24
+ // We use the `cy.get()` command to get all elements that match the selector.
25
+ // Then, we use `should` to assert that there are two matched items,
26
+ // which are the two default items.
27
+ cy.get('.todo-list li').should('have.length', 2);
28
+
29
+ // We can go even further and check that the default todos each contain
30
+ // the correct text. We use the `first` and `last` functions
31
+ // to get just the first and last matched elements individually,
32
+ // and then perform an assertion with `should`.
33
+ cy.get('.todo-list li').first().should('have.text', 'Pay electric bill');
34
+ cy.get('.todo-list li').last().should('have.text', 'Walk the dog');
35
+ });
36
+
37
+ it('can add new todo items', () => {
38
+ // We'll store our item text in a variable so we can reuse it
39
+ const newItem = 'Feed the cat';
40
+
41
+ // Let's get the input element and use the `type` command to
42
+ // input our new list item. After typing the content of our item,
43
+ // we need to type the enter key as well in order to submit the input.
44
+ // This input has a data-test attribute so we'll use that to select the
45
+ // element in accordance with best practices:
46
+ // https://on.cypress.io/selecting-elements
47
+ cy.get('[data-test=new-todo]').type(`${newItem}{enter}`);
48
+
49
+ // Now that we've typed our new item, let's check that it actually was added to the list.
50
+ // Since it's the newest item, it should exist as the last element in the list.
51
+ // In addition, with the two default items, we should have a total of 3 elements in the list.
52
+ // Since assertions yield the element that was asserted on,
53
+ // we can chain both of these assertions together into a single statement.
54
+ cy.get('.todo-list li')
55
+ .should('have.length', 3)
56
+ .last()
57
+ .should('have.text', newItem);
58
+ });
59
+
60
+ it('can check off an item as completed', () => {
61
+ // In addition to using the `get` command to get an element by selector,
62
+ // we can also use the `contains` command to get an element by its contents.
63
+ // However, this will yield the <label>, which is lowest-level element that contains the text.
64
+ // In order to check the item, we'll find the <input> element for this <label>
65
+ // by traversing up the dom to the parent element. From there, we can `find`
66
+ // the child checkbox <input> element and use the `check` command to check it.
67
+ cy.contains('Pay electric bill')
68
+ .parent()
69
+ .find('input[type=checkbox]')
70
+ .check();
71
+
72
+ // Now that we've checked the button, we can go ahead and make sure
73
+ // that the list element is now marked as completed.
74
+ // Again we'll use `contains` to find the <label> element and then use the `parents` command
75
+ // to traverse multiple levels up the dom until we find the corresponding <li> element.
76
+ // Once we get that element, we can assert that it has the completed class.
77
+ cy.contains('Pay electric bill')
78
+ .parents('li')
79
+ .should('have.class', 'completed');
80
+ });
81
+
82
+ context('with a checked task', () => {
83
+ beforeEach(() => {
84
+ // We'll take the command we used above to check off an element
85
+ // Since we want to perform multiple tests that start with checking
86
+ // one element, we put it in the beforeEach hook
87
+ // so that it runs at the start of every test.
88
+ cy.contains('Pay electric bill')
89
+ .parent()
90
+ .find('input[type=checkbox]')
91
+ .check();
92
+ });
93
+
94
+ it('can filter for uncompleted tasks', () => {
95
+ // We'll click on the "active" button in order to
96
+ // display only incomplete items
97
+ cy.contains('Active').click();
98
+
99
+ // After filtering, we can assert that there is only the one
100
+ // incomplete item in the list.
101
+ cy.get('.todo-list li')
102
+ .should('have.length', 1)
103
+ .first()
104
+ .should('have.text', 'Walk the dog');
105
+
106
+ // For good measure, let's also assert that the task we checked off
107
+ // does not exist on the page.
108
+ cy.contains('Pay electric bill').should('not.exist');
109
+ });
110
+
111
+ it('can filter for completed tasks', () => {
112
+ // We can perform similar steps as the test above to ensure
113
+ // that only completed tasks are shown
114
+ cy.contains('Completed').click();
115
+
116
+ cy.get('.todo-list li')
117
+ .should('have.length', 1)
118
+ .first()
119
+ .should('have.text', 'Pay electric bill');
120
+
121
+ cy.contains('Walk the dog').should('not.exist');
122
+ });
123
+
124
+ it('can delete all completed tasks', () => {
125
+ // First, let's click the "Clear completed" button
126
+ // `contains` is actually serving two purposes here.
127
+ // First, it's ensuring that the button exists within the dom.
128
+ // This button only appears when at least one task is checked
129
+ // so this command is implicitly verifying that it does exist.
130
+ // Second, it selects the button so we can click it.
131
+ cy.contains('Clear completed').click();
132
+
133
+ // Then we can make sure that there is only one element
134
+ // in the list and our element does not exist
135
+ cy.get('.todo-list li')
136
+ .should('have.length', 1)
137
+ .should('not.have.text', 'Pay electric bill');
138
+
139
+ // Finally, make sure that the clear button no longer exists.
140
+ cy.contains('Clear completed').should('not.exist');
141
+ });
142
+ });
143
+ });
@@ -0,0 +1,22 @@
1
+ /// <reference types="cypress" />
2
+
3
+ context('Window', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/window')
6
+ })
7
+
8
+ it('cy.window() - get the global window object', () => {
9
+ // https://on.cypress.io/window
10
+ cy.window().should('have.property', 'top')
11
+ })
12
+
13
+ it('cy.document() - get the document object', () => {
14
+ // https://on.cypress.io/document
15
+ cy.document().should('have.property', 'charset').and('eq', 'UTF-8')
16
+ })
17
+
18
+ it('cy.title() - get the title', () => {
19
+ // https://on.cypress.io/title
20
+ cy.title().should('include', 'Kitchen Sink')
21
+ })
22
+ })
@@ -0,0 +1,25 @@
1
+ // ***********************************************
2
+ // This example commands.js shows you how to
3
+ // create various custom commands and overwrite
4
+ // existing commands.
5
+ //
6
+ // For more comprehensive examples of custom
7
+ // commands please read more here:
8
+ // https://on.cypress.io/custom-commands
9
+ // ***********************************************
10
+ //
11
+ //
12
+ // -- This is a parent command --
13
+ // Cypress.Commands.add('login', (email, password) => { ... })
14
+ //
15
+ //
16
+ // -- This is a child command --
17
+ // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18
+ //
19
+ //
20
+ // -- This is a dual command --
21
+ // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22
+ //
23
+ //
24
+ // -- This will overwrite an existing command --
25
+ // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
@@ -0,0 +1,19 @@
1
+ // ***********************************************************
2
+ // This example support/e2e.js is processed and
3
+ // loaded automatically before your test files.
4
+ //
5
+ // This is a great place to put global configuration and
6
+ // behavior that modifies Cypress.
7
+ //
8
+ // You can change the location of this file or turn off
9
+ // automatically serving support files with the
10
+ // 'supportFile' configuration option.
11
+ //
12
+ // You can read more here:
13
+ // https://on.cypress.io/configuration
14
+ // ***********************************************************
15
+
16
+ // Import commands.js using ES2015 syntax:
17
+ import './commands';
18
+ import '../../index';
19
+
@@ -0,0 +1,7 @@
1
+ const { defineConfig } = require('cypress');
2
+
3
+ module.exports = defineConfig({
4
+ e2e: {
5
+ setupNodeEvents(on, config) {},
6
+ },
7
+ });
package/index.js ADDED
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Adds a searchbar to reporter to grep suites and tests.
3
+ */
4
+
5
+ if (
6
+ window.top?.document.querySelectorAll('#test-suite-filter-search').length ===
7
+ 0
8
+ ) {
9
+ const style = document.createElement('style');
10
+ style.textContent = `
11
+ #test-suite-filter-search::-webkit-search-decoration,
12
+ #test-suite-filter-search::-webkit-search-cancel-button,
13
+ #test-suite-filter-search::-webkit-search-results-button,
14
+ #test-suite-filter-search::-webkit-search-results-decoration {
15
+ display: none;
16
+ }
17
+ #clear-test-suite-filter-search {
18
+ background: inherit;
19
+ color: #d0d2e0 !important;
20
+ }
21
+ #test-suite-filter-search {
22
+ background: inherit
23
+ }
24
+ `;
25
+
26
+ const specContainer = window.top?.document.querySelector('.spec-container');
27
+ const runnableHeader = window.top?.document.querySelector('.runnable-header');
28
+
29
+ window.top?.document.head.appendChild(style);
30
+ const parentEl = Cypress.version >= '15.0.0' ? specContainer : runnableHeader;
31
+
32
+ parentEl.insertAdjacentHTML(
33
+ 'beforebegin',
34
+ `
35
+ <div class="border-b border-gray-800 h-[64px] mx-[16px] auto-cols-max grid grid-flow-col gap-[8px] grid-cols-[minmax(0,1fr)] pointer-cursor items-center">
36
+ <div class="relative flex items-center w-full h-[48px]">
37
+
38
+ <!-- 🔍 Search Icon (Left) -->
39
+ <div class="absolute left-2 top-1/2 -translate-y-1/2 flex items-center justify-center pointer-events-none">
40
+ <svg
41
+ id="search-icon-test-suite-filter"
42
+ width="16"
43
+ height="16"
44
+ viewBox="0 0 16 16"
45
+ fill="none"
46
+ xmlns="http://www.w3.org/2000/svg"
47
+ class="icon-dark-gray-800 icon-light-gray-1000"
48
+ style="min-width: 16px; min-height: 16px;">
49
+ <path
50
+ d="M12 7C12 8.38071 11.4404 9.63071 10.5355 10.5355C9.63071 11.4404 8.38071 12 7 12C4.23858 12 2 9.76142 2 7C2 4.23858 4.23858 2 7 2C9.76142 2 12 4.23858 12 7Z"
51
+ class="icon-light"
52
+ fill="none" />
53
+ <path
54
+ d="M10.5355 10.5355L14 14M10.5355 10.5355C11.4404 9.63071 12 8.38071 12 7C12 4.23858 9.76142 2 7 2C4.23858 2 2 4.23858 2 7C2 9.76142 4.23858 12 7 12C8.38071 12 9.63071 11.4404 10.5355 10.5355Z"
55
+ class="icon-dark"
56
+ stroke="#1B1E2E"
57
+ stroke-width="2"
58
+ stroke-linecap="round"
59
+ stroke-linejoin="round" />
60
+ </svg>
61
+ </div>
62
+
63
+ <!-- 🏷 Label (Visually Hidden for a11y) -->
64
+ <label
65
+ for="test-suite-filter-search"
66
+ class="cursor-text font-light bottom-[4px] left-[24px] text-gray-500 pointer-events-none absolute sr-only">
67
+ Filter suites/tests
68
+ </label>
69
+
70
+ <!-- 🔤 Input -->
71
+ <input
72
+ id="test-suite-filter-search"
73
+ type="search"
74
+ aria-label="filter search for suites and tests"
75
+ class="pl-8 pr-8 py-3 w-full font-bold text-lg outline-none bg-gray-1100 border-0 placeholder-gray-700 text-white-1500 rounded-md"
76
+ placeholder="Filter suites/tests"
77
+ autocapitalize="off"
78
+ autocomplete="off"
79
+ spellcheck="false"
80
+ />
81
+
82
+ <!-- ❌ Clear Button (Right) -->
83
+ <button
84
+ type="button"
85
+ id="clear-test-suite-filter-search"
86
+ aria-label="Clear search field"
87
+ class="border-transparent rounded-md flex outline-none h-[30px] my-[4px] inset-y-0 right-0 w-[24px] duration-300 absolute items-center justify-center group hocus-default hocus:ring-0">
88
+ <svg
89
+ width="16"
90
+ height="16"
91
+ viewBox="0 0 16 16"
92
+ fill="none"
93
+ xmlns="http://www.w3.org/2000/svg"
94
+ class="icon-light-gray-1000 group-hocus:icon-dark-indigo-300 icon-dark-gray-800"
95
+ style="min-width: 16px; min-height: 16px;">
96
+ <path
97
+ d="M3 13L13 3M3 3L13 13"
98
+ class="icon-dark"
99
+ stroke="#1B1E2E"
100
+ stroke-width="2"
101
+ stroke-linecap="round"
102
+ stroke-linejoin="round" />
103
+ </svg>
104
+ </button>
105
+
106
+ </div>
107
+ </div> `
108
+ );
109
+ }
110
+
111
+ const searchInput = window.top?.document.querySelector(
112
+ '#test-suite-filter-search'
113
+ );
114
+ const clearBtn = window.top?.document.querySelector(
115
+ '#clear-test-suite-filter-search'
116
+ );
117
+
118
+ searchInput?.addEventListener('focus', function () {
119
+ window.top?.document
120
+ .querySelector('#search-icon-test-suite-filter')
121
+ .setAttribute('class', 'icon-dark-indigo-300 icon-light-grey-1700');
122
+ });
123
+
124
+ searchInput?.addEventListener('focusout', function () {
125
+ window.top?.document
126
+ .querySelector('#search-icon-test-suite-filter')
127
+ .setAttribute('class', 'icon-dark-gray-800 icon-light-gray-1000');
128
+ });
129
+
130
+ clearBtn?.addEventListener('click', function () {
131
+ searchInput.value = '';
132
+ searchInput.focus();
133
+ searchInput.dispatchEvent(new Event('input', { bubbles: true }));
134
+ });
135
+
136
+ searchInput?.addEventListener('input', (event) => {
137
+ const searchTerm = event.target.value.toLowerCase();
138
+ const testsAndSuites = window.top?.document.querySelectorAll(
139
+ '.test.runnable, .suite.runnable'
140
+ );
141
+
142
+ for (let i = 0; i < testsAndSuites.length; i++) {
143
+ const itemText = testsAndSuites[i].textContent.toLowerCase();
144
+
145
+ if (itemText.includes(searchTerm)) {
146
+ testsAndSuites[i].style.display = '';
147
+ } 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
+ }
158
+ }
159
+ }
160
+ });
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "cypress-plugin-filter-runnables",
3
+ "version": "1.0.0",
4
+ "description": "Cypress plugin that allows user to filter suites/tests in Cypress Test Runner.",
5
+ "main": "./index.js",
6
+ "keywords": [
7
+ "cypress",
8
+ "testing",
9
+ "cypress-plugin"
10
+ ],
11
+ "devDependencies": {
12
+ "cypress": "^15.5.0"
13
+ },
14
+ "publishConfig": {
15
+ "registry": "https://registry.npmjs.org/"
16
+ },
17
+ "author": "Dennis Bergevin",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/dennisbergevin/cypress-plugin-filter-runnables.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/dennisbergevin/cypress-plugin-filter-runnables/issues"
25
+ },
26
+ "homepage": "https://github.com/dennisbergevin/cypress-plugin-filter-runnables#readme"
27
+ }