Skip to content

Commit 1adddde

Browse files
authored
feat(cli): support -p shorthand for --project (#10826)
1 parent b7be731 commit 1adddde

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

docs/guide/cli-generated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ Minimum time in milliseconds it takes to spawn the typechecker
794794

795795
### project
796796

797-
- **CLI:** `--project <name>`
797+
- **CLI:** `-p, --project <name>`
798798

799799
The name of the project to run if you are using Vitest workspace feature. This can be repeated for multiple projects: `--project=1 --project=2`. You can also filter projects using wildcards like `--project=packages*`, and exclude projects with `--project=!pattern`.
800800

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
743743
},
744744
},
745745
project: {
746+
shorthand: 'p',
746747
description:
747748
'The name of the project to run if you are using Vitest workspace feature. This can be repeated for multiple projects: `--project=1 --project=2`. You can also filter projects using wildcards like `--project=packages*`, and exclude projects with `--project=!pattern`.',
748749
argument: '<name>',

test/unit/test/cli-test.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ test('maxConcurrency is parsed correctly', () => {
215215
expect(getCLIOptions('--max-concurrency=1000')).toEqual({ maxConcurrency: 1000 })
216216
})
217217

218+
test('project is parsed correctly', () => {
219+
// cac copies the raw value to the shorthand key, it is ignored by vitest
220+
expect(getCLIOptions('--project space_1')).toEqual({ project: ['space_1'], p: 'space_1' })
221+
expect(getCLIOptions('--project=space_1')).toEqual({ project: ['space_1'], p: 'space_1' })
222+
expect(getCLIOptions('-p space_1')).toEqual({ project: ['space_1'], p: 'space_1' })
223+
expect(getCLIOptions('-p=space_1')).toEqual({ project: ['space_1'], p: 'space_1' })
224+
expect(getCLIOptions('-p space_1 -p space_2')).toEqual({
225+
project: ['space_1', 'space_2'],
226+
p: ['space_1', 'space_2'],
227+
})
228+
})
229+
218230
test('injectCjsGlobals is parsed correctly', () => {
219231
expect(getCLIOptions('--injectCjsGlobals')).toEqual({ injectCjsGlobals: true })
220232
expect(getCLIOptions('--inject-cjs-globals')).toEqual({ injectCjsGlobals: true })
@@ -446,6 +458,17 @@ test('public parseCLI works correctly', () => {
446458
filter: [],
447459
options: {
448460
'project': ['space_1', 'space_2'],
461+
'p': ['space_1', 'space_2'],
462+
'--': [],
463+
'color': true,
464+
},
465+
})
466+
467+
expect(parseCLI('vitest -p space_1 -p space_2')).toEqual({
468+
filter: [],
469+
options: {
470+
'project': ['space_1', 'space_2'],
471+
'p': ['space_1', 'space_2'],
449472
'--': [],
450473
'color': true,
451474
},
@@ -455,6 +478,7 @@ test('public parseCLI works correctly', () => {
455478
filter: [],
456479
options: {
457480
'project': ['space 1'],
481+
'p': '"space 1"',
458482
'--': [],
459483
'color': true,
460484
},
@@ -464,6 +488,7 @@ test('public parseCLI works correctly', () => {
464488
filter: [],
465489
options: {
466490
'project': ['space 1'],
491+
'p': 'space 1',
467492
'--': [],
468493
'color': true,
469494
},
@@ -473,6 +498,7 @@ test('public parseCLI works correctly', () => {
473498
filter: [],
474499
options: {
475500
'project': ['space 1'],
501+
'p': 'space 1',
476502
'--': [],
477503
'color': true,
478504
},
@@ -482,6 +508,7 @@ test('public parseCLI works correctly', () => {
482508
filter: [],
483509
options: {
484510
'project': ['space 1', 'space 2'],
511+
'p': ['"space 1"', '"space 2"'],
485512
'--': [],
486513
'color': true,
487514
},
@@ -491,6 +518,7 @@ test('public parseCLI works correctly', () => {
491518
filter: ['./test-1.js', './test-2.js'],
492519
options: {
493520
'project': ['space 1', 'space 2', 'space 3'],
521+
'p': ['"space 1"', '"space 2"', '"space 3"'],
494522
'--': [],
495523
'color': true,
496524
},

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo