37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { findMissingLocalImports } from "./local-imports";
|
|
|
|
const roots: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe("findMissingLocalImports", () => {
|
|
it("reports unresolved alias imports and ignores modules that exist", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "epicnext-imports-"));
|
|
roots.push(root);
|
|
await mkdir(join(root, "src", "features"), { recursive: true });
|
|
await mkdir(join(root, "src", "components", "ui"), { recursive: true });
|
|
await writeFile(join(root, "src", "components", "ui", "card.tsx"), "export const Card = {};\n");
|
|
await writeFile(
|
|
join(root, "src", "features", "page.tsx"),
|
|
[
|
|
'import { Card } from "@/components/ui/card";',
|
|
'import { Button } from "@/components/ui/button";',
|
|
"export default Card;",
|
|
].join("\n"),
|
|
);
|
|
|
|
await expect(findMissingLocalImports(root)).resolves.toEqual([
|
|
{
|
|
importer: "src/features/page.tsx",
|
|
specifier: "@/components/ui/button",
|
|
},
|
|
]);
|
|
});
|
|
});
|