From 48622e7b51e9f1bb1e9fa983437aaed03ecfada3 Mon Sep 17 00:00:00 2001 From: Qingyu Wang Date: Fri, 27 Feb 2026 15:38:50 +0800 Subject: [PATCH 1/2] test: ensure no interference with static assets query --- test/static-assets/index.test.ts | 39 ++++++++++++++++++++++++++++++++ test/static-assets/src/index.css | 3 +++ test/static-assets/src/index.js | 9 ++++++++ 3 files changed, 51 insertions(+) create mode 100644 test/static-assets/index.test.ts create mode 100644 test/static-assets/src/index.css create mode 100644 test/static-assets/src/index.js diff --git a/test/static-assets/index.test.ts b/test/static-assets/index.test.ts new file mode 100644 index 0000000..208e225 --- /dev/null +++ b/test/static-assets/index.test.ts @@ -0,0 +1,39 @@ +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { expect, test } from '@playwright/test'; +import { createRsbuild } from '@rsbuild/core'; +import { pluginTailwindCSS } from '../../src'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +test('should not interfere with static asset queries (?url, ?raw)', async ({ + page, +}) => { + const rsbuild = await createRsbuild({ + cwd: __dirname, + rsbuildConfig: { + plugins: [pluginTailwindCSS()], + }, + }); + + await rsbuild.build(); + const { server, urls } = await rsbuild.preview(); + + await page.goto(urls[0]); + + const cssUrl = await page.evaluate(() => window.cssUrl); + const cssRaw = await page.evaluate(() => window.cssRaw); + + // Check ?url + expect(cssUrl).toMatch(/\.css$/); + + // Check ?raw + // It should contain the original CSS content, NOT Tailwind's injected content (like @tailwind base etc.) + expect(cssRaw).toContain('.foo {'); + expect(cssRaw).toContain('color: red;'); + + // Ensure it's not empty or undefined + expect(cssRaw).toBeTruthy(); + + await server.close(); +}); diff --git a/test/static-assets/src/index.css b/test/static-assets/src/index.css new file mode 100644 index 0000000..a15c877 --- /dev/null +++ b/test/static-assets/src/index.css @@ -0,0 +1,3 @@ +.foo { + color: red; +} diff --git a/test/static-assets/src/index.js b/test/static-assets/src/index.js new file mode 100644 index 0000000..dc11f60 --- /dev/null +++ b/test/static-assets/src/index.js @@ -0,0 +1,9 @@ +// import url from './index.css?url'; +const url = new URL('./index.css', import.meta.url).href; +import raw from './index.css?raw'; + +window.cssUrl = url; +window.cssRaw = raw; + +// We also need to inject it to make sure it doesn't break normal behavior +import './index.css'; From 03d4cf150e970f1de37c5ddd5d5b64359708d7a0 Mon Sep 17 00:00:00 2001 From: Qingyu Wang <40660121+colinaaa@users.noreply.github.com> Date: Fri, 27 Feb 2026 16:15:14 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- test/static-assets/index.test.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/static-assets/index.test.ts b/test/static-assets/index.test.ts index 208e225..c46049b 100644 --- a/test/static-assets/index.test.ts +++ b/test/static-assets/index.test.ts @@ -1,4 +1,5 @@ -import { dirname } from 'node:path'; +import { readFileSync } from 'node:fs'; +import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { expect, test } from '@playwright/test'; import { createRsbuild } from '@rsbuild/core'; @@ -29,11 +30,8 @@ test('should not interfere with static asset queries (?url, ?raw)', async ({ // Check ?raw // It should contain the original CSS content, NOT Tailwind's injected content (like @tailwind base etc.) - expect(cssRaw).toContain('.foo {'); - expect(cssRaw).toContain('color: red;'); - - // Ensure it's not empty or undefined - expect(cssRaw).toBeTruthy(); + const originalCss = readFileSync(resolve(__dirname, 'src/index.css'), 'utf-8'); + expect(cssRaw.trim()).toBe(originalCss.trim()); await server.close(); });