feat(cli): support restart rstest when config file changed#477
Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull Request Overview
This PR implements automatic restart functionality for rstest when configuration files change during watch mode. When a config file is modified, the test runner will automatically restart to pick up the new configuration.
Key changes:
- Adds file watching for configuration files to trigger restarts
- Introduces a restart mechanism with proper cleanup handling
- Excludes config files from rspack watching to prevent conflicts
Reviewed Changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/watch/restart.test.ts | Adds test coverage for config file change restart functionality |
| packages/core/src/utils/watchFiles.ts | Utility for creating file watchers with glob pattern support |
| packages/core/src/core/restart.ts | Core restart logic with cleanup handling and file watching |
| packages/core/src/core/runTests.ts | Integrates restart mechanism into test runner |
| packages/core/src/core/rsbuild.ts | Passes config file path to rspack plugin |
| packages/core/src/core/plugins/entry.ts | Excludes config file from rspack watching |
| packages/core/src/core/index.ts | Updates createRstest to accept config file path |
| packages/core/src/core/context.ts | Adds config file path to context |
| packages/core/src/core/cliShortcuts.ts | Fixes event listener cleanup |
| packages/core/src/cli/commands.ts | Refactors command handling and adds restart watching |
| packages/core/package.json | Adds chokidar dependency |
| packages/core/LICENSE.md | Adds chokidar license |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| @@ -0,0 +1,43 @@ | |||
| import type { ChokidarOptions, FSWatcher } from 'chokidar'; | |||
|
|
|||
| export type WatchFilesResult = { | |||
There was a problem hiding this comment.
The WatchFilesResult type is defined but never used in this file. Consider removing it or using it as the return type for createChokidar function if that was the intention.
| }): Promise<boolean> => { | ||
| await beforeRestart({ filePath, clear }); | ||
|
|
||
| await runRest({ options, filters, command: 'watch' }); |
There was a problem hiding this comment.
The restart function calls runRest with hardcoded 'watch' command, but it should use the original command parameter passed to the function to maintain the correct command context.
| await runRest({ options, filters, command: 'watch' }); | |
| command, | |
| }: { | |
| options: CommonOptions; | |
| filters: string[]; | |
| filePath?: string; | |
| clear?: boolean; | |
| command: string; | |
| }): Promise<boolean> => { | |
| await beforeRestart({ filePath, clear }); | |
| await runRest({ options, filters, command }); |
| @@ -0,0 +1,113 @@ | |||
| import path from 'node:path'; | |||
| import type { ChokidarOptions } from 'chokidar'; | |||
| import { type CommonOptions, runRest } from '../cli/commands'; | |||
There was a problem hiding this comment.
Importing runRest from cli/commands creates a circular dependency risk since commands.ts imports from core modules. Consider moving runRest to a shared utility module.
| import { type CommonOptions, runRest } from '../cli/commands'; | |
| import type { CommonOptions } from '../cli/commands'; | |
| import { runRest } from '../cli/runRestUtil'; |
Summary
support restart rstest when config file changed.
Related Links
Checklist