run-vitest-suite.mjs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { spawnSync } from "node:child_process";
  2. import { createRequire } from "node:module";
  3. import { realpathSync } from "node:fs";
  4. import { tmpdir } from "node:os";
  5. import path from "node:path";
  6. import { suiteFiles, repositoryRoot } from "./lib/vitest-suites.mjs";
  7. const require = createRequire(import.meta.url);
  8. const name = process.argv[2];
  9. if (!name) throw new Error("Usage: node scripts/run-vitest-suite.mjs <suite>");
  10. const files = suiteFiles(repositoryRoot, name);
  11. const manifestPath = require.resolve("vitest/package.json");
  12. const cli = path.resolve(path.dirname(manifestPath), require(manifestPath).bin.vitest);
  13. // Windows runners expose TEMP through an 8.3 alias (RUNNER~1). Native
  14. // fs.watch can abort inside libuv when events use the corresponding long path:
  15. // https://github.com/libuv/libuv/issues/5010. Keep real filesystem watching in
  16. // the tests, but create their temporary fixtures beneath the canonical path.
  17. const environment = { ...process.env };
  18. if (process.platform === "win32") {
  19. environment.TEMP = environment.TMP = realpathSync.native(tmpdir());
  20. }
  21. const result = spawnSync(
  22. process.execPath,
  23. [
  24. cli,
  25. "run",
  26. "--config",
  27. "vitest.oss.config.mjs",
  28. // These suites create many SQLite databases and watched directories. On
  29. // Windows, concurrent files can exhaust the 5s test budget through I/O
  30. // contention. Serialize files without relaxing individual test deadlines.
  31. ...(process.platform === "win32" ? ["--maxWorkers", "1"] : []),
  32. ...files,
  33. ],
  34. { stdio: "inherit", cwd: repositoryRoot, env: environment },
  35. );
  36. if (result.error) throw result.error;
  37. process.exitCode = result.status ?? 1;