apps/web/src/reactCompilerCoverage.test.ts
// @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}`);
// 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)("compiles %s", async (file) => {
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([]);
});
}, 120_000);