run-tests.mjs 903 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env node
  2. import { spawnSync } from "node:child_process";
  3. import { readdirSync } from "node:fs";
  4. import { dirname, join, resolve } from "node:path";
  5. import { fileURLToPath } from "node:url";
  6. const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
  7. function collectTests(directory) {
  8. const result = [];
  9. for (const entry of readdirSync(directory, { withFileTypes: true })) {
  10. if (entry.name === "node_modules") continue;
  11. const fullPath = join(directory, entry.name);
  12. if (entry.isDirectory()) result.push(...collectTests(fullPath));
  13. else if (entry.isFile() && entry.name.endsWith(".test.mjs")) result.push(fullPath);
  14. }
  15. return result;
  16. }
  17. const tests = collectTests(root);
  18. const child = spawnSync(process.execPath, ["--test", ...tests], {
  19. cwd: root,
  20. stdio: "inherit",
  21. encoding: "utf8",
  22. maxBuffer: 1024 * 1024 * 100,
  23. });
  24. process.exit(child.status ?? 1);