|
| 1 | +import { dirname, resolve } from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | +import { expect, test } from '@playwright/test'; |
| 4 | +import { createRsbuild } from '@rsbuild/core'; |
| 5 | +import { pluginTailwindCSS } from '../../src'; |
| 6 | + |
| 7 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 8 | + |
| 9 | +test('should build with relative config', async ({ page }) => { |
| 10 | + const rsbuild = await createRsbuild({ |
| 11 | + cwd: __dirname, |
| 12 | + rsbuildConfig: { |
| 13 | + plugins: [ |
| 14 | + pluginTailwindCSS({ |
| 15 | + config: './config/tailwind.config.js', |
| 16 | + }), |
| 17 | + ], |
| 18 | + }, |
| 19 | + }); |
| 20 | + |
| 21 | + await rsbuild.build(); |
| 22 | + const { server, urls } = await rsbuild.preview(); |
| 23 | + |
| 24 | + await page.goto(urls[0]); |
| 25 | + |
| 26 | + const display = await page.evaluate(() => { |
| 27 | + const el = document.getElementById('test'); |
| 28 | + |
| 29 | + if (!el) { |
| 30 | + throw new Error('#test not found'); |
| 31 | + } |
| 32 | + |
| 33 | + return window.getComputedStyle(el).getPropertyValue('display'); |
| 34 | + }); |
| 35 | + |
| 36 | + expect(display).toBe('flex'); |
| 37 | + |
| 38 | + await server.close(); |
| 39 | +}); |
| 40 | + |
| 41 | +test('should build with absolute config', async ({ page }) => { |
| 42 | + const rsbuild = await createRsbuild({ |
| 43 | + cwd: __dirname, |
| 44 | + rsbuildConfig: { |
| 45 | + plugins: [ |
| 46 | + pluginTailwindCSS({ |
| 47 | + config: resolve(__dirname, './config/tailwind.config.js'), |
| 48 | + }), |
| 49 | + ], |
| 50 | + }, |
| 51 | + }); |
| 52 | + |
| 53 | + await rsbuild.build(); |
| 54 | + const { server, urls } = await rsbuild.preview(); |
| 55 | + |
| 56 | + await page.goto(urls[0]); |
| 57 | + |
| 58 | + const display = 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).getPropertyValue('display'); |
| 66 | + }); |
| 67 | + |
| 68 | + expect(display).toBe('flex'); |
| 69 | + |
| 70 | + await server.close(); |
| 71 | +}); |
0 commit comments