From 5ef7a2e2cce766b39ef72ac56a2312e8d6d3b0d0 Mon Sep 17 00:00:00 2001 From: Yevhenii Date: Sat, 17 Oct 2026 01:54:51 +0300 Subject: [PATCH] test: give each Tailwind render its own cache key, never the clock The harness passed Date.now() as Tailwind's base to keep renders from sharing its compiler cache, so two renders that start in the same millisecond shared it, and the second compiled against the first's stylesheet: a random Tailwind case failed in a full run and passed alone. A counter gives every render a base of its own. --- src/__tests__/vendor/tailwind/_tailwind.tsx | 6 ++++-- src/__tests__/vendor/tailwind/harness.test.tsx | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/__tests__/vendor/tailwind/harness.test.tsx diff --git a/src/__tests__/vendor/tailwind/_tailwind.tsx b/src/__tests__/vendor/tailwind/_tailwind.tsx index 3ba5db5e..49b18e6a 100644 --- a/src/__tests__/vendor/tailwind/_tailwind.tsx +++ b/src/__tests__/vendor/tailwind/_tailwind.tsx @@ -36,6 +36,8 @@ const debugDefault = typeof process.env.NODE_OPTIONS === "string" && process.env.NODE_OPTIONS.includes("--inspect"); +let renderCount = 0; + export async function render( component: ReactElement, { @@ -76,8 +78,8 @@ export async function render( // Process the TailwindCSS const { css: output } = await postcss([ - /* Tailwind seems to internally cache things, so we need a random value to cache bust */ - tailwind({ base: Date.now().toString() }), + // Tailwind caches its compiler per base, so each render takes a base of its own + tailwind({ base: `render-${renderCount++}` }), ]).process(css, { from: __dirname, }); diff --git a/src/__tests__/vendor/tailwind/harness.test.tsx b/src/__tests__/vendor/tailwind/harness.test.tsx new file mode 100644 index 00000000..cc13fd8b --- /dev/null +++ b/src/__tests__/vendor/tailwind/harness.test.tsx @@ -0,0 +1,16 @@ +import { renderSimple } from "./_tailwind"; + +afterEach(() => { + jest.restoreAllMocks(); +}); + +test("two renders in one millisecond each compile their own classes", async () => { + jest.spyOn(Date, "now").mockReturnValue(0); + + expect(await renderSimple({ className: "left-0" })).toStrictEqual({ + props: { style: { left: 0 } }, + }); + expect(await renderSimple({ className: "left-1" })).toStrictEqual({ + props: { style: { left: 3.5 } }, + }); +});