Skip to content

Commit

Permalink
fix(vite): normalize vitest cli args in executor (#21870)
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Feb 19, 2024
1 parent 31348e2 commit 077debe
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion packages/vite/src/executors/test/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ export async function getOptions(
? process.cwd()
: relative(context.cwd, joinPathFragments(context.root, projectRoot));

const normalizedExtraArgs = normalizeArgs(extraArgs);

const settings = {
...extraArgs,
...normalizedExtraArgs,
// This should not be needed as it's going to be set in vite.config.ts
// but leaving it here in case someone did not migrate correctly
root: resolved.config.root ?? root,
Expand All @@ -81,3 +83,31 @@ export async function getExtraArgs(

return extraArgs;
}

// normalizes some args that were previously normalized by `startVitest` until this is fixed
// https://github.com/vitest-dev/vitest/pull/5126/files#diff-49ef635be88fe607c8682e81ab56b061ba9aafd5c94a5690a70b90a54604cd24L40-L62
function normalizeArgs(extraArgs: Record<string, any>) {
const args = { ...extraArgs };

if (typeof args.coverage === 'boolean') {
args.coverage = { enabled: args.coverage };
}
// running "vitest --browser", assumes browser name is set in the config
if (typeof args.browser === 'boolean') {
args.browser = { enabled: args.browser } as any;
}
// running "vitest --browser=chrome"
if (typeof args.browser === 'string') {
args.browser = { enabled: true, name: args.browser };
}
if (typeof args.typecheck === 'boolean') {
args.typecheck = { enabled: true };
}
if (typeof args.typecheck?.only === 'boolean') {
args.typecheck ??= {};
args.typecheck.only = true;
args.typecheck.enabled = true;
}

return args;
}

0 comments on commit 077debe

Please sign in to comment.