Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
84 lines (80 loc) · 3.96 KB
/
Copy pathvitest.config.ts
File metadata and controls
84 lines (80 loc) · 3.96 KB
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
79
80
81
82
83
84
import { chmodSync, mkdirSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { defineConfig } from "vitest/config";
// Compiled-binary + oracle caches for the test lanes (see cc.ts's cache block
// and tests/harness/README.md). Workers inherit SCRIPTC_CACHE_DIR from here;
// SCRIPTC_NO_CACHE=1 in the caller's environment bypasses every cache in both
// directions (no reads, no writes). Production builds use the platform cache;
// this explicit override keeps test artifacts repo-local and disposable.
const configuredCacheDir = process.env["SCRIPTC_CACHE_DIR"];
const cacheDir =
configuredCacheDir ??
fileURLToPath(new URL("./node_modules/.cache/scriptc-tests/cas", import.meta.url));
const testTmpDir =
process.env["TMPDIR"] ??
join(process.env["XDG_CACHE_HOME"] ?? join(homedir(), ".cache"), "scriptc", "test-tmp");
// The production cache refuses an existing explicit override that is visible
// to other users. This repository owns the default test-only override, so
// create (or repair) it before any oracle subdirectory can implicitly create
// the root with the process umask (normally 0755). Otherwise native caching is
// silently disabled and every corpus case recompiles the complete C runtime.
if (configuredCacheDir === undefined && process.env["SCRIPTC_NO_CACHE"] !== "1") {
mkdirSync(cacheDir, { recursive: true, mode: 0o700 });
if (process.platform !== "win32") chmodSync(cacheDir, 0o700);
}
if (process.platform !== "win32") mkdirSync(testTmpDir, { recursive: true });
// Native differential tests are memory-heavy, so two workers is the safe host
// default. CI and larger machines can override it explicitly.
const configuredWorkers = process.env["SCRIPTC_TEST_WORKERS"] ?? "2";
const workers = Number(configuredWorkers);
if (!Number.isInteger(workers) || workers < 1) {
throw new Error("SCRIPTC_TEST_WORKERS must be a positive integer");
}
export default defineConfig({
resolve: {
alias: {
// Tests run against compiler source directly — no build step needed.
"@scriptc/compiler": fileURLToPath(
new URL("./packages/compiler/src/index.ts", import.meta.url),
),
},
},
test: {
include: [
"tests/harness/**/*.test.ts",
"packages/*/src/**/*.test.ts",
"packages/*/test/**/*.test.ts",
],
// The Test262 regression profile compiles every pinned vendor case and is
// currently red on ten known compiler bugs recorded in
// .red/researches/2026-09-25-upstream-merge/test262-baseline.json. It runs
// as its own gate via `pnpm test:test262` and joins CI once the lane is
// green; keeping it out of the default suite leaves the ordinary gate at
// its pre-existing baseline rather than adding ten new failures.
exclude: ["**/node_modules/**", "**/dist/**", "tests/harness/test262.test.ts"],
// Differential tests spawn clang + binaries; give them room. 300s is a
// hang detector, not a performance bound: under a merge gate sharing
// the box with lane compiles, a legitimately compile-heavy corpus
// entry can starve past 120s (1751 timed out twice on 2026-07-20 while
// passing in 3s isolated and uncached).
testTimeout: 300_000,
hookTimeout: 300_000,
env: {
SCRIPTC_CACHE_DIR: cacheDir,
...(process.platform === "win32" ? {} : { TMPDIR: testTmpDir }),
SCRIPTC_NATIVE_WORKERS: process.env["SCRIPTC_NATIVE_WORKERS"] ?? "2",
CARGO_BUILD_JOBS: process.env["CARGO_BUILD_JOBS"] ?? "1",
// The differential lanes run against one immutable checkout/toolchain
// per worker. Reuse expensive compiler/linker metadata probes inside
// that session; cc.test.ts removes this flag to keep exercising
// production's fresh-probe invalidation guarantees.
SCRIPTC_TEST_STABLE_TOOLCHAIN:
process.env["SCRIPTC_TEST_STABLE_TOOLCHAIN"] ?? "1",
},
maxWorkers: workers,
minWorkers: 1,
globalSetup: ["./tests/harness/suite-lock.mjs"],
},
});