Skip to content

feat(test): expose runner process.argv as FullConfig.argv#40850

Merged
yury-s merged 7 commits into
microsoft:mainfrom
yury-s:fix-10337
May 15, 2026
Merged

feat(test): expose runner process.argv as FullConfig.argv#40850
yury-s merged 7 commits into
microsoft:mainfrom
yury-s:fix-10337

Conversation

@yury-s

@yury-s yury-s commented May 14, 2026

Copy link
Copy Markdown
Member

Summary

  • Snapshot the runner process's process.argv and surface it as FullConfig.argv. Visible in tests via testInfo.config.argv, in globalSetup(config), and in reporter onBegin(config).
  • The test command also strips items supplied after -- from the variadic [test-filter...] so they aren't interpreted as filter regexes — default test discovery still works.
  • Playwright does not parse the args; consumers slice/parse them themselves with any argument-parsing library.
npx playwright test -- --build-path=./out --env=staging
# in your test / globalSetup / reporter:
config.argv  // includes ['', '--', '--build-path=./out', '--env=staging']

Fixes #10337

yury-s added 2 commits May 14, 2026 15:23
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.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread packages/playwright-ct-react/cli.js Outdated
Comment thread packages/playwright/src/common/config.ts Outdated
Comment thread tests/playwright-test/config.spec.ts Outdated
yury-s added 5 commits May 14, 2026 17:45
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.
@yury-s yury-s changed the title feat(test): expose custom CLI args after -- as FullConfig.cliArgs feat(test): expose runner process.argv as FullConfig.argv May 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

7086 passed, 1104 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

6 flaky ⚠️ [chromium-library] › library/video.spec.ts:682 › screencast › should capture full viewport on hidpi `@ubuntu-22.04-chromium-tip-of-tree`
⚠️ [chromium-library] › library/popup.spec.ts:261 › should not throw when click closes popup `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:719 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-page] › page/page-request-continue.spec.ts:756 › propagate headers cross origin redirect after interception `@chromium-ubuntu-22.04-node20`
⚠️ [chromium-library] › library/chromium/connect-to-worker.spec.ts:19 › should connect, evaluate, receive console and disconnect `@chromium-ubuntu-22.04-node22`
⚠️ [firefox-page] › page/page-emulate-media.spec.ts:144 › should keep reduced motion and color emulation after reload `@firefox-ubuntu-22.04-node20`

41893 passed, 850 skipped


Merge workflow run.

@yury-s yury-s requested a review from pavelfeldman May 15, 2026 15:26
@yury-s yury-s merged commit 5422254 into microsoft:main May 15, 2026
45 checks passed
@yury-s yury-s deleted the fix-10337 branch May 15, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Allow custom command-line arguments in @playwright/test

2 participants