Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-production-text-warnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/kumo": patch
---

Suppress deprecated `Text` heading variant warnings in production while retaining them during development.
54 changes: 39 additions & 15 deletions packages/kumo/src/components/text/text.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { describe, expect, it, vi } from "vite-plus/test";
import { afterEach, describe, expect, it, vi } from "vite-plus/test";
import { render } from "@testing-library/react";
import { Text, textVariants } from "./text";

describe("Text", () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.restoreAllMocks();
});

it("renders heading as a 16px semibold span by default", () => {
const { container } = render(<Text variant="heading">Heading</Text>);
const heading = container.querySelector("span");
Expand All @@ -26,20 +31,39 @@ describe("Text", () => {
expect(heading?.classList.contains("font-semibold")).toBe(true);
});

it("warns when a deprecated heading variant is used", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});

render(
<Text variant="heading1" as="h1">
Legacy heading
</Text>,
);

expect(warn).toHaveBeenCalledWith(
expect.stringContaining('variant="heading1" is deprecated'),
);
warn.mockRestore();
});
it.each(["heading1", "heading2", "heading3"] as const)(
"warns in development when deprecated variant %s is used",
(variant) => {
vi.stubEnv("NODE_ENV", "development");
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});

render(
<Text variant={variant} as="h1">
Legacy heading
</Text>,
);

expect(warn).toHaveBeenCalledWith(
expect.stringContaining(`variant="${variant}" is deprecated`),
);
},
);

it.each(["heading1", "heading2", "heading3"] as const)(
"does not warn in production when deprecated variant %s is used",
(variant) => {
vi.stubEnv("NODE_ENV", "production");
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});

render(
<Text variant={variant} as="h1">
Legacy heading
</Text>,
);

expect(warn).not.toHaveBeenCalled();
},
);

it("renders body variant as <p> by default", () => {
const { container } = render(<Text>Body copy</Text>);
Expand Down
28 changes: 28 additions & 0 deletions packages/kumo/tests/build/production-behavior.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createElement } from "react";
import { render } from "@testing-library/react";
import { describe, expect, it, vi } from "vite-plus/test";
import { existsSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const textEntryPath = join(__dirname, "../../dist/components/text.js");
const isBuilt = existsSync(textEntryPath);

describe.skipIf(!isBuilt)("Production behavior (Post-Build)", () => {
it("does not emit deprecated Text variant warnings", async () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const { Text } = await import("../../dist/components/text.js");

render(
createElement(Text, {
variant: "heading1",
as: "h1",
children: "Legacy heading",
}),
);

expect(warn).not.toHaveBeenCalled();
warn.mockRestore();
});
});
3 changes: 3 additions & 0 deletions packages/kumo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export default defineConfig({
platform: "browser",
outDir: "dist",
dts: false,
// Published artifacts are production builds. Define NODE_ENV explicitly
// so Rolldown removes development-only warnings and their message strings.
define: { "process.env.NODE_ENV": '"production"' },
// The dts pass emits declarations this pass can't see — pair them by
// co-location; asset entries aren't chunks, so re-attach them here.
exports: {
Expand Down
Loading