-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat: support test projects #420
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: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements support for multiple test projects in rstest by adding a projects
configuration option. This allows users to define and run tests across multiple project directories with different configurations, enabling better organization of test suites in monorepo structures.
Key changes include:
- Added
projects
configuration support to define multiple test directories - Updated core types to include project information throughout the testing pipeline
- Modified build and execution logic to handle multiple projects concurrently
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
rstest.config.ts | Updated configuration to use projects array instead of include patterns |
packages/core/src/types/*.ts | Added project property to core types (TestCase, TestSuite, TestResult, WorkerContext) |
packages/core/src/core/*.ts | Modified core functions to handle multiple projects and project-specific configurations |
packages/core/src/runtime/**/*.ts | Updated runtime components to track and pass project information |
packages/core/src/pool/*.ts | Enhanced pool management to support project-aware test execution |
packages/core/src/cli/*.ts | Refactored CLI to support project resolution and initialization |
packages/core/src/core/plugins/*.ts | Updated plugins to work with environment-specific configurations |
let testStart: number; | ||
const buildStart = Date.now(); | ||
const returns = await Promise.all( | ||
context.projects.map(async (p) => { | ||
const { entries, setupEntries, assetFiles, sourceMaps } = | ||
await getRsbuildStats(p.name); | ||
|
||
testStart ??= Date.now(); | ||
|
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.
The nullish coalescing assignment (??=) is used here, but testStart
is declared as let testStart: number;
which means it's undefined initially. This line should be moved outside the loop and executed once before the Promise.all to ensure consistent timing measurement.
let testStart: number; | |
const buildStart = Date.now(); | |
const returns = await Promise.all( | |
context.projects.map(async (p) => { | |
const { entries, setupEntries, assetFiles, sourceMaps } = | |
await getRsbuildStats(p.name); | |
testStart ??= Date.now(); | |
const testStart = Date.now(); | |
const buildStart = Date.now(); | |
const returns = await Promise.all( | |
context.projects.map(async (p) => { | |
const { entries, setupEntries, assetFiles, sourceMaps } = | |
await getRsbuildStats(p.name); |
Copilot uses AI. Check for mistakes.
}), | ||
); | ||
|
||
const buildTime = testStart! - buildStart; |
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.
Using the non-null assertion operator (!) on testStart
is unsafe. If no projects are processed, testStart
will remain undefined, causing a runtime error. Consider initializing testStart
to buildStart
or adding a proper null check.
Copilot uses AI. Check for mistakes.
|
||
const buildTime = testStart! - buildStart; | ||
|
||
const testTime = Date.now() - testStart!; |
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.
Same issue as above - using non-null assertion on testStart
is unsafe and could cause runtime errors if no projects are processed.
Copilot uses AI. Check for mistakes.
packages/core/src/cli/init.ts
Outdated
|
||
if (isDynamicPattern(projectStr)) { | ||
// TODO | ||
throw `Dynamic project pattern (${project}) is not supported. Please use static paths.`; |
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.
Throwing a string instead of an Error object is not a best practice. Consider using throw new Error()
for better error handling and stack traces.
Copilot uses AI. Check for mistakes.
throw `Project name "${config.name}" is already used. Please ensure all projects have unique names. | ||
Conflicting projects: | ||
${conflictProjects.map((p) => `- ${p.configFilePath || p.config.root}`).join('\n')} | ||
`; |
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.
Throwing a string instead of an Error object is not a best practice. Consider using throw new Error()
for better error handling and stack traces.
throw `Project name "${config.name}" is already used. Please ensure all projects have unique names. | |
Conflicting projects: | |
${conflictProjects.map((p) => `- ${p.configFilePath || p.config.root}`).join('\n')} | |
`; | |
throw new Error(`Project name "${config.name}" is already used. Please ensure all projects have unique names. | |
Conflicting projects: | |
${conflictProjects.map((p) => `- ${p.configFilePath || p.config.root}`).join('\n')}`); |
Copilot uses AI. Check for mistakes.
Can a unified rstest.config be configured for the each project? If a single project directory has an rstest.config, will it be merged? |
It seems that neither jest nor vitest will be merged by default, rstest will follow this behavior as well. |
Summary
Support define & run multiple test projects via
projects
configuration. This allows users to define and run tests across multiple project directories with different configurations, enabling better organization of test suites in monorepo structures.Related Links
Checklist