cypress-cli-select 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.
Files changed (45) hide show
  1. package/.github/workflows/jest.yml +12 -0
  2. package/CONTRIBUTING.md +39 -0
  3. package/LICENSE.md +21 -0
  4. package/README.md +197 -0
  5. package/assets/choose-spec-pattern-demo.gif +0 -0
  6. package/assets/cypress-cli-select-animated.gif +0 -0
  7. package/assets/print-selected-demo.png +0 -0
  8. package/assets/run-help.gif +0 -0
  9. package/assets/run-spec-tag.gif +0 -0
  10. package/assets/run-spec-title.gif +0 -0
  11. package/cypress/e2e/1-getting-started/todo.cy.js +143 -0
  12. package/cypress/e2e/2-advanced-examples/actions.cy.js +321 -0
  13. package/cypress/e2e/2-advanced-examples/aliasing.cy.js +39 -0
  14. package/cypress/e2e/2-advanced-examples/assertions.cy.js +176 -0
  15. package/cypress/e2e/2-advanced-examples/connectors.cy.js +98 -0
  16. package/cypress/e2e/2-advanced-examples/cookies.cy.js +118 -0
  17. package/cypress/e2e/2-advanced-examples/cypress_api.cy.js +211 -0
  18. package/cypress/e2e/2-advanced-examples/location.cy.js +32 -0
  19. package/cypress/e2e/2-advanced-examples/misc.cy.js +90 -0
  20. package/cypress/e2e/2-advanced-examples/navigation.cy.js +55 -0
  21. package/cypress/e2e/2-advanced-examples/network_requests.cy.js +163 -0
  22. package/cypress/e2e/2-advanced-examples/querying.cy.js +114 -0
  23. package/cypress/e2e/2-advanced-examples/spies_stubs_clocks.cy.js +220 -0
  24. package/cypress/e2e/2-advanced-examples/storage.cy.js +117 -0
  25. package/cypress/e2e/2-advanced-examples/traversal.cy.js +126 -0
  26. package/cypress/e2e/2-advanced-examples/utilities.cy.js +109 -0
  27. package/cypress/e2e/2-advanced-examples/viewport.cy.js +58 -0
  28. package/cypress/e2e/2-advanced-examples/waiting.cy.js +30 -0
  29. package/cypress/e2e/2-advanced-examples/window.cy.js +22 -0
  30. package/cypress/support/commands.js +25 -0
  31. package/cypress/support/component-index.html +14 -0
  32. package/cypress/support/component.js +24 -0
  33. package/cypress/support/e2e.js +19 -0
  34. package/cypress.config.js +25 -0
  35. package/cypress.new.config.js +26 -0
  36. package/index.js +586 -0
  37. package/package.json +46 -0
  38. package/src/components/Clock.cy.js +13 -0
  39. package/src/components/Stepper.cy.js +13 -0
  40. package/src/sortable-list.js +82 -0
  41. package/tapes/run-help.tape +94 -0
  42. package/tapes/run-spec-tag.tape +163 -0
  43. package/tapes/run-spec-title.tape +191 -0
  44. package/tests/cli-component.spec.js +409 -0
  45. package/tests/cli-e2e.spec.js +439 -0
@@ -0,0 +1,12 @@
1
+ name: Jest
2
+ on: push
3
+ jobs:
4
+ test:
5
+ runs-on: ubuntu-latest
6
+ steps:
7
+ - uses: actions/checkout@v4
8
+ - uses: actions/setup-node@v4
9
+ with:
10
+ node-version: 20
11
+ - run: npm ci
12
+ - run: npm test
@@ -0,0 +1,39 @@
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-cli-select
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
+ 1. Run Jest tests via the `npm run test` command
31
+
32
+ 2. Run `npx cypress-cli-select run` to inspect behavior before you commit your changes
33
+
34
+ ## Help needed
35
+
36
+ Please checkout the [the open issues](https://github.com/dennisbergevin/cypress-plugin-cli-select/issues)
37
+
38
+ Also, please watch the repo and respond to questions/bug reports/feature
39
+ 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,197 @@
1
+ <h2 align=center>Cypress cli-select</h2>
2
+ <p align="center">
3
+ </p>
4
+
5
+ <p align="center">
6
+ Cypress interactive cli prompts to select and run specs, tests or tags.
7
+ </p>
8
+
9
+ <img src="./assets/run-spec-title.gif" alt="Cypress-cli-select demo" loop=infinite>
10
+
11
+ ## Features
12
+
13
+ - ⌨ New interactive CLI prompts to select and run specs, tests or tags
14
+ - 👟 A new `cypress run` command to allow user to pass desired arguments
15
+
16
+ #### Table of Contents
17
+
18
+ - [Installation](#installation)
19
+ - [@bahmutov/cy-grep](#bahmutov-cy-grep)
20
+ - [@cypress/grep](#cypress-grep-package)
21
+ - [Run mode](#run-mode)
22
+ - [Keyboard controls](#keyboard-controls)
23
+ - [Test titles or tags](#test-titles-or-tags)
24
+ - [Help mode](#help-mode)
25
+ - [Choose spec pattern](#choose-spec-pattern)
26
+ - [Keyboard controls](#keyboard-controls)
27
+ - [Print selected](#print-selected)
28
+ - [Submit focused](#submit-focused)
29
+ - [Using a custom cypress config](#using-a-custom-cypress-config)
30
+ - [Setting up a `npm` script](#setting-up-a-npm-script)
31
+ - [Typescript support](#typescript-support)
32
+ - [Contributions](#contributions)
33
+
34
+ ---
35
+
36
+ ## Installation
37
+
38
+ 1. Install the following package:
39
+
40
+ ```sh
41
+ npm install --save-dev cypress-cli-select
42
+ ```
43
+
44
+ ### bahmutov cy-grep
45
+
46
+ In order to run specific tests by their title or tag, install the following plugin:
47
+
48
+ ```sh
49
+ npm install --save-dev @bahmutov/cy-grep
50
+ ```
51
+
52
+ Follow the installation and setup for `@bahmutov/cy-grep` in the project [README](https://github.com/bahmutov/cy-grep)
53
+
54
+ ### cypress grep package
55
+
56
+ If you use `@cypress/grep`, you can use this package for specs **or** tag selection, but this package uses functionality not currently supported by `@cypress/grep` to allow for other uses.
57
+
58
+ ---
59
+
60
+ ## Run mode
61
+
62
+ If you want to select e2e specs to run, simply run the following command:
63
+
64
+ ```bash
65
+ npx cypress-cli-select run
66
+ ```
67
+
68
+ For selecting component specs:
69
+
70
+ ```bash
71
+ npx cypress-cli-select run --component
72
+ ```
73
+
74
+ You can also include more cli arguments similar to `cypress run`, as the command harnesses the power of [Cypress module API](https://docs.cypress.io/guides/guides/module-api):
75
+
76
+ ```bash
77
+ # Example
78
+ npx cypress-cli-select run --component --browser=chrome
79
+ ```
80
+
81
+ ### Keyboard controls
82
+
83
+ | Keys | Action |
84
+ | :----------------------------: | :-----------------------------: |
85
+ | <kbd>Up</kbd> | Move to selection above current |
86
+ | <kbd>Down</kbd> | Move to selection below current |
87
+ | <kbd>Tab</kbd> | Select current |
88
+ | <kbd>Ctrl</kbd> + <kbd>a</kbd> | Select all |
89
+ | <kbd>Backspace</kbd> | Remove selection |
90
+ | <kbd>Enter</kbd> | Proceed |
91
+ | <kbd>Ctrl</kbd> + <kbd>c</kbd> | Exit |
92
+
93
+ **Note**: You can also filter choices displayed in list by typing
94
+
95
+ ---
96
+
97
+ ## Test titles or tags
98
+
99
+ If [@bahmutov/cy-grep](https://github.com/bahmutov/cy-grep) package is installed in your project, test titles and tags are available to select.
100
+
101
+ <img src="./assets/run-spec-tag.gif" alt="Cypress-cli-select tag selection" loop=infinite>
102
+
103
+ ---
104
+
105
+ ## Help mode
106
+
107
+ To open the cli help menu, pass the `--help` flag:
108
+
109
+ ```bash
110
+ npx cypress-cli-select run --help
111
+ ```
112
+
113
+ <img src="./assets/run-help.gif" alt="Cypress-cli-select help menu" loop=infinite>
114
+
115
+ ---
116
+
117
+ ## Choose spec pattern
118
+
119
+ If you are interested in running selected specs in a specific order, pass the following flag:
120
+
121
+ ```bash
122
+ npx cypress-cli-select run --choose-spec-pattern
123
+ ```
124
+
125
+ **Note**: If you pass `--choose-spec-pattern` you will not have the choice to run test titles or tags.
126
+
127
+ ### Keyboard controls
128
+
129
+ | Keys | Action |
130
+ | :------------------------------: | :-----------------------------: |
131
+ | <kbd>Up</kbd> | Move to selection above current |
132
+ | <kbd>Down</kbd> | Move to selection below current |
133
+ | <kbd>Shift</kbd> + <kbd>⬆</kbd> | Reorder current up |
134
+ | <kbd>Shift</kbd> + <kbd>⬇</kbd> | Reorder current down |
135
+ | <kbd>Enter</kbd> | Confirm order |
136
+
137
+ <img src="./assets/choose-spec-pattern-demo.gif" alt="Cypress-cli-select choose-spec-pattern demo" loop=infinite>
138
+
139
+ ---
140
+
141
+ ## Print selected
142
+
143
+ If you want to print all selected specs, tests or tags just prior to Cypress run, pass the following flag:
144
+
145
+ ```bash
146
+ npx cypress-cli-select run --print-selected
147
+ ```
148
+
149
+ ![Cypress cli select --print-selected](./assets/print-selected-demo.png)
150
+
151
+ ---
152
+
153
+ ## Submit focused
154
+
155
+ When no other options are already selected, automatically select the currently focused option with <kbd>Enter</kbd>.
156
+
157
+ To enable this feature, pass the following flag:
158
+
159
+ ```bash
160
+ npx cypress-cli-select run --submit-focused
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Using a custom cypress config
166
+
167
+ If you want to use a custom Cypress config, pass it via `--config-file` flag:
168
+
169
+ ```bash
170
+ npx cypress-cli-select run --config-file tests/cypress.config.js
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Setting up a `npm` script
176
+
177
+ For convenience, you may desire to house the `npx` command within an npm script in your project's `package.json`, including any desired cli arguments:
178
+
179
+ ```json
180
+ "scripts": {
181
+ "cy:select": "npx cypress-cli-select run --browser=firefox"
182
+ }
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Typescript support
188
+
189
+ For more information on Typescript support involved with `@bahmutov/cy-grep` package, refer to it's [README](https://github.com/bahmutov/cy-grep?tab=readme-ov-file#typescript-support).
190
+
191
+ ---
192
+
193
+ ## Contributions
194
+
195
+ Feel free to open a pull request or drop any feature request or bug in the [issues](https://github.com/dennisbergevin/cypress-cli-select/issues).
196
+
197
+ Please see more details in the [contributing doc](./CONTRIBUTING.md).
Binary file
Binary file
Binary file
Binary file
@@ -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', () => {
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
+ })