Skip to content

Commit

Permalink
feat: add --project option to limit what projects are running
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Nov 21, 2023
1 parent d1e1bc9 commit 0540e2d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Run only [benchmark](https://vitest.dev/guide/features.html#benchmarking-experim
| `--typecheck [options]` | Custom options for typecheck pool. If passed without options, enables typechecking |
| `--typecheck.enabled` | Enable typechecking alongside tests (default: `false`) |
| `--typecheck.only` | Run only typecheck tests. This automatically enables typecheck (default: `false`) |
| `--project` | 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` |
| `-h, --help` | Display available CLI options |

::: tip
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ cli
.option('--typecheck [options]', 'Custom options for typecheck pool')
.option('--typecheck.enabled', 'Enable typechecking alongside tests (default: false)')
.option('--typecheck.only', 'Run only typecheck tests. This automatically enables typecheck (default: false)')
.option('--project', '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')
.help()

cli
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export class Vitest {
await Promise.all(this._onSetServer.map(fn => fn()))

this.projects = await this.resolveWorkspace(cliOptions)
const filteredProjects = toArray(resolved.project)
if (filteredProjects.length)
this.projects = this.projects.filter(p => filteredProjects.includes(p.getName()))
if (!this.coreWorkspaceProject)
this.coreWorkspaceProject = WorkspaceProject.createBasicProject(this)

Expand Down
5 changes: 5 additions & 0 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,11 @@ export interface UserConfig extends InlineConfig {
* @example --shard=2/3
*/
shard?: string

/**
* Name of the project or projects to run.
*/
project?: string | string[]
}

export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'filters' | 'browser' | 'coverage' | 'testNamePattern' | 'related' | 'api' | 'reporters' | 'resolveSnapshotPath' | 'benchmark' | 'shard' | 'cache' | 'sequence' | 'typecheck' | 'runner' | 'poolOptions' | 'pool'> {
Expand Down

0 comments on commit 0540e2d

Please sign in to comment.