Repository navigation
Expand file tree
/
Copy pathreactCompilerCoverage.test.ts
More file actions
41 lines (36 loc) · 1.8 KB
/
Copy pathreactCompilerCoverage.test.ts
File metadata and controls
41 lines (36 loc) · 1.8 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
// @effect-diagnostics nodeBuiltinImport:off - compiles real source files on disk.
import * as NodeFS from "node:fs";
import * as NodePath from "node:path";
import * as NodeURL from "node:url";
import { transform } from "oxc-transform-react";
import { describe, expect, it } from "vite-plus/test";
const repoRoot = NodePath.resolve(
NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)),
"../../..",
);
const webSourceFiles = NodeFS.readdirSync(NodePath.join(repoRoot, "apps/web/src"), {
recursive: true,
})
.map(String)
.filter((file) => /\.tsx?$/.test(file) && !/\.(test|browser)\.tsx?$/.test(file))
.filter((file) => !file.endsWith(".gen.ts"))
.map((file) => `apps/web/src/${file}`);
// ChatView is ~9k lines. Compiling it takes ~9s on a fast machine and can pass the
// 15s project limit on loaded CI runners, so slow files get a 60s limit below.
const slowFiles = new Set(["apps/web/src/components/ChatView.tsx"]);
const compile = async (file: string) => {
const absolute = NodePath.join(repoRoot, file);
const result = await transform(absolute, NodeFS.readFileSync(absolute, "utf8"), {
jsx: { runtime: "automatic", development: false, refresh: false },
reactCompiler: { reportDiagnostics: true },
});
const bailouts = result.errors.map((error) => error.codeframe ?? error.message);
expect(bailouts).toEqual([]);
};
// Lint reports most compiler bailouts, but not every one (try/finally, throw
// inside try). A skipped file still builds, just unmemoized, so check the output.
describe("React Compiler coverage", () => {
it.each(webSourceFiles.filter((file) => !slowFiles.has(file)))("compiles %s", compile);
// oxlint-disable-next-line t3code/no-test-timeout-or-unreasoned-skip -- CPU-bound compile of a huge file, not a hidden wait.
it.each([...slowFiles])("compiles %s", compile, 60_000);
});