-
Notifications
You must be signed in to change notification settings - Fork 6
test(v4): verify recompilation when theme file changes #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import fs from 'node:fs'; | ||
| import { dirname, join } 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)); | ||
| const themePath = join(__dirname, 'src/theme.css'); | ||
|
|
||
| test('should update styles when theme file changes', async ({ page }) => { | ||
| // Reset theme file | ||
| fs.writeFileSync( | ||
| themePath, | ||
| ` | ||
| @theme { | ||
| --color-dynamic: rgb(1, 2, 3); | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const rsbuild = await createRsbuild({ | ||
| cwd: __dirname, | ||
| rsbuildConfig: { | ||
| plugins: [pluginTailwindCSS()], | ||
| }, | ||
| }); | ||
|
|
||
| // First build | ||
| await rsbuild.build(); | ||
| let result = await rsbuild.preview(); | ||
|
|
||
| await page.goto(result.urls[0]); | ||
| let locator = page.locator('#dynamic'); | ||
| await expect(locator).toHaveCSS('background-color', 'rgb(1, 2, 3)'); | ||
| await result.server.close(); | ||
|
|
||
| // Modify theme file | ||
| fs.writeFileSync( | ||
| themePath, | ||
| ` | ||
| @theme { | ||
| --color-dynamic: rgb(4, 5, 6); | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| // Second build (reusing instance if possible, or creating new one if that's how tests work) | ||
| // The user asked to "Same createRsbuild instance" if possible. | ||
| // rsbuild.build() runs the build. | ||
| // We can run it again. | ||
| await rsbuild.build(); | ||
| result = await rsbuild.preview(); // New preview server | ||
|
|
||
| await page.goto(result.urls[0]); | ||
| locator = page.locator('#dynamic'); | ||
| await expect(locator).toHaveCSS('background-color', 'rgb(4, 5, 6)'); | ||
| await result.server.close(); | ||
| }); | ||
|
Comment on lines
+11
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test modifies a file on the file system ( You can use Playwright's Here's how you could implement this: // At the top of the file
const __dirname = dirname(fileURLToPath(import.meta.url));
const themePath = join(__dirname, 'src/theme.css');
const originalTheme = fs.readFileSync(themePath, 'utf-8');
test.afterEach(() => {
fs.writeFileSync(themePath, originalTheme);
});
// The test itself remains largely the same
test('should update styles when theme file changes', async ({ page }) => {
// ...
}); |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @import "tailwindcss"; | ||
| @reference "./theme.css"; | ||
|
|
||
| .dynamic-bg { | ||
| @apply bg-dynamic; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import './index.css'; | ||
|
|
||
| const div = document.createElement('div'); | ||
| div.id = 'dynamic'; | ||
| div.className = 'dynamic-bg'; | ||
| div.textContent = 'Dynamic'; | ||
| document.body.appendChild(div); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @theme { | ||
| --color-dynamic: rgb(4, 5, 6); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments appear to be development notes and can be removed to improve code clarity. The code itself is self-explanatory in that it's performing a second build.