|
| 1 | +import { dirname } from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | + |
| 4 | +import { expect, test } from '@playwright/test'; |
| 5 | +import { createRsbuild } from '@rsbuild/core'; |
| 6 | + |
| 7 | +import { pluginTailwindCSS } from '../../src'; |
| 8 | +import { getRandomPort, supportESM } from '../helper'; |
| 9 | + |
| 10 | +const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 11 | + |
| 12 | +test('plugin', async ({ page }) => { |
| 13 | + test.skip( |
| 14 | + !supportESM(), |
| 15 | + 'Skip since the tailwindcss version does not support ESM configuration', |
| 16 | + ); |
| 17 | + |
| 18 | + const rsbuild = await createRsbuild({ |
| 19 | + cwd: __dirname, |
| 20 | + rsbuildConfig: { |
| 21 | + plugins: [ |
| 22 | + pluginTailwindCSS({ |
| 23 | + config: './config/tailwind.config.js', |
| 24 | + }), |
| 25 | + ], |
| 26 | + server: { |
| 27 | + port: getRandomPort(), |
| 28 | + }, |
| 29 | + }, |
| 30 | + }); |
| 31 | + |
| 32 | + await rsbuild.build(); |
| 33 | + const { server, urls } = await rsbuild.preview(); |
| 34 | + |
| 35 | + try { |
| 36 | + await page.goto(urls[0]); |
| 37 | + await page.waitForSelector('#test', { state: 'attached' }); |
| 38 | + |
| 39 | + const style = await page.evaluate(() => { |
| 40 | + const el = document.getElementById('test'); |
| 41 | + |
| 42 | + if (!el) { |
| 43 | + throw new Error('#test not found'); |
| 44 | + } |
| 45 | + |
| 46 | + const computed = window.getComputedStyle(el); |
| 47 | + return { |
| 48 | + position: computed.getPropertyValue('position'), |
| 49 | + top: computed.getPropertyValue('top'), |
| 50 | + }; |
| 51 | + }); |
| 52 | + |
| 53 | + expect(style.position).toBe('fixed'); |
| 54 | + expect(style.top).toBe('0px'); |
| 55 | + } finally { |
| 56 | + await server.close(); |
| 57 | + } |
| 58 | +}); |
0 commit comments