Skip to content

Commit 5503d59

Browse files
committed
chore: allow exact in cli
1 parent 4c9adb5 commit 5503d59

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

docs/guide/cli-generated.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ Control if Vitest catches uncaught exceptions so they can be reported (default:
429429

430430
Enable trace view mode. Supported: "on", "off", "on-first-retry", "on-all-retries", "retain-on-failure".
431431

432+
### browser.locators.exact
433+
434+
- **CLI:** `--browser.locators.exact`
435+
- **Config:** [browser.locators.exact](/config/browser/locators#locators-exact)
436+
437+
Should locators match the text exactly by default (default: `false`)
438+
432439
### pool
433440

434441
- **CLI:** `--pool <pool>`

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,22 @@ export const cliOptionsConfig: VitestCLIOptions = {
418418
viewport: null,
419419
screenshotDirectory: null,
420420
screenshotFailures: null,
421-
locators: null,
421+
locators: {
422+
description: 'Options for how locators should be handled by default',
423+
argument: '<options>',
424+
subcommands: {
425+
testIdAttribute: null,
426+
exact: {
427+
description: 'Should locators match the text exactly by default (default: `false`)',
428+
},
429+
},
430+
transform(val) {
431+
if (typeof val !== 'object' || val == null) {
432+
return {}
433+
}
434+
return val
435+
},
436+
},
422437
testerHtmlPath: null,
423438
instances: null,
424439
expect: null,

test/core/test/cli-test.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ test('browser.detailsPanelPosition is parsed correctly', () => {
289289
})
290290
})
291291

292+
test('browser.locators are passed correctly', () => {
293+
expect(getCLIOptions('--browser.locators')).toEqual({
294+
browser: { locators: {} },
295+
})
296+
expect(getCLIOptions('--browser.locators.exact')).toEqual({
297+
browser: { locators: { exact: true } },
298+
})
299+
})
300+
292301
test('clearScreen', async (ctx) => {
293302
// skip vm since rolldown native modules break due to RegExp instance
294303
// https://github.com/vitest-dev/vitest/issues/8754#issuecomment-3727583957

0 commit comments

Comments
 (0)