Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

reactCompiledFiles.test.ts

35 lines1.5 KB

1// @effect-diagnostics nodeBuiltinImport:off - compiles real source files on disk.
2import * as NodeFS from "node:fs";
3import * as NodePath from "node:path";
4import * as NodeURL from "node:url";
5import { transform } from "oxc-transform-react";
6import { describe, expect, it } from "vite-plus/test";
7import { REACT_COMPILED_FILES } from "../reactCompiledFiles";
8​
9const repoRoot = NodePath.resolve(
10 NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)),
11 "../../..",
12);
13​
14function expandPattern(pattern: string): string[] {
15 if (!pattern.endsWith("/**")) return [pattern];
16 const directory = pattern.slice(0, -3);
17 return NodeFS.readdirSync(NodePath.join(repoRoot, directory), { recursive: true })
18 .map(String)
19 .filter((file) => /\.tsx?$/.test(file) && !/\.(test|browser)\.tsx?$/.test(file))
20 .map((file) => `${directory}/${file}`);
22​
23// Lint reports most compiler bailouts, but not every one (try/finally, throw
24// inside try). A skipped file still builds, just unmemoized, so check the output.
25describe("React Compiler coverage", () => {
26 it.each(REACT_COMPILED_FILES.flatMap(expandPattern))("compiles %s", async (file) => {
27 const absolute = NodePath.join(repoRoot, file);
28 const result = await transform(absolute, NodeFS.readFileSync(absolute, "utf8"), {
29 jsx: { runtime: "automatic", development: false, refresh: false },
30 reactCompiler: { reportDiagnostics: true },
31 });
32 const bailouts = result.errors.map((error) => error.codeframe ?? error.message);
33 expect(bailouts).toEqual([]);
34 });
35}, 120_000);