feat(test): expose runner process.argv as FullConfig.argv#40850
Merged
Conversation
Allow users to pass arbitrary command-line arguments to their tests by
placing them after the `--` separator:
npx playwright test -- --build-path=/foo --env=staging
Anything after `--` is captured verbatim into `FullConfig.cliArgs` and is
available in tests via `testInfo.config.cliArgs`, in `globalSetup` via the
`config` argument, and in reporters via `onBegin(config)`. Playwright does
not parse these; consumers can use any argument-parsing library.
Args before `--` continue to be parsed by commander as before, so unknown
built-in flags still produce a "unknown option" error.
Fixes microsoft#10337
- Drop unnecessary `[...cliArgs]` defensive copy and `if (cliArgs.length)` guard in testActions.ts — `FullConfigInternal` already defaults to `[]`. - Trim redundant comments from cliArgs.ts and program.ts; drop underscore prefix from file-local `dashDashIndex` const. - Fold the "built-in flags before --" test into the basic capture test — one fewer child-process spawn, same coverage.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Address PR feedback from @pavelfeldman: - Rename `cliArgs` -> `processArgv` to avoid clash with the recently-removed `cliArgs` field that meant something different. - Stop slicing argv around the `--` separator and stop swapping commander's parse input. Instead, snapshot the runner's `process.argv` verbatim and expose it as `FullConfig.processArgv`. Consumers parse it however they like — Playwright doesn't pretend to do half the work. - Revert all cli.js entry points to `program.parse(process.argv)` and drop the `argvForCommander` helper module.
- Capture user-supplied args after `--` at module load and strip them (and the `--` itself) from process.argv before commander parses, so they cannot be mistaken for test-filter regexes. cli.js entry points stay as `program.parse(process.argv)` — no second symbol to thread. - Rename `processArgv` -> `argv` on FullConfig per review.
Drop the argv.ts side-effect helper and the process.argv mutation. Instead, extract the post-`--` slice in the `test` command's action handler — the runner process itself, where commander's parsed `args` already includes those items appended to the variadic [test-filter...]. We pull them off the end and pass them to runTests as a separate parameter.
`args.slice(0, args.length - 0)` is identical to `args.slice(0, args.length)`, so the `argv.length ?` branch was dead. Simpler without it.
Per discussion: stop slicing post-`--` args and pass the runner's full process.argv through to FullConfig.argv. Consumers slice and parse it themselves. The action handler still trims post-`--` args off the variadic [test-filter...] so they don't poison test discovery, but no longer threads them through runTests as a separate parameter.
-- as FullConfig.cliArgs
Contributor
Test results for "MCP"7086 passed, 1104 skipped Merge workflow run. |
Contributor
Test results for "tests 1"6 flaky41893 passed, 850 skipped Merge workflow run. |
pavelfeldman
approved these changes
May 15, 2026
This was referenced May 18, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
process.argvand surface it asFullConfig.argv. Visible in tests viatestInfo.config.argv, inglobalSetup(config), and in reporteronBegin(config).--from the variadic[test-filter...]so they aren't interpreted as filter regexes — default test discovery still works.Fixes #10337