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

reactCompiledFiles.test.ts

38 lines1.6 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, REACT_COMPILED_FILES_PENDING_LINT } 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, ...REACT_COMPILED_FILES_PENDING_LINT].flatMap(expandPattern))(
27 "compiles %s",
28 async (file) => {
29 const absolute = NodePath.join(repoRoot, file);
30 const result = await transform(absolute, NodeFS.readFileSync(absolute, "utf8"), {
31 jsx: { runtime: "automatic", development: false, refresh: false },
32 reactCompiler: { reportDiagnostics: true },
33 });
34 const bailouts = result.errors.map((error) => error.codeframe ?? error.message);
35 expect(bailouts).toEqual([]);
36 },
37 );
38}, 120_000);