diff --git a/scripts/run-vitest.mjs b/scripts/run-vitest.mjs index c3a8a795bc1..dc52fc61633 100644 --- a/scripts/run-vitest.mjs +++ b/scripts/run-vitest.mjs @@ -1,6 +1,9 @@ +import { createRequire } from "node:module"; +import path from "node:path"; import { spawnPnpmRunner } from "./pnpm-runner.mjs"; const TRUTHY_ENV_VALUES = new Set(["1", "true", "yes", "on"]); +const require = createRequire(import.meta.url); function isTruthyEnvValue(value) { return TRUTHY_ENV_VALUES.has(value?.trim().toLowerCase() ?? ""); @@ -14,6 +17,11 @@ export function resolveVitestNodeArgs(env = process.env) { return ["--no-maglev"]; } +export function resolveVitestCliEntry() { + const vitestPackageJson = require.resolve("vitest/package.json"); + return path.join(path.dirname(vitestPackageJson), "vitest.mjs"); +} + function main(argv = process.argv.slice(2), env = process.env) { if (argv.length === 0) { console.error("usage: node scripts/run-vitest.mjs "); @@ -21,8 +29,7 @@ function main(argv = process.argv.slice(2), env = process.env) { } const child = spawnPnpmRunner({ - pnpmArgs: ["exec", "vitest", ...argv], - nodeArgs: resolveVitestNodeArgs(env), + pnpmArgs: ["exec", "node", ...resolveVitestNodeArgs(env), resolveVitestCliEntry(), ...argv], env, });