52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
/**
|
|
* Tree-shake guard — verify subpaths don't drag unrelated modules.
|
|
*/
|
|
import { readFile } from "node:fs/promises";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { describe, expect, it } from "../src/runner/index.js";
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const distRoot = resolve(here, "..", "dist");
|
|
|
|
async function distExists(): Promise<boolean> {
|
|
try {
|
|
await readFile(resolve(distRoot, "index.js"), "utf8");
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function readDist(rel: string): Promise<string> {
|
|
return readFile(resolve(distRoot, rel), "utf8");
|
|
}
|
|
|
|
describe("tree-shake guards", () => {
|
|
it("matchers subpath does not pull renderComponent", {
|
|
timeout: 10000,
|
|
}, async () => {
|
|
if (!(await distExists())) return;
|
|
const text = await readDist("matchers/matchers.js");
|
|
expect(text).not.toMatch(/function\s+renderComponent\b/);
|
|
expect(text).not.toMatch(/class\s+RenderError\b/);
|
|
});
|
|
|
|
it("user/setup-user does not pull jest-dom matchers", {
|
|
timeout: 10000,
|
|
}, async () => {
|
|
if (!(await distExists())) return;
|
|
const text = await readDist("user/setup-user.js");
|
|
expect(text).not.toMatch(/toBeInTheDocument/);
|
|
expect(text).not.toMatch(/jest-dom/);
|
|
});
|
|
|
|
it("polyfills subpath has no functional surface", {
|
|
timeout: 10000,
|
|
}, async () => {
|
|
if (!(await distExists())) return;
|
|
const text = await readDist("setup/polyfills.js");
|
|
expect(text).not.toMatch(/export\s+(?:const|function|class)/);
|
|
});
|
|
});
|