= { new (): { $props: P } };\nexport interface GlobalComponents {}\n"); afterAll(() => rmSync(app, { recursive: true, force: true })); -function typecheck(moduleResolution: string, module: string, type: "module" | "commonjs", files = ["consumer.ts"]) { +async function typecheck(moduleResolution: string, module: string, type: "module" | "commonjs", files = ["consumer.ts"]) { writeFileSync(join(app, "package.json"), JSON.stringify({ type })); const compilerOptions = { target: "ES2022", module, moduleResolution, lib: ["ES2022", "DOM", "DOM.Iterable"], types: [], strict: true, noEmit: true, skipLibCheck: false, jsx: "react-jsx" }; writeFileSync(join(app, "tsconfig.json"), JSON.stringify({ compilerOptions, files })); - try { execFileSync(process.execPath, [tsc, "-p", "tsconfig.json"], { cwd: app, stdio: "pipe" }); return ""; } - catch (e) { return String((e as { stdout?: Buffer }).stdout ?? e); } + return tscErrors("tsconfig.json", app); } describe("published types", () => { @@ -61,21 +68,21 @@ describe("published types", () => { expect(readFileSync(`${root}/dist/${f}`, "utf8"), f).not.toMatch(/(from|import\()\s*["']\.\/[^"']*\.ts["']/); } }); - it("type-checks in an app with the original settings (self-reference)", () => { - expect(() => execFileSync(process.execPath, [tsc, "-p", "test/types/tsconfig.json"], { cwd: root, stdio: "pipe" })).not.toThrow(); + it("type-checks in an app with the original settings (self-reference)", async () => { + expect(await tscErrors("test/types/tsconfig.json", root)).toBe(""); }, 60_000); it.each([ ["bundler", "esnext", "module"], ["node16", "node16", "module"], ["nodenext", "nodenext", "module"], ["node10", "commonjs", "commonjs"], - ] as const)("type-checks in an app with moduleResolution %s", (mr, m, type) => { - expect(typecheck(mr, m, type)).toBe(""); + ] as const)("type-checks in an app with moduleResolution %s", async (mr, m, type) => { + expect(await typecheck(mr, m, type)).toBe(""); }, 60_000); - it("types React 19 props, events and the hook", () => { - expect(typecheck("bundler", "esnext", "module", ["consumer-react.tsx"])).toBe(""); + it("types React 19 props, events and the hook", async () => { + expect(await typecheck("bundler", "esnext", "module", ["consumer-react.tsx"])).toBe(""); }, 60_000); - it("types Vue template events", () => { - expect(typecheck("bundler", "esnext", "module", ["consumer-vue.ts"])).toBe(""); + it("types Vue template events", async () => { + expect(await typecheck("bundler", "esnext", "module", ["consumer-vue.ts"])).toBe(""); }, 60_000); });