Skip to content

Commit aa77d5b

Browse files
committed
test: add @reference support verification
1 parent 403290a commit aa77d5b

File tree

7 files changed

+51
-0
lines changed

7 files changed

+51
-0
lines changed

test/at-reference/index.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 handle @reference directive correctly in CSS modules', async ({
10+
page,
11+
}) => {
12+
const rsbuild = await createRsbuild({
13+
cwd: __dirname,
14+
rsbuildConfig: {
15+
plugins: [pluginTailwindCSS()],
16+
},
17+
});
18+
19+
await rsbuild.build();
20+
const { server, urls } = await rsbuild.preview();
21+
22+
await page.goto(urls[0]);
23+
24+
const locator = page.locator('#test-div');
25+
// Check if the custom color defined in theme.css is applied via @apply in the module
26+
await expect(locator).toHaveCSS('background-color', 'rgb(18, 52, 86)'); // #123456
27+
28+
await server.close();
29+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@reference "./theme.css";
2+
3+
.myButton {
4+
@apply bg-custom-brand;
5+
}

test/at-reference/src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import styles from './App.module.css';
2+
3+
const div = document.createElement('div');
4+
div.id = 'test-div';
5+
div.className = styles.myButton;
6+
div.textContent = 'Test Button';
7+
document.body.appendChild(div);

test/at-reference/src/theme.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@theme {
2+
--color-custom-brand: #123456;
3+
}

test/css-modules/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ test('can co-exist with CSS modules', async ({ page }) => {
2222
const locator = page.locator('#button');
2323
await expect(locator).toHaveCSS('display', 'flex');
2424
await expect(locator).toHaveCSS('color', 'rgb(17, 34, 51)');
25+
await expect(locator).toHaveCSS('background-color', 'rgb(170, 187, 204)');
2526

2627
await server.close();
2728
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
@reference "../theme.css";
2+
13
.button {
24
color: #112233;
5+
@apply bg-btn-bg;
36
}

test/css-modules/src/theme.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@theme {
2+
--color-btn-bg: #aabbcc;
3+
}

0 commit comments

Comments
 (0)