├── .github └── workflows │ └── jest.yml ├── .gitignore ├── .prettierrc ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── index.js ├── jest ├── cli.spec.js └── data │ ├── custom.json │ └── default.json ├── package-lock.json ├── package.json ├── playwright.config.js ├── playwright.dev.config.js ├── tapes ├── run-flags.tape ├── run-help.tape ├── run-last-failed.tape ├── run-only-changed.tape └── run-test.tape └── tests ├── demo-app └── demo-app.spec.js ├── firstDir └── another.spec.js └── secondDir └── example.spec.js /.github/workflows/jest.yml: -------------------------------------------------------------------------------- 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 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Playwright 3 | node_modules/ 4 | /test-results/ 5 | /playwright-report/ 6 | /blob-report/ 7 | /playwright/.cache/ 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "semi": true, 4 | "singleQuote": false 5 | } 6 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 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/playwright-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 test` command 31 | 32 | 2. Run `npx playwright-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/playwright-cli-select/issues) 37 | 38 | Also, please watch the repo and respond to questions/bug reports/feature 39 | requests! Thanks! 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
3 |
4 | 5 |6 | Playwright interactive cli prompts to select and run specs, tests or tags. 7 |
8 | 9 |  10 | 11 | ## Features 12 | 13 | - ❓ New interactive CLI prompts to select and run specs, tests or tags 14 | - 🎭 A new `playwright test` command to allow user to pass desired arguments 15 | 16 | ### External Resources 17 | 18 | - [Dev blog: playwright-cli-select](https://dev.to/dennisbergevin/playwright-cli-select-12j) 19 | 20 | #### Table of Contents 21 | 22 | - [Installation](#installation) 23 | - [Run mode](#run-mode) 24 | - [Command line arguments](#command-line-arguments) 25 | - [Using last failed](#using-last-failed) 26 | - [Using only changed](#using-only-changed) 27 | - [UI mode](#ui-mode) 28 | - [Keyboard controls](#keyboard-controls) 29 | - [Help mode](#help-mode) 30 | - [Submit focused](#submit-focused) 31 | - [Optional path to test list json](#optional-path-to-test-list-json) 32 | - [Using a custom playwright config file](#using-a-custom-playwright-config-file) 33 | - [Setting up a `npm` script](#setting-up-a-npm-script) 34 | - [Contributions](#contributions) 35 | 36 | --- 37 | 38 | ## Installation 39 | 40 | Install the following package: 41 | 42 | ```bash 43 | npm install --save-dev playwright-cli-select 44 | # within your Playwright repository as dev dependency 45 | ``` 46 | 47 | Or: 48 | 49 | ```bash 50 | npm install -g playwright-cli-select 51 | # global install 52 | ``` 53 | 54 | --- 55 | 56 | ## Run mode 57 | 58 | Run the following command in your Playwright repository: 59 | 60 | ```bash 61 | npx playwright-cli-select run 62 | ``` 63 | 64 | If you want to skip straight to selecting specs, titles and/or tags: 65 | 66 | ```bash 67 | npx playwright-cli-select run --specs 68 | # skips straight to spec selection 69 | ``` 70 | 71 | ```bash 72 | npx playwright-cli-select run --titles 73 | # skips to test title selection 74 | ``` 75 | 76 | ```bash 77 | npx playwright-cli-select run --tags 78 | # skips to tag selection 79 | ``` 80 | 81 | ```bash 82 | npx playwright-cli-select run --titles --tags 83 | # skips to test title selection, followed by tag selection 84 | # Any combination of `--specs`, `--titles` and/or `--tags` parameters is permitted. 85 | ``` 86 | 87 |  88 | 89 | --- 90 | 91 | ## Command line arguments 92 | 93 | You can also include more cli arguments similar to `npx playwright test`: 94 | 95 | ```bash 96 | npx playwright-cli-select run --project firefox webkit 97 | ``` 98 | 99 | ### Using last failed 100 | 101 | Passing Playwright's `--last-failed` parameter filters the available selections in each prompt to the last failed tests. 102 | 103 | Using this package, you can further drill down on specific tests within the last failed tests: 104 | 105 | ```sh 106 | npx playwright-cli-select run --last-failed 107 | ``` 108 | 109 |  110 | 111 | --- 112 | 113 | ### Using only changed 114 | 115 | Passing Playwright's `--only-changed` parameter filters available selections to the changed tests detected. 116 | 117 | To specify a specific subset of changed tests rather than running entire changed test files: 118 | 119 | ```sh 120 | npx playwright-cli-select run --only-changed 121 | ``` 122 | 123 |  124 | 125 | --- 126 | 127 | ## UI mode 128 | 129 | You can append the `--ui` or `--headed` parameters to open a browser and view selected specs, test titles and/or tags: 130 | 131 | ```bash 132 | npx playwright-cli-select run --ui 133 | ``` 134 | 135 | Or: 136 | 137 | ```bash 138 | npx playwright-cli-select run --titles --headed 139 | # Example of choosing only test titles to run headed 140 | ``` 141 | 142 | --- 143 | 144 | ### Keyboard controls 145 | 146 | | Keys | Action | 147 | | :----------------------------: | :-----------------------------: | 148 | | Up | Move to selection above current | 149 | | Down | Move to selection below current | 150 | | Tab | Select current | 151 | | Ctrl + a | Select all | 152 | | Backspace | Remove selection | 153 | | Enter | Proceed | 154 | | Ctrl + c | Exit | 155 | 156 | **Note**: You can also filter choices displayed in list by typing 157 | 158 | --- 159 | 160 | ## Help mode 161 | 162 | To open the cli help menu, pass the `--help` flag: 163 | 164 | ```bash 165 | npx playwright-cli-select run --help 166 | ``` 167 | 168 |  169 | 170 | --- 171 | 172 | ## Submit focused 173 | 174 | When no other options are already selected, automatically select the currently focused option with Enter. 175 | 176 | To enable this feature, pass the following flag: 177 | 178 | ```bash 179 | npx playwright-cli-select run --submit-focused 180 | ``` 181 | 182 | --- 183 | 184 | ## Optional path to test list json 185 | 186 | This package uses the `npx playwright test --list --reporter=json` command to gather information about Playwright tests. 187 | 188 | If you prefer or already house the data from this command in a file, pass the path to the file via the `--json-data-path` parameter: 189 | 190 | ```bash 191 | npx playwright-cli-select run --json-data-path data/sample-test-list.json 192 | ``` 193 | 194 | --- 195 | 196 | ## Using a custom playwright config file 197 | 198 | If you want to use a custom Playwright config, pass it via the `-c` or `--config` flag: 199 | 200 | ```bash 201 | npx playwright-cli-select run --config playwright.staging.config.js 202 | ``` 203 | 204 | Or: 205 | 206 | ```bash 207 | npx playwright-cli-select run -c playwright.dev.config.js 208 | ``` 209 | 210 | --- 211 | 212 | ## Setting up a `npm` script 213 | 214 | 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: 215 | 216 | ```json 217 | "scripts": { 218 | "pw:select": "npx playwright-cli-select run --project=firefox" 219 | } 220 | ``` 221 | 222 | --- 223 | 224 | ## Contributions 225 | 226 | Feel free to open a pull request or drop any feature request or bug in the [issues](https://github.com/dennisbergevin/playwright-cli-select/issues). 227 | 228 | Please see more details in the [contributing doc](./CONTRIBUTING.md). 229 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const { execSync, spawn } = require("child_process"); 4 | const Fuse = require("fuse.js"); 5 | const pc = require("picocolors"); 6 | const fs = require("fs"); 7 | const yarg = require("yargs"); 8 | const { select } = require("inquirer-select-pro"); 9 | 10 | // walk the suites structure from the json reporter 11 | // collect file:line, suite > name and tags 12 | function iterateObject( 13 | obj, 14 | baseArr, 15 | continuedArr, 16 | tagArr, 17 | baseTagArr, 18 | fileName 19 | ) { 20 | if (obj.specs) { 21 | obj.specs.forEach((spec) => { 22 | let newerarr = [...continuedArr, spec.title]; 23 | const testObj = { 24 | title: newerarr, 25 | tags: spec.tags, 26 | line: `${fileName}:${spec.line}`, 27 | }; 28 | tagArr.push(spec.tags); 29 | baseTagArr.push(tagArr); 30 | baseArr.push(testObj); 31 | }); 32 | } 33 | 34 | if (obj.suites) { 35 | obj.suites.forEach((suite) => { 36 | let evenNewerArr = [...continuedArr, suite.title]; 37 | const suiteObj = { 38 | title: evenNewerArr, 39 | line: `${fileName}:${suite.line}`, 40 | }; 41 | baseArr.push(suiteObj); 42 | iterateObject(suite, baseArr, evenNewerArr, tagArr, baseTagArr, fileName); 43 | }); 44 | } 45 | } 46 | 47 | // Used to remove a process argument before executing Cypress run 48 | function findAndRemoveArgv(arg) { 49 | const argToRemove = arg; 50 | const index = process.argv.indexOf(argToRemove); 51 | if (index > -1) { 52 | process.argv.splice(index, 1); // Remove the argument 53 | } 54 | } 55 | 56 | async function getTests() { 57 | // help menu options 58 | yarg 59 | .completion("--specs", false) 60 | .option("specs", { 61 | desc: "Skips to spec selection prompt", 62 | type: "boolean", 63 | }) 64 | .example("npx playwright-cli-select run --specs"); 65 | 66 | yarg 67 | .completion("--titles", false) 68 | .option("titles", { 69 | desc: "Skips to test title selection prompt", 70 | type: "boolean", 71 | }) 72 | .example("npx playwright-cli-select run --titles"); 73 | 74 | yarg 75 | .completion("--tags", false) 76 | .option("tags", { 77 | desc: "Skips to tag selection prompt", 78 | type: "boolean", 79 | }) 80 | .example("npx playwright-cli-select run --tags"); 81 | 82 | yarg 83 | .completion("--json-data-path", false) 84 | .option("json-data-path", { 85 | desc: "Optional path of file housing output of \n`npx playwright test --list --reporter=json`", 86 | type: "string", 87 | }) 88 | .example( 89 | "npx playwright-cli-select run --json-data-path data/sample-test-list.json" 90 | ); 91 | 92 | yarg 93 | .completion("--submit-focused", false) 94 | .option("submit-focused", { 95 | desc: "Selects and submits focused item using enter", 96 | type: "boolean", 97 | }) 98 | .example("npx playwright-cli-select run --submit-focused"); 99 | 100 | yarg 101 | .scriptName("npx playwright-cli-select run") 102 | .usage( 103 | "\nInteractive cli prompts to select Playwright specs, tests or tags run\n" 104 | ) 105 | .usage("$0 [args]") 106 | .example("npx playwright-cli-select run --project=firefox") 107 | .help().argv; 108 | 109 | if (process.argv.includes("--submit-focused")) { 110 | findAndRemoveArgv("--submit-focused"); 111 | process.env.SUBMIT_FOCUSED = true; 112 | } 113 | 114 | if (process.argv.includes("--titles")) { 115 | findAndRemoveArgv("--titles"); 116 | process.env.TEST_TITLES = true; 117 | } 118 | 119 | if (process.argv.includes("--specs")) { 120 | findAndRemoveArgv("--specs"); 121 | process.env.TEST_SPECS = true; 122 | } 123 | 124 | if (process.argv.includes("--tags")) { 125 | findAndRemoveArgv("--tags"); 126 | process.env.TEST_TAGS = true; 127 | } 128 | 129 | if (process.argv.includes("--ui")) { 130 | findAndRemoveArgv("--ui"); 131 | process.env.TEST_IN_UI_MODE = "--ui"; 132 | } 133 | 134 | if (process.argv.includes("--json-data-path")) { 135 | const index = process.argv.indexOf("--json-data-path"); 136 | process.env.JSON_TEST_DATA = await fs.promises.readFile( 137 | `${process.argv[index + 1]}`, 138 | "utf8" 139 | ); 140 | findAndRemoveArgv(process.argv[index + 1]); 141 | findAndRemoveArgv("--json-data-path"); 142 | } 143 | 144 | process.argv.forEach((arg, index) => { 145 | if (arg.includes("--reporter=")) { 146 | process.env.TEST_REPORTER_TYPE = process.argv[index]; 147 | findAndRemoveArgv(process.argv[index]); 148 | } 149 | }); 150 | 151 | // collect all arguments passed to command 152 | // remove the 'run' 153 | if (process.argv.includes("--reporter")) { 154 | const index = process.argv.indexOf("--reporter"); 155 | process.env.TEST_REPORTER_TYPE = `--reporter ${process.argv[index + 1]}`; 156 | findAndRemoveArgv(process.argv[index + 1]); 157 | findAndRemoveArgv("--reporter"); 158 | } 159 | 160 | // collect all arguments passed to npx command 161 | let args = process.argv.slice(2); 162 | // remove 'run' 163 | args.shift(); 164 | 165 | // add arguments to test list command 166 | let getTestCommand = `npx playwright test --list --reporter=json ${args.join(" ").toString()}`; 167 | 168 | // collect test data 169 | // if --json-data-path flag is not used, exec --list --reporter=json command 170 | if (!process.env.JSON_TEST_DATA) { 171 | try { 172 | process.env.JSON_TEST_DATA = execSync(getTestCommand, { 173 | encoding: "utf-8", 174 | stdio: "pipe", 175 | }); 176 | } catch (e) { 177 | if (e.stdout.includes("Error: No tests found")) { 178 | console.log("\n"); 179 | console.log(pc.redBright(pc.bold("Error: No tests found"))); 180 | process.exit(); 181 | } else if (e.stdout.includes("Error: Cannot detect changed files")) { 182 | console.log("\n"); 183 | console.log( 184 | pc.redBright(pc.bold("Error: Cannot detect changed files")) 185 | ); 186 | process.exit(); 187 | } else { 188 | console.log(e); 189 | process.exit(); 190 | } 191 | } 192 | } 193 | 194 | const testJSON = JSON.parse(process.env.JSON_TEST_DATA); 195 | const baseArr = []; 196 | const baseTagArr = []; 197 | const tagArr = []; 198 | let fileArr = []; 199 | let newarr = []; 200 | let grepString = ""; 201 | 202 | testJSON.suites.forEach((suite) => { 203 | const singleTests = suite.specs; 204 | const fileName = suite.file; 205 | fileArr.push(fileName); 206 | 207 | singleTests.forEach((test) => { 208 | newarr = [suite.file, test.title]; 209 | const testObj = { 210 | title: newarr, 211 | tags: test.tags, 212 | line: `${suite.file}:${test.line}`, 213 | }; 214 | baseArr.push(testObj); 215 | tagArr.push(test.tags); 216 | baseTagArr.push(tagArr); 217 | }); 218 | 219 | if (suite.suites) { 220 | suite.suites.forEach((nextSuite) => { 221 | newarr = [suite.file, nextSuite.title]; 222 | const suiteObj = { 223 | title: newarr, 224 | line: `${suite.file}:${nextSuite.line}`, 225 | }; 226 | baseArr.push(suiteObj); 227 | tagArr.push(nextSuite.tags); 228 | baseTagArr.push(tagArr); 229 | 230 | iterateObject(nextSuite, baseArr, newarr, tagArr, baseTagArr, fileName); 231 | }); 232 | } 233 | }); 234 | 235 | // check for tags that are duplicate and store unique tags in array for prompt 236 | function hasDuplicateArrays(arr, newArr) { 237 | const seen = new Set(); 238 | const array = arr.flat(); 239 | for (const subArray of array) { 240 | const stringified = JSON.stringify(subArray); 241 | if ( 242 | !seen.has(stringified) && 243 | stringified !== undefined && 244 | stringified !== "" && 245 | stringified !== "[]" 246 | ) { 247 | newArr.push(subArray); 248 | } 249 | seen.add(stringified); 250 | } 251 | return newArr; 252 | } 253 | 254 | // Playwright-cli-select title 255 | console.log("\n"); 256 | console.log(pc.bold(`🎭 Playwright-cli-select `)); 257 | console.log("\n"); 258 | 259 | // check if there are tags, disable tag choice in prompt if none 260 | const tags = hasDuplicateArrays(baseTagArr.flat(), []); 261 | 262 | if (tags.length === 0) { 263 | process.env.DISABLE_TAGS_CHOICE = true; 264 | } 265 | 266 | try { 267 | // open the first interactive prompt if no --specs, --titles, --tags 268 | if ( 269 | !process.env.TEST_TITLES && 270 | !process.env.TEST_SPECS && 271 | !process.env.TEST_TAGS 272 | ) { 273 | const specAndTestPrompt = await select({ 274 | message: "Choose to filter by specs, specific test titles or tags: ", 275 | multiple: true, 276 | clearInputWhenSelected: true, 277 | selectFocusedOnSubmit: process.env.SUBMIT_FOCUSED, 278 | canToggleAll: true, 279 | options: [ 280 | { 281 | name: "Specs", 282 | value: "Specs", 283 | }, 284 | { 285 | name: "Test titles", 286 | value: "Test titles", 287 | }, 288 | { 289 | name: "Tags", 290 | value: "Tags", 291 | disabled: process.env.DISABLE_TAGS_CHOICE ? true : false, 292 | }, 293 | ], 294 | required: true, 295 | }); 296 | if (specAndTestPrompt.includes("Specs")) { 297 | process.env.TEST_SPECS = true; 298 | } 299 | if (specAndTestPrompt.includes("Test titles")) { 300 | process.env.TEST_TITLES = true; 301 | } 302 | if (specAndTestPrompt.includes("Tags")) { 303 | process.env.TEST_TAGS = true; 304 | } 305 | } 306 | 307 | if (process.env.TEST_SPECS) { 308 | if (fileArr.length > 0) { 309 | function specsChoices() { 310 | let arr = []; 311 | fileArr.forEach((element) => { 312 | const spec = { 313 | name: element, 314 | value: element, 315 | }; 316 | arr.push(spec); 317 | }); 318 | return arr; 319 | } 320 | 321 | const specSelections = await select({ 322 | message: "Select specs to run:", 323 | multiple: true, 324 | required: true, 325 | clearInputWhenSelected: true, 326 | selectFocusedOnSubmit: process.env.SUBMIT_FOCUSED, 327 | canToggleAll: true, 328 | options: (input = "") => { 329 | const specs = specsChoices(); 330 | 331 | const fuse = new Fuse(specs, { 332 | keys: ["value"], 333 | }); 334 | 335 | if (!input) return specs; 336 | if (fuse) { 337 | const result = fuse.search(input).map(({ item }) => item); 338 | return result; 339 | } 340 | return []; 341 | }, 342 | }); 343 | specSelections.forEach((spec) => { 344 | grepString += `${spec} `; 345 | }); 346 | } else { 347 | console.log(pc.redBright(pc.bold("No test files/specs detected"))); 348 | process.exit(); 349 | } 350 | } 351 | 352 | if (process.env.TEST_TITLES) { 353 | const uniqueArray = [ 354 | ...new Set(baseArr.map((obj) => JSON.stringify(obj))), 355 | ].map((str) => JSON.parse(str)); 356 | 357 | if (uniqueArray.length > 0) { 358 | // organize suite/test titles into title prompt format 359 | // value will be the file:line format while user will see suite > test format 360 | const testChoices = () => { 361 | let arr = []; 362 | uniqueArray.forEach((element) => { 363 | const choices = { 364 | name: element.title.join(" › "), 365 | value: element.line, 366 | }; 367 | arr.push(choices); 368 | }); 369 | return arr; 370 | }; 371 | const selectedTests = await select({ 372 | message: "Select tests to run:", 373 | multiple: true, 374 | clearInputWhenSelected: true, 375 | selectFocusedOnSubmit: process.env.SUBMIT_FOCUSED, 376 | required: true, 377 | options: (input = "") => { 378 | const tests = testChoices(); 379 | 380 | const fuse = new Fuse(tests, { 381 | keys: ["name"], 382 | ignoreLocation: true, 383 | }); 384 | 385 | if (!input) return tests; 386 | if (fuse) { 387 | const result = fuse.search(input).map(({ item }) => item); 388 | return result; 389 | } 390 | return []; 391 | }, 392 | }); 393 | selectedTests.forEach((test) => { 394 | grepString += `${test} `; 395 | }); 396 | } else { 397 | console.log(pc.redBright(pc.bold("No tests detected"))); 398 | process.exit(); 399 | } 400 | } 401 | 402 | if (process.env.TEST_TAGS) { 403 | const flatTagArr = baseTagArr.flat(); 404 | const uniqueTagArray = []; 405 | const tags = hasDuplicateArrays(flatTagArr, uniqueTagArray); 406 | const uniqueArray = [ 407 | ...new Set(baseArr.map((obj) => JSON.stringify(obj))), 408 | ].map((str) => JSON.parse(str)); 409 | const tagArr = []; 410 | 411 | // add file:line for every test that includes a specific tag 412 | tags.forEach((tag) => { 413 | const testLines = []; 414 | uniqueArray.forEach((obj) => { 415 | if (obj.tags?.includes(tag)) { 416 | testLines.push(obj.line); 417 | } 418 | }); 419 | // organize tags with file:line values for tag prompt 420 | tagArr.push({ 421 | name: tag, 422 | value: testLines.join(" "), 423 | }); 424 | }); 425 | if (tags.length > 0) { 426 | // sort the tags presented 427 | tagArr.sort(); 428 | 429 | const selectedTags = await select({ 430 | message: "Select tags to run:", 431 | multiple: true, 432 | clearInputWhenSelected: true, 433 | selectFocusedOnSubmit: process.env.SUBMIT_FOCUSED, 434 | required: true, 435 | options: (input = "") => { 436 | const tags = tagArr; 437 | 438 | const fuse = new Fuse(tags, { 439 | keys: ["name"], 440 | }); 441 | 442 | if (!input) return tags; 443 | if (fuse) { 444 | const result = fuse.search(input).map(({ item }) => item); 445 | return result; 446 | } 447 | return []; 448 | }, 449 | }); 450 | selectedTags.forEach((tag) => { 451 | grepString += `${tag} `; 452 | }); 453 | } else { 454 | console.log(pc.redBright(pc.bold("No tags detected"))); 455 | process.exit(); 456 | } 457 | } 458 | } catch (e) { 459 | // if user closes prompt send a error message instead of inquirer.js error 460 | if (e.message.includes("User force closed the prompt")) { 461 | console.log("\n"); 462 | console.log(pc.redBright(pc.bold("The prompt was closed"))); 463 | process.exit(); 464 | } else { 465 | console.log(e); 466 | process.exit(); 467 | } 468 | } 469 | 470 | // remove the last " " from the grep string 471 | const newGrepString = grepString.slice(0, -1); 472 | args.unshift(`${newGrepString}`); 473 | // add --reporter back to npx playwright test command if necessary 474 | if (process.env.TEST_REPORTER_TYPE) { 475 | args.push(process.env.TEST_REPORTER_TYPE); 476 | } 477 | // add --ui back to arguments for the npx playwright test command if necessary 478 | if (process.env.TEST_IN_UI_MODE) { 479 | args.push(process.env.TEST_IN_UI_MODE); 480 | } 481 | console.log(); 482 | console.log("Arguments: "); 483 | console.log(); 484 | console.log(args); 485 | console.log(); 486 | 487 | spawn("npx playwright test", args, { 488 | shell: true, 489 | stdio: "inherit", 490 | }); 491 | } 492 | 493 | getTests(); 494 | -------------------------------------------------------------------------------- /jest/cli.spec.js: -------------------------------------------------------------------------------- 1 | const { describe, it, expect } = require("@jest/globals"); 2 | const { render } = require("cli-testing-library"); 3 | const { resolve } = require("path"); 4 | require("cli-testing-library/extend-expect"); 5 | const data = require("./data/default.json"); 6 | 7 | describe("basic input prompt flows", () => { 8 | it("handles spec select", async () => { 9 | const { findByText, userEvent } = await render("cd ../../../ && node", [ 10 | resolve(__dirname, "../index.js"), 11 | ["--submit-focused"], 12 | ["--json-data-path"], 13 | [resolve(__dirname, "./data/default.json")], 14 | ]); 15 | 16 | expect( 17 | await findByText( 18 | "Choose to filter by specs, specific test titles or tags" 19 | ) 20 | ).toBeInTheConsole(); 21 | 22 | expect(await findByText("Specs")).toBeInTheConsole(); 23 | expect(await findByText("Test titles")).toBeInTheConsole(); 24 | expect(await findByText("Tags")).toBeInTheConsole(); 25 | 26 | userEvent.keyboard("[Enter]"); 27 | 28 | expect(await findByText("Select specs to run")).toBeInTheConsole(); 29 | expect(await findByText("firstDir/another.spec.js")).toBeInTheConsole(); 30 | expect(await findByText("secondDir/example.spec.js")).toBeInTheConsole(); 31 | 32 | userEvent.keyboard("[Enter]"); 33 | 34 | expect(await findByText("Arguments:")).toBeInTheConsole(); 35 | }); 36 | 37 | it("handles test title select", async () => { 38 | const { findByText, userEvent } = await render("cd ../../../ && node", [ 39 | resolve(__dirname, "../index.js"), 40 | ["--submit-focused"], 41 | ["--json-data-path"], 42 | [resolve(__dirname, "./data/default.json")], 43 | ]); 44 | 45 | expect( 46 | await findByText( 47 | "Choose to filter by specs, specific test titles or tags" 48 | ) 49 | ).toBeInTheConsole(); 50 | 51 | expect(await findByText("Specs")).toBeInTheConsole(); 52 | expect(await findByText("Test titles")).toBeInTheConsole(); 53 | expect(await findByText("Tags")).toBeInTheConsole(); 54 | 55 | userEvent.keyboard("[ArrowDown]"); 56 | userEvent.keyboard("[Enter]"); 57 | 58 | expect(await findByText("Select tests to run")).toBeInTheConsole(); 59 | expect( 60 | await findByText("firstDir/another.spec.js › New tests @new") 61 | ).toBeInTheConsole(); 62 | 63 | userEvent.keyboard("[Enter]"); 64 | expect(await findByText("Arguments")).toBeInTheConsole(); 65 | }); 66 | 67 | it("handles tag select", async () => { 68 | const { findByText, userEvent } = await render("cd ../../../ && node", [ 69 | resolve(__dirname, "../index.js"), 70 | ["--submit-focused"], 71 | ["--json-data-path"], 72 | [resolve(__dirname, "./data/default.json")], 73 | ]); 74 | 75 | expect( 76 | await findByText( 77 | "Choose to filter by specs, specific test titles or tags" 78 | ) 79 | ).toBeInTheConsole(); 80 | 81 | expect(await findByText("Specs")).toBeInTheConsole(); 82 | expect(await findByText("Test titles")).toBeInTheConsole(); 83 | expect(await findByText("Tags")).toBeInTheConsole(); 84 | 85 | userEvent.keyboard("[ArrowDown]"); 86 | userEvent.keyboard("[ArrowDown]"); 87 | userEvent.keyboard("[Enter]"); 88 | 89 | expect(await findByText("Select tags to run")).toBeInTheConsole(); 90 | expect(await findByText("deeply-nested")).toBeInTheConsole(); 91 | 92 | userEvent.keyboard("[Enter]"); 93 | expect(await findByText("Arguments:")).toBeInTheConsole(); 94 | }); 95 | 96 | it("--spec flag starts at spec selection", async () => { 97 | const { findByText, userEvent } = await render("cd ../../../ && node", [ 98 | resolve(__dirname, "../index.js"), 99 | ["--submit-focused"], 100 | ["--json-data-path"], 101 | [resolve(__dirname, "./data/default.json")], 102 | ["--specs"], 103 | ]); 104 | 105 | expect(await findByText("Select specs to run")).toBeInTheConsole(); 106 | expect(await findByText("firstDir/another.spec.js")).toBeInTheConsole(); 107 | }); 108 | 109 | it("--titles flag starts at test title selection", async () => { 110 | const { findByText, userEvent } = await render("cd ../../../ && node", [ 111 | resolve(__dirname, "../index.js"), 112 | ["--submit-focused"], 113 | ["--json-data-path"], 114 | [resolve(__dirname, "./data/default.json")], 115 | ["--titles"], 116 | ]); 117 | 118 | expect(await findByText("Select tests to run")).toBeInTheConsole(); 119 | expect( 120 | await findByText("firstDir/another.spec.js › New tests @new") 121 | ).toBeInTheConsole(); 122 | }); 123 | 124 | it("--tags flag starts at tag selection", async () => { 125 | const { findByText, userEvent } = await render("cd ../../../ && node", [ 126 | resolve(__dirname, "../index.js"), 127 | ["--submit-focused"], 128 | ["--json-data-path"], 129 | [resolve(__dirname, "./data/default.json")], 130 | ["--tags"], 131 | ]); 132 | 133 | expect(await findByText("Select tags to run")).toBeInTheConsole(); 134 | expect(await findByText("deeply-nested")).toBeInTheConsole(); 135 | }); 136 | }); 137 | 138 | describe("handles prompt searching", () => { 139 | it("handles searching", async () => { 140 | const { findByText, userEvent } = await render("cd ../../../ && node", [ 141 | resolve(__dirname, "../index.js"), 142 | ["--submit-focused"], 143 | ["--json-data-path"], 144 | [resolve(__dirname, "./data/default.json")], 145 | ]); 146 | 147 | expect( 148 | await findByText( 149 | "Choose to filter by specs, specific test titles or tags" 150 | ) 151 | ).toBeInTheConsole(); 152 | 153 | expect(await findByText("Specs")).toBeInTheConsole(); 154 | expect(await findByText("Test titles")).toBeInTheConsole(); 155 | expect(await findByText("Tags")).toBeInTheConsole(); 156 | 157 | userEvent.keyboard("[Enter]"); 158 | 159 | expect(await findByText("Select specs to run")).toBeInTheConsole(); 160 | expect(await findByText("firstDir/another.spec.js")).toBeInTheConsole(); 161 | expect(await findByText("secondDir/example.spec.js")).toBeInTheConsole(); 162 | 163 | await userEvent.keyboard("firstDir[Enter]", { delay: 300 }); 164 | 165 | expect(await findByText("firstDir/another.spec.js")).toBeInTheConsole(); 166 | 167 | expect(await findByText("Arguments:")).toBeInTheConsole(); 168 | }); 169 | }); 170 | 171 | describe("accepts custom config", () => { 172 | it("specs: passing --config reads testDir", async () => { 173 | const { findByText, queryByText, userEvent } = await render( 174 | "cd ../../../ && node", 175 | [ 176 | resolve(__dirname, "../index.js"), 177 | ["--submit-focused"], 178 | ["--config"], 179 | ["playwright.dev.config.js"], 180 | ["--json-data-path"], 181 | [resolve(__dirname, "./data/custom.json")], 182 | ] 183 | ); 184 | 185 | expect( 186 | await findByText( 187 | "Choose to filter by specs, specific test titles or tags" 188 | ) 189 | ).toBeInTheConsole(); 190 | 191 | expect(await findByText("Specs")).toBeInTheConsole(); 192 | expect(await findByText("Test titles")).toBeInTheConsole(); 193 | expect(await findByText("Tags")).toBeInTheConsole(); 194 | 195 | userEvent.keyboard("[Enter]"); 196 | 197 | expect(await findByText("Select specs to run")).toBeInTheConsole(); 198 | expect(await findByText("example.spec.js")).toBeInTheConsole(); 199 | expect(await queryByText("another.spec.js")).not.toBeInTheConsole(); 200 | 201 | userEvent.keyboard("[Enter]"); 202 | 203 | expect(await findByText("Arguments:")).toBeInTheConsole(); 204 | }); 205 | 206 | it("titles: passing --config reads testDir", async () => { 207 | const { findByText, queryByText, userEvent } = await render( 208 | "cd ../../../ && node", 209 | [ 210 | resolve(__dirname, "../index.js"), 211 | ["--submit-focused"], 212 | ["--config"], 213 | ["playwright.dev.config.js"], 214 | ["--json-data-path"], 215 | [resolve(__dirname, "./data/custom.json")], 216 | ] 217 | ); 218 | 219 | expect( 220 | await findByText( 221 | "Choose to filter by specs, specific test titles or tags" 222 | ) 223 | ).toBeInTheConsole(); 224 | 225 | expect(await findByText("Specs")).toBeInTheConsole(); 226 | expect(await findByText("Test titles")).toBeInTheConsole(); 227 | expect(await findByText("Tags")).toBeInTheConsole(); 228 | 229 | userEvent.keyboard("[ArrowDown]"); 230 | userEvent.keyboard("[Enter]"); 231 | 232 | expect(await findByText("Select tests to run")).toBeInTheConsole(); 233 | expect( 234 | await findByText("example.spec.js › outside test") 235 | ).toBeInTheConsole(); 236 | 237 | expect(await queryByText("another.spec.js")).not.toBeInTheConsole(); 238 | 239 | userEvent.keyboard("[Enter]"); 240 | 241 | expect(await findByText("Arguments:")).toBeInTheConsole(); 242 | }); 243 | 244 | it("tags: passing --config reads testDir", async () => { 245 | const { findByText, queryByText, userEvent } = await render( 246 | "cd ../../../ && node", 247 | [ 248 | resolve(__dirname, "../index.js"), 249 | ["--submit-focused"], 250 | ["--config"], 251 | ["playwright.dev.config.js"], 252 | ["--json-data-path"], 253 | [resolve(__dirname, "./data/custom.json")], 254 | ] 255 | ); 256 | 257 | expect( 258 | await findByText( 259 | "Choose to filter by specs, specific test titles or tags" 260 | ) 261 | ).toBeInTheConsole(); 262 | 263 | expect(await findByText("Specs")).toBeInTheConsole(); 264 | expect(await findByText("Test titles")).toBeInTheConsole(); 265 | expect(await findByText("Tags")).toBeInTheConsole(); 266 | 267 | userEvent.keyboard("[ArrowDown]"); 268 | userEvent.keyboard("[ArrowDown]"); 269 | userEvent.keyboard("[Enter]"); 270 | 271 | expect(await findByText("Select tags to run")).toBeInTheConsole(); 272 | expect(await findByText("nested")).toBeInTheConsole(); 273 | 274 | expect(await queryByText("deeply-nested")).not.toBeInTheConsole(); 275 | 276 | userEvent.keyboard("[Enter]"); 277 | 278 | expect(await findByText("Arguments:")).toBeInTheConsole(); 279 | }); 280 | }); 281 | -------------------------------------------------------------------------------- /jest/data/custom.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "configFile": "./playwright-cli-select/playwright.dev.config.js", 4 | "rootDir": "./playwright-cli-select/tests/secondDir", 5 | "forbidOnly": false, 6 | "fullyParallel": true, 7 | "globalSetup": null, 8 | "globalTeardown": null, 9 | "globalTimeout": 0, 10 | "grep": {}, 11 | "grepInvert": null, 12 | "maxFailures": 0, 13 | "metadata": {}, 14 | "preserveOutput": "always", 15 | "reporter": [["json"]], 16 | "reportSlowTests": { 17 | "max": 5, 18 | "threshold": 15000 19 | }, 20 | "quiet": false, 21 | "projects": [ 22 | { 23 | "outputDir": "./playwright-cli-select/test-results", 24 | "repeatEach": 1, 25 | "retries": 0, 26 | "metadata": {}, 27 | "id": "chromium", 28 | "name": "chromium", 29 | "testDir": "./playwright-cli-select/tests/secondDir", 30 | "testIgnore": [], 31 | "testMatch": ["**/*.@(spec|test).?(c|m)[jt]s?(x)"], 32 | "timeout": 30000 33 | }, 34 | { 35 | "outputDir": "./playwright-cli-select/test-results", 36 | "repeatEach": 1, 37 | "retries": 0, 38 | "metadata": {}, 39 | "id": "firefox", 40 | "name": "firefox", 41 | "testDir": "./playwright-cli-select/tests/secondDir", 42 | "testIgnore": [], 43 | "testMatch": ["**/*.@(spec|test).?(c|m)[jt]s?(x)"], 44 | "timeout": 30000 45 | }, 46 | { 47 | "outputDir": "./playwright-cli-select/test-results", 48 | "repeatEach": 1, 49 | "retries": 0, 50 | "metadata": {}, 51 | "id": "webkit", 52 | "name": "webkit", 53 | "testDir": "./playwright-cli-select/tests/secondDir", 54 | "testIgnore": [], 55 | "testMatch": ["**/*.@(spec|test).?(c|m)[jt]s?(x)"], 56 | "timeout": 30000 57 | } 58 | ], 59 | "shard": null, 60 | "updateSnapshots": "missing", 61 | "updateSourceMethod": "patch", 62 | "version": "1.50.1", 63 | "workers": 4, 64 | "webServer": null 65 | }, 66 | "suites": [ 67 | { 68 | "title": "example.spec.js", 69 | "file": "example.spec.js", 70 | "column": 0, 71 | "line": 0, 72 | "specs": [ 73 | { 74 | "title": "outside test", 75 | "ok": true, 76 | "tags": ["smoke", "sanity"], 77 | "tests": [ 78 | { 79 | "timeout": 30000, 80 | "annotations": [], 81 | "expectedStatus": "passed", 82 | "projectId": "chromium", 83 | "projectName": "chromium", 84 | "results": [], 85 | "status": "skipped" 86 | } 87 | ], 88 | "id": "dd9b2edffe9b7501040c-cb4d89943ee10f9e78f8", 89 | "file": "example.spec.js", 90 | "line": 37, 91 | "column": 5 92 | }, 93 | { 94 | "title": "outside test", 95 | "ok": true, 96 | "tags": ["smoke", "sanity"], 97 | "tests": [ 98 | { 99 | "timeout": 30000, 100 | "annotations": [], 101 | "expectedStatus": "passed", 102 | "projectId": "firefox", 103 | "projectName": "firefox", 104 | "results": [], 105 | "status": "skipped" 106 | } 107 | ], 108 | "id": "dd9b2edffe9b7501040c-aae5ec8d059565ec3dd6", 109 | "file": "example.spec.js", 110 | "line": 37, 111 | "column": 5 112 | }, 113 | { 114 | "title": "outside test", 115 | "ok": true, 116 | "tags": ["smoke", "sanity"], 117 | "tests": [ 118 | { 119 | "timeout": 30000, 120 | "annotations": [], 121 | "expectedStatus": "passed", 122 | "projectId": "webkit", 123 | "projectName": "webkit", 124 | "results": [], 125 | "status": "skipped" 126 | } 127 | ], 128 | "id": "dd9b2edffe9b7501040c-80b105f8db79074e5598", 129 | "file": "example.spec.js", 130 | "line": 37, 131 | "column": 5 132 | } 133 | ], 134 | "suites": [ 135 | { 136 | "title": "All tests", 137 | "file": "example.spec.js", 138 | "line": 4, 139 | "column": 6, 140 | "specs": [ 141 | { 142 | "title": "has title", 143 | "ok": true, 144 | "tags": ["play", "sanity"], 145 | "tests": [ 146 | { 147 | "timeout": 30000, 148 | "annotations": [], 149 | "expectedStatus": "passed", 150 | "projectId": "chromium", 151 | "projectName": "chromium", 152 | "results": [], 153 | "status": "skipped" 154 | } 155 | ], 156 | "id": "dd9b2edffe9b7501040c-0cb7170db15f6992d526", 157 | "file": "example.spec.js", 158 | "line": 5, 159 | "column": 7 160 | }, 161 | { 162 | "title": "get started link", 163 | "ok": true, 164 | "tags": ["smoke", "sanity"], 165 | "tests": [ 166 | { 167 | "timeout": 30000, 168 | "annotations": [], 169 | "expectedStatus": "passed", 170 | "projectId": "chromium", 171 | "projectName": "chromium", 172 | "results": [], 173 | "status": "skipped" 174 | } 175 | ], 176 | "id": "dd9b2edffe9b7501040c-498e32afb51f55a65e0c", 177 | "file": "example.spec.js", 178 | "line": 12, 179 | "column": 7 180 | }, 181 | { 182 | "title": "has title", 183 | "ok": true, 184 | "tags": ["play", "sanity"], 185 | "tests": [ 186 | { 187 | "timeout": 30000, 188 | "annotations": [], 189 | "expectedStatus": "passed", 190 | "projectId": "firefox", 191 | "projectName": "firefox", 192 | "results": [], 193 | "status": "skipped" 194 | } 195 | ], 196 | "id": "dd9b2edffe9b7501040c-115d5c33362efdc980e4", 197 | "file": "example.spec.js", 198 | "line": 5, 199 | "column": 7 200 | }, 201 | { 202 | "title": "get started link", 203 | "ok": true, 204 | "tags": ["smoke", "sanity"], 205 | "tests": [ 206 | { 207 | "timeout": 30000, 208 | "annotations": [], 209 | "expectedStatus": "passed", 210 | "projectId": "firefox", 211 | "projectName": "firefox", 212 | "results": [], 213 | "status": "skipped" 214 | } 215 | ], 216 | "id": "dd9b2edffe9b7501040c-09a0a890b47a59dfd37d", 217 | "file": "example.spec.js", 218 | "line": 12, 219 | "column": 7 220 | }, 221 | { 222 | "title": "has title", 223 | "ok": true, 224 | "tags": ["play", "sanity"], 225 | "tests": [ 226 | { 227 | "timeout": 30000, 228 | "annotations": [], 229 | "expectedStatus": "passed", 230 | "projectId": "webkit", 231 | "projectName": "webkit", 232 | "results": [], 233 | "status": "skipped" 234 | } 235 | ], 236 | "id": "dd9b2edffe9b7501040c-46bbf05781ac06767c73", 237 | "file": "example.spec.js", 238 | "line": 5, 239 | "column": 7 240 | }, 241 | { 242 | "title": "get started link", 243 | "ok": true, 244 | "tags": ["smoke", "sanity"], 245 | "tests": [ 246 | { 247 | "timeout": 30000, 248 | "annotations": [], 249 | "expectedStatus": "passed", 250 | "projectId": "webkit", 251 | "projectName": "webkit", 252 | "results": [], 253 | "status": "skipped" 254 | } 255 | ], 256 | "id": "dd9b2edffe9b7501040c-db55b6dd23c5d03b75ee", 257 | "file": "example.spec.js", 258 | "line": 12, 259 | "column": 7 260 | } 261 | ], 262 | "suites": [ 263 | { 264 | "title": "Nested suite", 265 | "file": "example.spec.js", 266 | "line": 23, 267 | "column": 8, 268 | "specs": [ 269 | { 270 | "title": "nested test", 271 | "ok": true, 272 | "tags": ["nested"], 273 | "tests": [ 274 | { 275 | "timeout": 30000, 276 | "annotations": [], 277 | "expectedStatus": "passed", 278 | "projectId": "chromium", 279 | "projectName": "chromium", 280 | "results": [], 281 | "status": "skipped" 282 | } 283 | ], 284 | "id": "dd9b2edffe9b7501040c-c91aaa999febb2257c98", 285 | "file": "example.spec.js", 286 | "line": 24, 287 | "column": 9 288 | }, 289 | { 290 | "title": "nested test", 291 | "ok": true, 292 | "tags": ["nested"], 293 | "tests": [ 294 | { 295 | "timeout": 30000, 296 | "annotations": [], 297 | "expectedStatus": "passed", 298 | "projectId": "firefox", 299 | "projectName": "firefox", 300 | "results": [], 301 | "status": "skipped" 302 | } 303 | ], 304 | "id": "dd9b2edffe9b7501040c-77a1701e0aa1deecff98", 305 | "file": "example.spec.js", 306 | "line": 24, 307 | "column": 9 308 | }, 309 | { 310 | "title": "nested test", 311 | "ok": true, 312 | "tags": ["nested"], 313 | "tests": [ 314 | { 315 | "timeout": 30000, 316 | "annotations": [], 317 | "expectedStatus": "passed", 318 | "projectId": "webkit", 319 | "projectName": "webkit", 320 | "results": [], 321 | "status": "skipped" 322 | } 323 | ], 324 | "id": "dd9b2edffe9b7501040c-edc383a3dead00fc5ddb", 325 | "file": "example.spec.js", 326 | "line": 24, 327 | "column": 9 328 | } 329 | ] 330 | } 331 | ] 332 | } 333 | ] 334 | } 335 | ], 336 | "errors": [], 337 | "stats": { 338 | "startTime": "2025-02-10T20:01:27.301Z", 339 | "duration": 7.027999999999992, 340 | "expected": 0, 341 | "skipped": 12, 342 | "unexpected": 0, 343 | "flaky": 0 344 | } 345 | } 346 | -------------------------------------------------------------------------------- /jest/data/default.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "configFile": "./playwright-cli-select/playwright.config.js", 4 | "rootDir": "./playwright-cli-select/tests", 5 | "forbidOnly": false, 6 | "fullyParallel": true, 7 | "globalSetup": null, 8 | "globalTeardown": null, 9 | "globalTimeout": 0, 10 | "grep": {}, 11 | "grepInvert": null, 12 | "maxFailures": 0, 13 | "metadata": {}, 14 | "preserveOutput": "always", 15 | "reporter": [["json"]], 16 | "reportSlowTests": { 17 | "max": 5, 18 | "threshold": 15000 19 | }, 20 | "quiet": false, 21 | "projects": [ 22 | { 23 | "outputDir": "./playwright-cli-select/test-results", 24 | "repeatEach": 1, 25 | "retries": 0, 26 | "metadata": {}, 27 | "id": "chromium", 28 | "name": "chromium", 29 | "testDir": "./playwright-cli-select/tests", 30 | "testIgnore": [], 31 | "testMatch": ["**/*.@(spec|test).?(c|m)[jt]s?(x)"], 32 | "timeout": 30000 33 | }, 34 | { 35 | "outputDir": "./playwright-cli-select/test-results", 36 | "repeatEach": 1, 37 | "retries": 0, 38 | "metadata": {}, 39 | "id": "firefox", 40 | "name": "firefox", 41 | "testDir": "./playwright-cli-select/tests", 42 | "testIgnore": [], 43 | "testMatch": ["**/*.@(spec|test).?(c|m)[jt]s?(x)"], 44 | "timeout": 30000 45 | }, 46 | { 47 | "outputDir": "./playwright-cli-select/test-results", 48 | "repeatEach": 1, 49 | "retries": 0, 50 | "metadata": {}, 51 | "id": "webkit", 52 | "name": "webkit", 53 | "testDir": "./playwright-cli-select/tests", 54 | "testIgnore": [], 55 | "testMatch": ["**/*.@(spec|test).?(c|m)[jt]s?(x)"], 56 | "timeout": 30000 57 | } 58 | ], 59 | "shard": null, 60 | "updateSnapshots": "missing", 61 | "updateSourceMethod": "patch", 62 | "version": "1.50.1", 63 | "workers": 4, 64 | "webServer": null 65 | }, 66 | "suites": [ 67 | { 68 | "title": "firstDir/another.spec.js", 69 | "file": "firstDir/another.spec.js", 70 | "column": 0, 71 | "line": 0, 72 | "specs": [], 73 | "suites": [ 74 | { 75 | "title": "New tests @new", 76 | "file": "firstDir/another.spec.js", 77 | "line": 4, 78 | "column": 6, 79 | "specs": [ 80 | { 81 | "title": "has title", 82 | "ok": true, 83 | "tags": ["new", "smoke", "sanity"], 84 | "tests": [ 85 | { 86 | "timeout": 30000, 87 | "annotations": [], 88 | "expectedStatus": "passed", 89 | "projectId": "chromium", 90 | "projectName": "chromium", 91 | "results": [], 92 | "status": "skipped" 93 | } 94 | ], 95 | "id": "3f128aca3994d1ede1d8-d571f207c6b982de2d43", 96 | "file": "firstDir/another.spec.js", 97 | "line": 5, 98 | "column": 7 99 | }, 100 | { 101 | "title": "$get started link", 102 | "ok": true, 103 | "tags": ["new", "smoke", "sanity"], 104 | "tests": [ 105 | { 106 | "timeout": 30000, 107 | "annotations": [], 108 | "expectedStatus": "passed", 109 | "projectId": "chromium", 110 | "projectName": "chromium", 111 | "results": [], 112 | "status": "skipped" 113 | } 114 | ], 115 | "id": "3f128aca3994d1ede1d8-241c85b58b841137c9ce", 116 | "file": "firstDir/another.spec.js", 117 | "line": 12, 118 | "column": 7 119 | }, 120 | { 121 | "title": "has title", 122 | "ok": true, 123 | "tags": ["new", "smoke", "sanity"], 124 | "tests": [ 125 | { 126 | "timeout": 30000, 127 | "annotations": [], 128 | "expectedStatus": "passed", 129 | "projectId": "firefox", 130 | "projectName": "firefox", 131 | "results": [], 132 | "status": "skipped" 133 | } 134 | ], 135 | "id": "3f128aca3994d1ede1d8-fc97689deff86f485ed2", 136 | "file": "firstDir/another.spec.js", 137 | "line": 5, 138 | "column": 7 139 | }, 140 | { 141 | "title": "$get started link", 142 | "ok": true, 143 | "tags": ["new", "smoke", "sanity"], 144 | "tests": [ 145 | { 146 | "timeout": 30000, 147 | "annotations": [], 148 | "expectedStatus": "passed", 149 | "projectId": "firefox", 150 | "projectName": "firefox", 151 | "results": [], 152 | "status": "skipped" 153 | } 154 | ], 155 | "id": "3f128aca3994d1ede1d8-b88a6e8dc89e1142d4f9", 156 | "file": "firstDir/another.spec.js", 157 | "line": 12, 158 | "column": 7 159 | }, 160 | { 161 | "title": "has title", 162 | "ok": true, 163 | "tags": ["new", "smoke", "sanity"], 164 | "tests": [ 165 | { 166 | "timeout": 30000, 167 | "annotations": [], 168 | "expectedStatus": "passed", 169 | "projectId": "webkit", 170 | "projectName": "webkit", 171 | "results": [], 172 | "status": "skipped" 173 | } 174 | ], 175 | "id": "3f128aca3994d1ede1d8-4bde48f10b61950df580", 176 | "file": "firstDir/another.spec.js", 177 | "line": 5, 178 | "column": 7 179 | }, 180 | { 181 | "title": "$get started link", 182 | "ok": true, 183 | "tags": ["new", "smoke", "sanity"], 184 | "tests": [ 185 | { 186 | "timeout": 30000, 187 | "annotations": [], 188 | "expectedStatus": "passed", 189 | "projectId": "webkit", 190 | "projectName": "webkit", 191 | "results": [], 192 | "status": "skipped" 193 | } 194 | ], 195 | "id": "3f128aca3994d1ede1d8-59de3d7195a0348ee115", 196 | "file": "firstDir/another.spec.js", 197 | "line": 12, 198 | "column": 7 199 | } 200 | ], 201 | "suites": [ 202 | { 203 | "title": "Nested suite", 204 | "file": "firstDir/another.spec.js", 205 | "line": 27, 206 | "column": 8, 207 | "specs": [ 208 | { 209 | "title": "nested test", 210 | "ok": true, 211 | "tags": ["new", "nested"], 212 | "tests": [ 213 | { 214 | "timeout": 30000, 215 | "annotations": [], 216 | "expectedStatus": "passed", 217 | "projectId": "chromium", 218 | "projectName": "chromium", 219 | "results": [], 220 | "status": "skipped" 221 | } 222 | ], 223 | "id": "3f128aca3994d1ede1d8-6d4ac1138d87ef9475db", 224 | "file": "firstDir/another.spec.js", 225 | "line": 28, 226 | "column": 9 227 | }, 228 | { 229 | "title": "nested test", 230 | "ok": true, 231 | "tags": ["new", "nested"], 232 | "tests": [ 233 | { 234 | "timeout": 30000, 235 | "annotations": [], 236 | "expectedStatus": "passed", 237 | "projectId": "firefox", 238 | "projectName": "firefox", 239 | "results": [], 240 | "status": "skipped" 241 | } 242 | ], 243 | "id": "3f128aca3994d1ede1d8-de8de360e914817b4b29", 244 | "file": "firstDir/another.spec.js", 245 | "line": 28, 246 | "column": 9 247 | }, 248 | { 249 | "title": "nested test", 250 | "ok": true, 251 | "tags": ["new", "nested"], 252 | "tests": [ 253 | { 254 | "timeout": 30000, 255 | "annotations": [], 256 | "expectedStatus": "passed", 257 | "projectId": "webkit", 258 | "projectName": "webkit", 259 | "results": [], 260 | "status": "skipped" 261 | } 262 | ], 263 | "id": "3f128aca3994d1ede1d8-1bf541a0a0b4aeda22ae", 264 | "file": "firstDir/another.spec.js", 265 | "line": 28, 266 | "column": 9 267 | } 268 | ], 269 | "suites": [ 270 | { 271 | "title": "Deeply nested suite", 272 | "file": "firstDir/another.spec.js", 273 | "line": 39, 274 | "column": 10, 275 | "specs": [ 276 | { 277 | "title": "deeply nested test", 278 | "ok": true, 279 | "tags": ["new", "deeply-nested"], 280 | "tests": [ 281 | { 282 | "timeout": 30000, 283 | "annotations": [], 284 | "expectedStatus": "passed", 285 | "projectId": "chromium", 286 | "projectName": "chromium", 287 | "results": [], 288 | "status": "skipped" 289 | } 290 | ], 291 | "id": "3f128aca3994d1ede1d8-4517e1aa22cf6f307399", 292 | "file": "firstDir/another.spec.js", 293 | "line": 40, 294 | "column": 11 295 | }, 296 | { 297 | "title": "deeply nested test", 298 | "ok": true, 299 | "tags": ["new", "deeply-nested"], 300 | "tests": [ 301 | { 302 | "timeout": 30000, 303 | "annotations": [], 304 | "expectedStatus": "passed", 305 | "projectId": "firefox", 306 | "projectName": "firefox", 307 | "results": [], 308 | "status": "skipped" 309 | } 310 | ], 311 | "id": "3f128aca3994d1ede1d8-761d1b126eb4e450de09", 312 | "file": "firstDir/another.spec.js", 313 | "line": 40, 314 | "column": 11 315 | }, 316 | { 317 | "title": "deeply nested test", 318 | "ok": true, 319 | "tags": ["new", "deeply-nested"], 320 | "tests": [ 321 | { 322 | "timeout": 30000, 323 | "annotations": [], 324 | "expectedStatus": "passed", 325 | "projectId": "webkit", 326 | "projectName": "webkit", 327 | "results": [], 328 | "status": "skipped" 329 | } 330 | ], 331 | "id": "3f128aca3994d1ede1d8-906e3d5ac8a2b9819694", 332 | "file": "firstDir/another.spec.js", 333 | "line": 40, 334 | "column": 11 335 | } 336 | ] 337 | } 338 | ] 339 | } 340 | ] 341 | } 342 | ] 343 | }, 344 | { 345 | "title": "secondDir/example.spec.js", 346 | "file": "secondDir/example.spec.js", 347 | "column": 0, 348 | "line": 0, 349 | "specs": [ 350 | { 351 | "title": "outside test", 352 | "ok": true, 353 | "tags": ["smoke", "sanity"], 354 | "tests": [ 355 | { 356 | "timeout": 30000, 357 | "annotations": [], 358 | "expectedStatus": "passed", 359 | "projectId": "chromium", 360 | "projectName": "chromium", 361 | "results": [], 362 | "status": "skipped" 363 | } 364 | ], 365 | "id": "9702f855ac861a8600fd-f1a7fb1158e2635c53c3", 366 | "file": "secondDir/example.spec.js", 367 | "line": 37, 368 | "column": 5 369 | }, 370 | { 371 | "title": "outside test", 372 | "ok": true, 373 | "tags": ["smoke", "sanity"], 374 | "tests": [ 375 | { 376 | "timeout": 30000, 377 | "annotations": [], 378 | "expectedStatus": "passed", 379 | "projectId": "firefox", 380 | "projectName": "firefox", 381 | "results": [], 382 | "status": "skipped" 383 | } 384 | ], 385 | "id": "9702f855ac861a8600fd-0b888511889a24489371", 386 | "file": "secondDir/example.spec.js", 387 | "line": 37, 388 | "column": 5 389 | }, 390 | { 391 | "title": "outside test", 392 | "ok": true, 393 | "tags": ["smoke", "sanity"], 394 | "tests": [ 395 | { 396 | "timeout": 30000, 397 | "annotations": [], 398 | "expectedStatus": "passed", 399 | "projectId": "webkit", 400 | "projectName": "webkit", 401 | "results": [], 402 | "status": "skipped" 403 | } 404 | ], 405 | "id": "9702f855ac861a8600fd-540684e7e884095e5b25", 406 | "file": "secondDir/example.spec.js", 407 | "line": 37, 408 | "column": 5 409 | } 410 | ], 411 | "suites": [ 412 | { 413 | "title": "All tests", 414 | "file": "secondDir/example.spec.js", 415 | "line": 4, 416 | "column": 6, 417 | "specs": [ 418 | { 419 | "title": "has title", 420 | "ok": true, 421 | "tags": ["play", "sanity"], 422 | "tests": [ 423 | { 424 | "timeout": 30000, 425 | "annotations": [], 426 | "expectedStatus": "passed", 427 | "projectId": "chromium", 428 | "projectName": "chromium", 429 | "results": [], 430 | "status": "skipped" 431 | } 432 | ], 433 | "id": "9702f855ac861a8600fd-22683ab8acd13e93d028", 434 | "file": "secondDir/example.spec.js", 435 | "line": 5, 436 | "column": 7 437 | }, 438 | { 439 | "title": "get started link", 440 | "ok": true, 441 | "tags": ["smoke", "sanity"], 442 | "tests": [ 443 | { 444 | "timeout": 30000, 445 | "annotations": [], 446 | "expectedStatus": "passed", 447 | "projectId": "chromium", 448 | "projectName": "chromium", 449 | "results": [], 450 | "status": "skipped" 451 | } 452 | ], 453 | "id": "9702f855ac861a8600fd-b7d9a57e197e3060153c", 454 | "file": "secondDir/example.spec.js", 455 | "line": 12, 456 | "column": 7 457 | }, 458 | { 459 | "title": "has title", 460 | "ok": true, 461 | "tags": ["play", "sanity"], 462 | "tests": [ 463 | { 464 | "timeout": 30000, 465 | "annotations": [], 466 | "expectedStatus": "passed", 467 | "projectId": "firefox", 468 | "projectName": "firefox", 469 | "results": [], 470 | "status": "skipped" 471 | } 472 | ], 473 | "id": "9702f855ac861a8600fd-d0d1d7d68ec7bf5ab109", 474 | "file": "secondDir/example.spec.js", 475 | "line": 5, 476 | "column": 7 477 | }, 478 | { 479 | "title": "get started link", 480 | "ok": true, 481 | "tags": ["smoke", "sanity"], 482 | "tests": [ 483 | { 484 | "timeout": 30000, 485 | "annotations": [], 486 | "expectedStatus": "passed", 487 | "projectId": "firefox", 488 | "projectName": "firefox", 489 | "results": [], 490 | "status": "skipped" 491 | } 492 | ], 493 | "id": "9702f855ac861a8600fd-2dfce446504ed61f3922", 494 | "file": "secondDir/example.spec.js", 495 | "line": 12, 496 | "column": 7 497 | }, 498 | { 499 | "title": "has title", 500 | "ok": true, 501 | "tags": ["play", "sanity"], 502 | "tests": [ 503 | { 504 | "timeout": 30000, 505 | "annotations": [], 506 | "expectedStatus": "passed", 507 | "projectId": "webkit", 508 | "projectName": "webkit", 509 | "results": [], 510 | "status": "skipped" 511 | } 512 | ], 513 | "id": "9702f855ac861a8600fd-980d86312596de2e039e", 514 | "file": "secondDir/example.spec.js", 515 | "line": 5, 516 | "column": 7 517 | }, 518 | { 519 | "title": "get started link", 520 | "ok": true, 521 | "tags": ["smoke", "sanity"], 522 | "tests": [ 523 | { 524 | "timeout": 30000, 525 | "annotations": [], 526 | "expectedStatus": "passed", 527 | "projectId": "webkit", 528 | "projectName": "webkit", 529 | "results": [], 530 | "status": "skipped" 531 | } 532 | ], 533 | "id": "9702f855ac861a8600fd-d84b7d914c4a138e8e4d", 534 | "file": "secondDir/example.spec.js", 535 | "line": 12, 536 | "column": 7 537 | } 538 | ], 539 | "suites": [ 540 | { 541 | "title": "Nested suite", 542 | "file": "secondDir/example.spec.js", 543 | "line": 23, 544 | "column": 8, 545 | "specs": [ 546 | { 547 | "title": "nested test", 548 | "ok": true, 549 | "tags": ["nested"], 550 | "tests": [ 551 | { 552 | "timeout": 30000, 553 | "annotations": [], 554 | "expectedStatus": "passed", 555 | "projectId": "chromium", 556 | "projectName": "chromium", 557 | "results": [], 558 | "status": "skipped" 559 | } 560 | ], 561 | "id": "9702f855ac861a8600fd-c41523583c44befdc50a", 562 | "file": "secondDir/example.spec.js", 563 | "line": 24, 564 | "column": 9 565 | }, 566 | { 567 | "title": "nested test", 568 | "ok": true, 569 | "tags": ["nested"], 570 | "tests": [ 571 | { 572 | "timeout": 30000, 573 | "annotations": [], 574 | "expectedStatus": "passed", 575 | "projectId": "firefox", 576 | "projectName": "firefox", 577 | "results": [], 578 | "status": "skipped" 579 | } 580 | ], 581 | "id": "9702f855ac861a8600fd-15e2a1b49c2082009d65", 582 | "file": "secondDir/example.spec.js", 583 | "line": 24, 584 | "column": 9 585 | }, 586 | { 587 | "title": "nested test", 588 | "ok": true, 589 | "tags": ["nested"], 590 | "tests": [ 591 | { 592 | "timeout": 30000, 593 | "annotations": [], 594 | "expectedStatus": "passed", 595 | "projectId": "webkit", 596 | "projectName": "webkit", 597 | "results": [], 598 | "status": "skipped" 599 | } 600 | ], 601 | "id": "9702f855ac861a8600fd-43cb03fe02bf51ed21a0", 602 | "file": "secondDir/example.spec.js", 603 | "line": 24, 604 | "column": 9 605 | } 606 | ] 607 | } 608 | ] 609 | } 610 | ] 611 | } 612 | ], 613 | "errors": [], 614 | "stats": { 615 | "startTime": "2025-02-10T17:15:02.808Z", 616 | "duration": 8.59299999999999, 617 | "expected": 0, 618 | "skipped": 24, 619 | "unexpected": 0, 620 | "flaky": 0 621 | } 622 | } 623 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "playwright-cli-select", 3 | "version": "1.0.6", 4 | "description": "Playwright interactive cli prompts to select and run specs, tests or tags", 5 | "main": "index.js", 6 | "bin": { 7 | "playwright-cli-select": "index.js" 8 | }, 9 | "scripts": { 10 | "test": "jest ./jest --verbose" 11 | }, 12 | "publishConfig": { 13 | "registry": "https://registry.npmjs.org/" 14 | }, 15 | "keywords": [ 16 | "cli", 17 | "playwright", 18 | "testing", 19 | "tooling" 20 | ], 21 | "author": "Dennis Bergevin", 22 | "license": "MIT", 23 | "devDependencies": { 24 | "@playwright/test": "^1.50.1", 25 | "@types/node": "^22.13.1", 26 | "cli-testing-library": "^2.0.2", 27 | "jest": "^29.7.0" 28 | }, 29 | "dependencies": { 30 | "fuse.js": "^7.1.0", 31 | "inquirer-select-pro": "^1.0.0-alpha.9", 32 | "yargs": "^17.7.2" 33 | }, 34 | "repository": { 35 | "type": "git", 36 | "url": "https://github.com/dennisbergevin/playwright-cli-select.git" 37 | }, 38 | "bugs": { 39 | "url": "https://github.com/dennisbergevin/playwright-cli-select/issues" 40 | }, 41 | "homepage": "https://github.com/dennisbergevin/playwright-cli-select#readme" 42 | } 43 | -------------------------------------------------------------------------------- /playwright.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import { defineConfig, devices } from "@playwright/test"; 3 | 4 | /** 5 | * Read environment variables from file. 6 | * https://github.com/motdotla/dotenv 7 | */ 8 | // import dotenv from 'dotenv'; 9 | // import path from 'path'; 10 | // dotenv.config({ path: path.resolve(__dirname, '.env') }); 11 | 12 | /** 13 | * @see https://playwright.dev/docs/test-configuration 14 | */ 15 | export default defineConfig({ 16 | testDir: "./tests", 17 | /* Run tests in files in parallel */ 18 | fullyParallel: true, 19 | /* Fail the build on CI if you accidentally left test.only in the source code. */ 20 | forbidOnly: !!process.env.CI, 21 | /* Retry on CI only */ 22 | retries: process.env.CI ? 2 : 0, 23 | /* Opt out of parallel tests on CI. */ 24 | workers: process.env.CI ? 1 : undefined, 25 | /* Reporter to use. See https://playwright.dev/docs/test-reporters */ 26 | reporter: "html", 27 | /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ 28 | use: { 29 | /* Base URL to use in actions like `await page.goto('/')`. */ 30 | // baseURL: 'http://127.0.0.1:3000', 31 | 32 | /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ 33 | trace: "on-first-retry", 34 | }, 35 | 36 | /* Configure projects for major browsers */ 37 | projects: [ 38 | { 39 | name: "chromium", 40 | use: { ...devices["Desktop Chrome"] }, 41 | }, 42 | 43 | { 44 | name: "firefox", 45 | use: { ...devices["Desktop Firefox"] }, 46 | }, 47 | 48 | { 49 | name: "webkit", 50 | use: { ...devices["Desktop Safari"] }, 51 | }, 52 | 53 | /* Test against mobile viewports. */ 54 | // { 55 | // name: 'Mobile Chrome', 56 | // use: { ...devices['Pixel 5'] }, 57 | // }, 58 | // { 59 | // name: 'Mobile Safari', 60 | // use: { ...devices['iPhone 12'] }, 61 | // }, 62 | 63 | /* Test against branded browsers. */ 64 | // { 65 | // name: 'Microsoft Edge', 66 | // use: { ...devices['Desktop Edge'], channel: 'msedge' }, 67 | // }, 68 | // { 69 | // name: 'Google Chrome', 70 | // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, 71 | // }, 72 | ], 73 | 74 | /* Run your local dev server before starting the tests */ 75 | // webServer: { 76 | // command: 'npm run start', 77 | // url: 'http://127.0.0.1:3000', 78 | // reuseExistingServer: !process.env.CI, 79 | // }, 80 | }); 81 | -------------------------------------------------------------------------------- /playwright.dev.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import { defineConfig, devices } from "@playwright/test"; 3 | 4 | /** 5 | * Read environment variables from file. 6 | * https://github.com/motdotla/dotenv 7 | */ 8 | // import dotenv from 'dotenv'; 9 | // import path from 'path'; 10 | // dotenv.config({ path: path.resolve(__dirname, '.env') }); 11 | 12 | /** 13 | * @see https://playwright.dev/docs/test-configuration 14 | */ 15 | export default defineConfig({ 16 | testDir: "./tests/secondDir/", 17 | /* Run tests in files in parallel */ 18 | fullyParallel: true, 19 | /* Fail the build on CI if you accidentally left test.only in the source code. */ 20 | forbidOnly: !!process.env.CI, 21 | /* Retry on CI only */ 22 | retries: process.env.CI ? 2 : 0, 23 | /* Opt out of parallel tests on CI. */ 24 | workers: process.env.CI ? 1 : undefined, 25 | /* Reporter to use. See https://playwright.dev/docs/test-reporters */ 26 | reporter: "list", 27 | /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ 28 | use: { 29 | /* Base URL to use in actions like `await page.goto('/')`. */ 30 | // baseURL: 'http://127.0.0.1:3000', 31 | 32 | /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ 33 | trace: "on-first-retry", 34 | }, 35 | 36 | /* Configure projects for major browsers */ 37 | projects: [ 38 | { 39 | name: "chromium", 40 | use: { ...devices["Desktop Chrome"] }, 41 | }, 42 | 43 | { 44 | name: "firefox", 45 | use: { ...devices["Desktop Firefox"] }, 46 | }, 47 | 48 | { 49 | name: "webkit", 50 | use: { ...devices["Desktop Safari"] }, 51 | }, 52 | 53 | /* Test against mobile viewports. */ 54 | // { 55 | // name: 'Mobile Chrome', 56 | // use: { ...devices['Pixel 5'] }, 57 | // }, 58 | // { 59 | // name: 'Mobile Safari', 60 | // use: { ...devices['iPhone 12'] }, 61 | // }, 62 | 63 | /* Test against branded browsers. */ 64 | // { 65 | // name: 'Microsoft Edge', 66 | // use: { ...devices['Desktop Edge'], channel: 'msedge' }, 67 | // }, 68 | // { 69 | // name: 'Google Chrome', 70 | // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, 71 | // }, 72 | ], 73 | 74 | /* Run your local dev server before starting the tests */ 75 | // webServer: { 76 | // command: 'npm run start', 77 | // url: 'http://127.0.0.1:3000', 78 | // reuseExistingServer: !process.env.CI, 79 | // }, 80 | }); 81 | -------------------------------------------------------------------------------- /tapes/run-flags.tape: -------------------------------------------------------------------------------- 1 | 2 | # VHS documentation 3 | # 4 | # Output: 5 | # Output