From 12eb5ae7b6026ff64c04f889b2221418d772da72 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 6 May 2026 11:10:17 +0200 Subject: [PATCH] Cleanup noisy test output (#20015) This PR cleans up the noisy test output where some `console.warn` messages were leaking into the test output. This also uses the `src/` files instead of the `dist/` files of `@tailwindcss/node` to get rid of a source map related warning in tests. It also means that we don't have to rebuild `@tailwindcss/node` when we make changes. ## Test plan 1. Existing tests pass 2. Output is clean when running tests (`vitest run --reporter=minimal`) Before: image After: image --- packages/@tailwindcss-node/package.json | 32 ++++++++++++++----- .../@tailwindcss-node/src/require-cache.ts | 5 +++ .../@tailwindcss-postcss/src/index.test.ts | 2 ++ packages/tailwindcss/src/utilities.test.ts | 17 ++++++++++ 4 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 packages/@tailwindcss-node/src/require-cache.ts diff --git a/packages/@tailwindcss-node/package.json b/packages/@tailwindcss-node/package.json index 560bd17ef..80335b894 100644 --- a/packages/@tailwindcss-node/package.json +++ b/packages/@tailwindcss-node/package.json @@ -19,21 +19,37 @@ ], "publishConfig": { "provenance": true, - "access": "public" + "access": "public", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.mjs", + "require": "./dist/index.js" + }, + "./require-cache": { + "types": "./dist/require-cache.d.ts", + "default": "./dist/require-cache.js" + }, + "./esm-cache-loader": { + "types": "./dist/esm-cache.loader.d.mts", + "default": "./dist/esm-cache.loader.mjs" + } + } }, "exports": { ".": { - "types": "./dist/index.d.ts", - "import": "./dist/index.mjs", - "require": "./dist/index.js" + "types": "./src/index.ts", + "import": "./src/index.ts", + "require": "./src/index.cts" }, "./require-cache": { - "types": "./dist/require-cache.d.ts", - "default": "./dist/require-cache.js" + "types": "./src/require-cache.ts", + "import": "./src/require-cache.ts", + "require": "./src/require-cache.cts" }, "./esm-cache-loader": { - "types": "./dist/esm-cache.loader.d.mts", - "default": "./dist/esm-cache.loader.mjs" + "types": "./src/esm-cache.loader.mts", + "default": "./src/esm-cache.loader.mts" } }, "dependencies": { diff --git a/packages/@tailwindcss-node/src/require-cache.ts b/packages/@tailwindcss-node/src/require-cache.ts new file mode 100644 index 000000000..ea0562019 --- /dev/null +++ b/packages/@tailwindcss-node/src/require-cache.ts @@ -0,0 +1,5 @@ +export function clearRequireCache(files: string[]) { + for (let key of files) { + delete require.cache[key] + } +} diff --git a/packages/@tailwindcss-postcss/src/index.test.ts b/packages/@tailwindcss-postcss/src/index.test.ts index 3ded1f810..14acdec50 100644 --- a/packages/@tailwindcss-postcss/src/index.test.ts +++ b/packages/@tailwindcss-postcss/src/index.test.ts @@ -146,6 +146,8 @@ describe('processing without specifying a base path', () => { }) test('fallback to `base` directory when `result.opts.from` is not provided', async () => { + using _ = vi.spyOn(console, 'warn').mockImplementation(() => {}) + let processor = postcss([ tailwindcss({ base: `${__dirname}/fixtures/example-project`, optimize: { minify: false } }), ]) diff --git a/packages/tailwindcss/src/utilities.test.ts b/packages/tailwindcss/src/utilities.test.ts index f4b235bb1..443ef1c9f 100644 --- a/packages/tailwindcss/src/utilities.test.ts +++ b/packages/tailwindcss/src/utilities.test.ts @@ -30148,6 +30148,7 @@ describe('custom utilities', () => { }) test('resolving unsupported bare values', async () => { + using spy = vi.spyOn(console, 'warn').mockImplementation(() => {}) let input = css` @utility tab-* { tab-size: --value(color); @@ -30157,6 +30158,22 @@ describe('custom utilities', () => { ` expect(await compileCss(input, ['tab-#0088cc', 'tab-foo'])).toEqual('') + expect( + `\n${spy.mock.calls + .map((c) => c.join(' ')) + .join('\n') + .trim()}\n`, + ).toMatchInlineSnapshot(` + " + Unsupported bare value data type: "color". + Only valid data types are: "number", "integer", "ratio", "percentage". + + \`\`\`css + --value(color) + ^^^^^ + \`\`\` + " + `) }) test('resolving arbitrary values', async () => {