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" +};