From 44c27caf8b0801c91b28eb968b47f031a99af4f2 Mon Sep 17 00:00:00 2001 From: Qingyu Wang Date: Fri, 27 Feb 2026 15:39:15 +0800 Subject: [PATCH] test: verify cjs module compatibility --- test/cjs-compat/index.test.ts | 26 ++++++++++++++++++++++++++ test/cjs-compat/src/index.js | 6 ++++++ test/cjs-compat/src/lib.cjs | 4 ++++ 3 files changed, 36 insertions(+) create mode 100644 test/cjs-compat/index.test.ts create mode 100644 test/cjs-compat/src/index.js create mode 100644 test/cjs-compat/src/lib.cjs diff --git a/test/cjs-compat/index.test.ts b/test/cjs-compat/index.test.ts new file mode 100644 index 0000000..b4ec712 --- /dev/null +++ b/test/cjs-compat/index.test.ts @@ -0,0 +1,26 @@ +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 CJS modules', 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 locator = page.locator('#cjs-output'); + await expect(locator).toHaveText('Hello from CJS'); + + await server.close(); +}); diff --git a/test/cjs-compat/src/index.js b/test/cjs-compat/src/index.js new file mode 100644 index 0000000..9c69427 --- /dev/null +++ b/test/cjs-compat/src/index.js @@ -0,0 +1,6 @@ +import lib from './lib.cjs'; + +const div = document.createElement('div'); +div.id = 'cjs-output'; +div.textContent = lib.message; +document.body.appendChild(div); diff --git a/test/cjs-compat/src/lib.cjs b/test/cjs-compat/src/lib.cjs new file mode 100644 index 0000000..da42510 --- /dev/null +++ b/test/cjs-compat/src/lib.cjs @@ -0,0 +1,4 @@ +module.exports = { + message: 'Hello from CJS', + data: Array.from({ length: 1000 }, (_, i) => i), // Some data to make it "large" +};