Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): handle run mode correctly (fix #719) #717

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vitest/src/constants.ts
Expand Up @@ -49,6 +49,7 @@ export const configDefaults: UserConfig = Object.freeze({
isolate: true,
watchIgnore: [/\/node_modules\//, /\/dist\//],
update: false,
run: !!process.env.CI,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix should be make watch default to false and handles it in CLI, /cc @sheremet-va

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed

watch: !process.env.CI,
reporters: ['default'],
silent: false,
Expand Down
14 changes: 5 additions & 9 deletions packages/vitest/src/node/cli.ts
Expand Up @@ -35,34 +35,30 @@ cli

cli
.command('run [...filters]')
.action(run)
.action((cliFilters: string[], argv: UserConfig) => run(cliFilters, { ...argv, run: true, watch: false }))

cli
.command('related [...filters]')
.action(runRelated)

cli
.command('watch [...filters]')
.action(dev)
.action(run)

cli
.command('dev [...filters]')
.action(dev)
.action(run)

cli
.command('[...filters]')
.action(dev)
.action(run)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the original naming? I found them a bit confusing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't really need the dev function anymore I now inlined the option overrides of vitest run.


cli.parse()

async function runRelated(relatedFiles: string[] | string, argv: UserConfig) {
argv.related = relatedFiles
argv.passWithNoTests ??= true
await dev([], argv)
}

async function dev(cliFilters: string[], argv: UserConfig) {
await run(cliFilters, argv)
await run([], argv)
}

async function run(cliFilters: string[], options: UserConfig) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/index.ts
Expand Up @@ -57,7 +57,7 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest())
options,
)
options.api = resolveApiConfig(options)
options.watch = options.watch && !options.run
options.watch &&= !options.run

process.env.BASE_URL ??= viteConfig.base
process.env.MODE ??= viteConfig.mode
Expand Down