|
| 1 | +import { dirname } 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 support Tailwind CSS v4 features', async ({ page }) => { |
| 10 | + const rsbuild = await createRsbuild({ |
| 11 | + cwd: __dirname, |
| 12 | + rsbuildConfig: { |
| 13 | + plugins: [pluginTailwindCSS()], |
| 14 | + }, |
| 15 | + }); |
| 16 | + |
| 17 | + await rsbuild.build(); |
| 18 | + const { server, urls } = await rsbuild.preview(); |
| 19 | + |
| 20 | + await page.goto(urls[0]); |
| 21 | + |
| 22 | + // 1. Test !important modifier |
| 23 | + const important = page.locator('#important'); |
| 24 | + await expect(important).toHaveCSS('display', 'flex'); |
| 25 | + |
| 26 | + // 2. Test 3D transforms |
| 27 | + const transform = page.locator('#transform'); |
| 28 | + await expect(transform).toHaveCSS('perspective', '500px'); |
| 29 | + // Check for rotateX in transform. Computed value is usually a matrix. |
| 30 | + await expect(transform).not.toHaveCSS('transform', 'none'); |
| 31 | + |
| 32 | + // 3. Test Container Queries |
| 33 | + const containerItem = page.locator('#container-item'); |
| 34 | + // In v4, colors might be returned as lab/oklch depending on browser support. |
| 35 | + // We accept the lab value seen in tests or the rgb fallback if environment differs. |
| 36 | + // Received: "lab(55.4814 75.0732 48.8528)" |
| 37 | + const color = await containerItem.evaluate( |
| 38 | + (el) => getComputedStyle(el).color, |
| 39 | + ); |
| 40 | + expect(color).toMatch( |
| 41 | + /^(rgb\(239, 68, 68\)|lab\(55\.4814 75\.0732 48\.8528\)|oklch\(0\.637 0\.237 25\.331\))$/, |
| 42 | + ); |
| 43 | + |
| 44 | + await server.close(); |
| 45 | +}); |
0 commit comments