File size: 1,737 Bytes
06671aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import fs from "fs";
import { spawnSync } from "child_process";
import path from "path";

const testDir = path.resolve(process.argv[2] || "tests/integration");
let files = [];

if (fs.existsSync(testDir)) {
  files = fs
    .readdirSync(testDir)
    .filter((f) => f.endsWith(".test.ts"))
    .map((f) => path.join(testDir, f))
    .sort();
}

if (files.length === 0) {
  console.error("Error: Zero integration test files discovered.");
  process.exit(1);
}

const results = [];
let anyFailed = false;

for (const file of files) {
  const displayFile = path.relative(process.cwd(), file) || file;
  console.log(`\n=== Running ${displayFile} ===`);

  const childEnv = { ...process.env };
  delete childEnv.NODE_TEST_CONTEXT;

  const child = spawnSync(
    process.execPath,
    ["--import", "tsx", "--test", file],
    {
      stdio: "inherit",
      env: childEnv,
    },
  );

  const exitCode = child.status ?? 1;
  results.push({ file: displayFile, exitCode });

  if (child.error) {
    console.error(`Failed to launch ${displayFile}: ${child.error.message}`);
  }
  if (exitCode !== 0) {
    anyFailed = true;
  }
}

console.log("\n=== Integration Tests Summary ===");
let passed = 0;
let failed = 0;
for (const res of results) {
  if (res.exitCode === 0) {
    console.log(`PASS: ${res.file}`);
    passed++;
  } else {
    console.log(`FAIL: ${res.file} (exit code ${res.exitCode})`);
    failed++;
  }
}

console.log(
  `\nDiscovered: ${files.length}, Executed: ${results.length}, Passed: ${passed}, Failed: ${failed}`,
);

if (files.length !== results.length) {
  console.error(
    "Fatal: Number of executed tests does not match number of discovered tests!",
  );
  process.exit(1);
}

if (anyFailed) {
  process.exit(1);
}