|
| 1 | +import { dirname } from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | + |
| 4 | +import test, { expect } from '@playwright/test'; |
| 5 | +import { createRsbuild } from '@rsbuild/core'; |
| 6 | + |
| 7 | +import { pluginTailwindCSS } from '../../src'; |
| 8 | +import { getRandomPort } from '../helper'; |
| 9 | + |
| 10 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 11 | + |
| 12 | +test('should build with multiple configs for different entries', async ({ |
| 13 | + page, |
| 14 | +}) => { |
| 15 | + const rsbuild = await createRsbuild({ |
| 16 | + cwd: __dirname, |
| 17 | + rsbuildConfig: { |
| 18 | + source: { |
| 19 | + entry: { |
| 20 | + index: './src/index.js', |
| 21 | + main: './src/main.js', |
| 22 | + default: './src/default.js', |
| 23 | + }, |
| 24 | + }, |
| 25 | + plugins: [ |
| 26 | + pluginTailwindCSS({ |
| 27 | + multipleConfig: { |
| 28 | + index: './config/tailwind.index.config.js', |
| 29 | + main: './config/tailwind.main.config.js', |
| 30 | + }, |
| 31 | + }), |
| 32 | + ], |
| 33 | + server: { |
| 34 | + port: getRandomPort(), |
| 35 | + }, |
| 36 | + }, |
| 37 | + }); |
| 38 | + |
| 39 | + await rsbuild.build(); |
| 40 | + |
| 41 | + const { server, urls } = await rsbuild.startDevServer(); |
| 42 | + |
| 43 | + await page.goto(`${urls[0]}/index`); |
| 44 | + let style = await getStyle(); |
| 45 | + expect(style.backgroundColor).toBe('rgb(0, 85, 255)'); |
| 46 | + |
| 47 | + await page.goto(`${urls[0]}/main`); |
| 48 | + style = await getStyle(); |
| 49 | + expect(style.backgroundColor).toBe('rgb(255, 85, 0)'); |
| 50 | + |
| 51 | + await page.goto(`${urls[0]}/default`); |
| 52 | + style = await getStyle(); |
| 53 | + expect(style.backgroundColor).toBe('rgb(85, 255, 0)'); |
| 54 | + |
| 55 | + await server.close(); |
| 56 | + |
| 57 | + async function getStyle() { |
| 58 | + return await page.evaluate(() => { |
| 59 | + const el = document.getElementById('test'); |
| 60 | + |
| 61 | + if (!el) { |
| 62 | + throw new Error('#test not found'); |
| 63 | + } |
| 64 | + |
| 65 | + return window.getComputedStyle(el); |
| 66 | + }); |
| 67 | + } |
| 68 | +}); |
0 commit comments