test(v4): verify recompilation when theme file changes#89
test(v4): verify recompilation when theme file changes#89colinaaa wants to merge 1 commit intorstackjs:v4from
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a crucial test to ensure the robustness of the build system's handling of external CSS theme files. By simulating modifications to a theme file and verifying that the subsequent build correctly applies these changes, it confirms that the styling pipeline is properly re-evaluating and updating styles, preventing stale visual outputs when theme definitions are altered. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds an important integration test to verify that changes to theme files trigger recompilation. The test implementation is sound, but I have a couple of suggestions to improve its robustness and clarity. Specifically, I recommend adding a cleanup mechanism to handle file system side effects and removing some leftover development comments. These changes will make the test more maintainable.
| 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(); | ||
| }); |
There was a problem hiding this comment.
This test modifies a file on the file system (theme.css), which is a side effect. If the test fails midway, the file could be left in a modified state, potentially affecting other tests or subsequent local runs. It's a good practice to ensure cleanup, even on failure.
You can use Playwright's test.afterEach hook to restore the file to its original state after the test completes, regardless of whether it passed or failed. This makes the test more robust and self-contained.
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 }) => {
// ...
});| // 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. |
This PR adds test cases to verify that changes to external theme files trigger a recompilation and update the styles correctly.