Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/at-reference/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test } from '@playwright/test';
import { createRsbuild } from '@rsbuild/core';
import { pluginTailwindCSS } from '../../src';

const __dirname = dirname(fileURLToPath(import.meta.url));

test('should handle @reference directive correctly in CSS modules', async ({
page,
}) => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
plugins: [pluginTailwindCSS()],
},
});

await rsbuild.build();
const { server, urls } = await rsbuild.preview();

await page.goto(urls[0]);

const locator = page.locator('#test-div');
// Check if the custom color defined in theme.css is applied via @apply in the module
await expect(locator).toHaveCSS('background-color', 'rgb(18, 52, 86)'); // #123456

await server.close();
});
5 changes: 5 additions & 0 deletions test/at-reference/src/App.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@reference "./theme.css";

.myButton {
@apply bg-custom-brand;
}
7 changes: 7 additions & 0 deletions test/at-reference/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import styles from './App.module.css';

const div = document.createElement('div');
div.id = 'test-div';
div.className = styles.myButton;
div.textContent = 'Test Button';
document.body.appendChild(div);
3 changes: 3 additions & 0 deletions test/at-reference/src/theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@theme {
--color-custom-brand: #123456;
}
1 change: 1 addition & 0 deletions test/css-modules/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test('can co-exist with CSS modules', async ({ page }) => {
const locator = page.locator('#button');
await expect(locator).toHaveCSS('display', 'flex');
await expect(locator).toHaveCSS('color', 'rgb(17, 34, 51)');
await expect(locator).toHaveCSS('background-color', 'rgb(170, 187, 204)');

await server.close();
});
3 changes: 3 additions & 0 deletions test/css-modules/src/components/Button.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
@reference "../theme.css";

.button {
color: #112233;
@apply bg-btn-bg;
}
3 changes: 3 additions & 0 deletions test/css-modules/src/theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@theme {
--color-btn-bg: #aabbcc;
}