Skip to content

Commit 403290a

Browse files
authored
test(v4): cover preflight and layer ordering (#83)
## Summary - Add Playwright test verifying preflight base styles (body, button, list) are applied via the virtual global CSS injected by the plugin. - Add Playwright test verifying explicit @layer ordering () controls which declarations win across layers.
1 parent 80cb611 commit 403290a

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

test/basic/index.test.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,97 @@ test('should build with tailwind utilities', async ({ page }) => {
2525
await server.close();
2626
});
2727

28+
test('preflight base styles are applied from virtual global CSS', async ({
29+
page,
30+
}) => {
31+
const rsbuild = await createRsbuild({
32+
cwd: __dirname,
33+
rsbuildConfig: {
34+
plugins: [pluginTailwindCSS()],
35+
},
36+
});
37+
38+
await rsbuild.build();
39+
const { server, urls } = await rsbuild.preview();
40+
41+
try {
42+
await page.goto(urls[0]);
43+
44+
await page.evaluate(() => {
45+
const button = document.createElement('button');
46+
button.id = 'preflight-button';
47+
button.textContent = 'Button';
48+
document.body.appendChild(button);
49+
50+
const list = document.createElement('ul');
51+
list.id = 'preflight-list';
52+
const item = document.createElement('li');
53+
item.textContent = 'Item';
54+
list.appendChild(item);
55+
document.body.appendChild(list);
56+
});
57+
58+
await expect(page.locator('body')).toHaveCSS('margin', '0px');
59+
await expect(page.locator('#preflight-button')).toHaveCSS(
60+
'border-radius',
61+
'0px',
62+
);
63+
await expect(page.locator('#preflight-button')).toHaveCSS(
64+
'background-color',
65+
'rgba(0, 0, 0, 0)',
66+
);
67+
await expect(page.locator('#preflight-list')).toHaveCSS(
68+
'list-style-type',
69+
'none',
70+
);
71+
} finally {
72+
await server.close();
73+
}
74+
});
75+
76+
test('layer order controls which styles win across layers', async ({
77+
page,
78+
}) => {
79+
const rsbuild = await createRsbuild({
80+
cwd: __dirname,
81+
rsbuildConfig: {
82+
plugins: [pluginTailwindCSS()],
83+
},
84+
});
85+
86+
await rsbuild.build();
87+
const { server, urls } = await rsbuild.preview();
88+
89+
try {
90+
await page.goto(urls[0]);
91+
92+
await page.addStyleTag({
93+
content: `@layer utilities {
94+
#layer-order-test { color: red; }
95+
}
96+
97+
@layer base {
98+
#layer-order-test { color: blue; }
99+
}
100+
`,
101+
});
102+
103+
await page.evaluate(() => {
104+
const el = document.createElement('div');
105+
el.id = 'layer-order-test';
106+
el.textContent = 'Layer order';
107+
document.body.appendChild(el);
108+
});
109+
110+
await expect(page.locator('#layer-order-test')).toHaveCSS(
111+
'color',
112+
'rgb(255, 0, 0)',
113+
);
114+
} finally {
115+
await server.close();
116+
}
117+
});
118+
28119
test('should not generate tailwind.config.js in dist/', async () => {
29120
const rsbuild = await createRsbuild({
30121
cwd: __dirname,

0 commit comments

Comments
 (0)