feat: support filter projects via --project option#520
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 adds support for filtering test projects via the --project command-line option. Users can now specify which projects to run using exact names, wildcards, or exclusion patterns.
Key changes include:
- Added
filterProjectsutility function with support for wildcard and negation patterns - Updated CLI to accept the new
--projectoption - Enhanced project resolution to apply filtering and provide helpful error messages
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/utils/testFiles.ts | Added filterProjects function to filter projects by name patterns |
| packages/core/src/cli/init.ts | Integrated project filtering into project resolution with error handling |
| packages/core/src/cli/commands.ts | Added --project CLI option definition |
| packages/core/tests/utils/testFiles.test.ts | Added comprehensive tests for the filterProjects function |
| e2e/projects/filter.test.ts | Added end-to-end test for project filtering functionality |
| website/docs/*/guide/basic/test-filter.mdx | Added documentation for project filtering feature |
| website/docs/*/guide/basic/cli.mdx | Updated CLI documentation with new --project option |
| website/docs/*/config/test/projects.mdx | Added cross-reference to project filtering |
| website/docs/*/config/test/name.mdx | Enhanced documentation with examples and filtering context |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const escaped = (isNeg ? pattern.slice(1) : pattern) | ||
| .split('*') | ||
| .map((part) => part.replace(/[.+?^${}()|[\]\\]/g, '\\$&')) | ||
| .join('.*'); | ||
| return new RegExp(isNeg ? `^(?!${escaped})` : `^${escaped}$`); |
There was a problem hiding this comment.
The negation regex pattern ^(?!${escaped}) creates a negative lookahead that will match any string that doesn't start with the escaped pattern, but it doesn't anchor the end. This could lead to unexpected matches. It should be ^(?!${escaped}$).* to properly negate the entire pattern.
| const escaped = (isNeg ? pattern.slice(1) : pattern) | |
| .split('*') | |
| .map((part) => part.replace(/[.+?^${}()|[\]\\]/g, '\\$&')) | |
| .join('.*'); | |
| return new RegExp(isNeg ? `^(?!${escaped})` : `^${escaped}$`); | |
| return new RegExp(isNeg ? `^(?!${escaped}$).*` : `^${escaped}$`); |
| options: CommonOptions; | ||
| }): Promise<Project[]> { | ||
| if (!config.projects || !config.projects.length) { | ||
| if (!config.projects) { |
There was a problem hiding this comment.
The condition only checks for falsy values but doesn't handle empty arrays. An empty projects array should also return early. The condition should be if (!config.projects || !config.projects.length) to match the original logic.
| if (!config.projects) { | |
| if (!config.projects || !config.projects.length) { |
Summary
Support filter projects via
--projectoption.For example, to match projects whose name is
@test/aor@test/b:You can also use wildcards to match project names:
rstest --project '@test/*'You can exclude certain projects by negation:
rstest --project '!@test/a'Related Links
Checklist