// @effect-diagnostics nodeBuiltinImport:off - Vite loads this while reading test configs. import * as NodeFS from "node:fs"; import * as NodePath from "node:path"; const REPO_ROOT = NodePath.resolve(import.meta.dirname, "../.."); const TEST_FILE = /\.(test|spec)\.[cm]?[jt]sx?$/; /** * Repo-relative paths of the test files a `vitest run` command line names, or undefined * unless every filter is an existing test file. Configs use it to set up only the * projects that own those files; undefined keeps every project. */ export async function cliTestFiles(argv = process.argv, cwd = process.cwd()) { const vitest = argv.findIndex((arg) => /[\\/]vitest(\.mjs)?$/.test(arg)); if (vitest === -1 || argv[vitest + 1] !== "run") return undefined; // Vitest's own parser, loaded only for test runs so dev servers and builds skip it. const { parseCLI } = await import("vite-plus/test/node"); const { filter, options } = parseCLI(["vitest", ...argv.slice(vitest + 1)]); if (options.root !== undefined || filter.length === 0) return undefined; const files: string[] = []; for (const arg of filter) { const file = NodePath.resolve(cwd, arg.replace(/:\d+$/, "")); if (!TEST_FILE.test(file) || !NodeFS.statSync(file, { throwIfNoEntry: false })?.isFile()) { return undefined; } files.push(NodePath.relative(REPO_ROOT, file).replaceAll("\\", "/")); } return files; }