134 lines
5.5 KiB
TypeScript
134 lines
5.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { classifyBuildWarning, shouldSuppressBuildWarning } from "./buildWarningTriage";
|
|
|
|
describe("build warning triage", () => {
|
|
it("classifies large chunk warnings without suppressing them", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "PLUGIN_WARNING",
|
|
message: "Some chunks are larger than 1800 kB after minification. Consider code-splitting.",
|
|
});
|
|
|
|
expect(classification.class).toBe("large-chunk");
|
|
expect(classification.suppressed).toBe(false);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(false);
|
|
});
|
|
|
|
it("suppresses known empty chunk warnings that are covered by the bundle gate", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "EMPTY_BUNDLE",
|
|
message: 'Generated an empty chunk: "readyz".',
|
|
id: "apps/web/app/routes/readyz.tsx",
|
|
});
|
|
|
|
expect(classification.class).toBe("empty-chunk");
|
|
expect(classification.suppressed).toBe(true);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(true);
|
|
});
|
|
|
|
it("suppresses current React Router resource route empty chunks", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "EMPTY_BUNDLE",
|
|
message: 'Generated an empty chunk: "api.embed.forms._formKey.submit".',
|
|
});
|
|
|
|
expect(classification.class).toBe("empty-chunk");
|
|
expect(classification.suppressed).toBe(true);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(true);
|
|
});
|
|
|
|
it("keeps unknown empty chunk warnings visible", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "EMPTY_BUNDLE",
|
|
message: 'Generated an empty chunk: "new-empty-route".',
|
|
id: "apps/web/app/routes/new-empty-route.tsx",
|
|
});
|
|
|
|
expect(classification.class).toBe("empty-chunk");
|
|
expect(classification.suppressed).toBe(false);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(false);
|
|
});
|
|
|
|
it("classifies sourcemap resolve failures as suppressed", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "SOURCEMAP_ERROR",
|
|
message: "Can't resolve original location of error.",
|
|
id: "node_modules/example/index.js",
|
|
});
|
|
|
|
expect(classification.class).toBe("sourcemap-resolve-failure");
|
|
expect(classification.suppressed).toBe(true);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(true);
|
|
});
|
|
|
|
it("classifies production sourcemap warnings without suppressing them", () => {
|
|
const classification = classifyBuildWarning({
|
|
message: "Source maps are enabled in production",
|
|
});
|
|
|
|
expect(classification.class).toBe("production-sourcemap");
|
|
expect(classification.suppressed).toBe(false);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(false);
|
|
});
|
|
|
|
it("classifies AWS and Smithy circular chunk warnings without suppressing them", () => {
|
|
const classification = classifyBuildWarning({
|
|
message: [
|
|
'Export "Command" of module "../../node_modules/.pnpm/@smithy+core/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/command.js"',
|
|
'was reexported through module "../../node_modules/.pnpm/@aws-sdk+nested-clients/node_modules/@aws-sdk/nested-clients/dist-es/index.js"',
|
|
"while both modules are dependencies of each other and will end up in different chunks by current Rollup settings.",
|
|
"This scenario is not well supported at the moment as it will produce a circular dependency between chunks and will likely lead to broken execution order.",
|
|
].join(" "),
|
|
});
|
|
|
|
expect(classification.class).toBe("aws-smithy-circular-chunk");
|
|
expect(classification.suppressed).toBe(false);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(false);
|
|
});
|
|
|
|
it("classifies dynamic/static import chunking warnings without suppressing them", () => {
|
|
const classification = classifyBuildWarning({
|
|
message:
|
|
"apps/web/app/utils/db.server.ts is dynamically imported by apps/web/app/routes/admin/marketing-leads/index.tsx but also statically imported by apps/web/app/modules/crm/services/CrmService.ts, dynamic import will not move module into another chunk.",
|
|
});
|
|
|
|
expect(classification.class).toBe("dynamic-static-import");
|
|
expect(classification.suppressed).toBe(false);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(false);
|
|
});
|
|
|
|
it("classifies next-themes invalid annotation warnings as suppressed", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "INVALID_ANNOTATION",
|
|
message: "Contains an annotation that Rollup cannot interpret.",
|
|
id: "/repo/node_modules/next-themes/dist/index.mjs",
|
|
});
|
|
|
|
expect(classification.class).toBe("next-themes-invalid-annotation");
|
|
expect(classification.suppressed).toBe(true);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(true);
|
|
});
|
|
|
|
it("keeps unknown warnings unsuppressed", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "CIRCULAR_DEPENDENCY",
|
|
message: "Circular dependency detected between route modules.",
|
|
file: "apps/web/app/routes/dashboard.tsx",
|
|
});
|
|
|
|
expect(classification.class).toBe("unknown");
|
|
expect(classification.suppressed).toBe(false);
|
|
expect(shouldSuppressBuildWarning(classification)).toBe(false);
|
|
});
|
|
|
|
it("handles casing drift for known warning codes and messages", () => {
|
|
const classification = classifyBuildWarning({
|
|
code: "sourcemap_error",
|
|
message: "can't resolve original location of error.",
|
|
});
|
|
|
|
expect(classification.class).toBe("sourcemap-resolve-failure");
|
|
expect(classification.suppressed).toBe(true);
|
|
});
|
|
});
|