aboutsummaryrefslogtreecommitdiff
path: root/scripts/run-bun-tests-bounded.js
blob: f3e5a03b78f73e0a8aa858ec025905ebdf0bbeb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bun
import { readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const root = join(dirname(fileURLToPath(import.meta.url)), "..");
const testFile = join(root, "tests/coreutils.test.js");
const source = await readFile(testFile, "utf8");
const names = [...source.matchAll(/^test\("((?:[^"\\]|\\.)+)"/gm)].map((match) => JSON.parse(`"${match[1]}"`));
if (names.length === 0) {
  console.error("run-bun-tests-bounded: no tests found");
  process.exit(2);
}

const failures = [];
for (let index = 0; index < names.length; index++) {
  const name = names[index];
  console.log(`\nBOUNDED TEST ${index + 1}/${names.length}: ${name}`);
  const exactPattern = `^${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`;
  const proc = Bun.spawn([
    process.execPath,
    join(root, "scripts/run-memory-bounded.js"),
    "--rss-limit", process.env.BNU_TEST_RSS_LIMIT ?? "1GiB",
    "--memory-limit", process.env.BNU_TEST_MEMORY_LIMIT ?? "3GiB",
    "--",
    process.execPath,
    "test",
    testFile,
    "--test-name-pattern", exactPattern,
    "--timeout", process.env.BNU_TEST_TIMEOUT ?? "300000",
    "--max-concurrency", "1",
  ], {
    cwd: root,
    env: { ...process.env, BNU_FACTOR_WORKERS: process.env.BNU_FACTOR_WORKERS ?? "1" },
    stdin: "ignore",
    stdout: "inherit",
    stderr: "inherit",
  });
  const code = await proc.exited;
  if (code !== 0) failures.push({ name, code });
}

if (failures.length) {
  console.error(`\n${failures.length} bounded test process(es) failed:`);
  for (const failure of failures) console.error(`- ${failure.name} (exit ${failure.code})`);
  process.exit(1);
}
console.log(`\nAll ${names.length} bounded test processes passed.`);