-
-
Notifications
You must be signed in to change notification settings - Fork 13
docs: add projects guide
#724
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1173dfb
docs: add projects guide
9aoy fd2b09c
fix: lint
9aoy 701e576
Update website/docs/en/guide/basic/projects.mdx
9aoy 4f14f6d
Update website/docs/zh/guide/basic/projects.mdx
9aoy d177d26
Update website/docs/en/guide/basic/projects.mdx
9aoy fca74fc
fix: checkDeadLinks
9aoy 50321b1
fix: update rspress config
9aoy 0da2320
fix: update
9aoy 3f4bb36
docs: update link
9aoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| ["cli", "configure-rstest", "test-filter", "vscode-extension", "upgrade-rstest"] | ||
| [ | ||
| "cli", | ||
| "configure-rstest", | ||
| "test-filter", | ||
| "projects", | ||
| "vscode-extension", | ||
| "upgrade-rstest" | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| # Test projects | ||
|
|
||
| Rstest supports running multiple test projects simultaneously within a single Rstest process. These projects can have different test configurations and test environments. | ||
|
|
||
| ## Use cases | ||
|
|
||
| - **Monorepo projects**: When your codebase contains multiple sub-packages or modules, each sub-project might have different test configuration requirements. | ||
| - **Different test environments**: Different sub-projects (or even the same sub-project) might need to run in different environments (e.g., Node environment and browser environment). | ||
| - **File-specific testing**: You can specify different test or build configurations for specific test files/directories. | ||
|
|
||
| ## Example | ||
|
|
||
| Define each sub-project in a monorepo as a project through the [projects](/config/test/projects) field, where each sub-project has its own test configuration. | ||
|
|
||
| Rstest will automatically recognize each subdirectory under the `packages` directory as an independent test project and run tests according to the [rstest.config.ts](/guide/basic/configure-rstest#configuration-files) file (if present) in the subdirectory. | ||
|
|
||
| ```ts name='rstest.config.ts' | ||
| import { defineConfig } from '@rstest/core'; | ||
|
|
||
| export default defineConfig({ | ||
| projects: [ | ||
| // A monorepo: each package directory is a project | ||
| 'packages/*', | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| ## Configuration description | ||
|
|
||
| You can define multiple test projects through the [projects](/config/test/projects) field. Rstest will run the corresponding tests according to the configurations defined by each project, and all test results will be merged and displayed. | ||
|
|
||
| If there is no `projects` field, `rstest` will treat the current directory as a single project. | ||
|
|
||
| ### Configuration syntax | ||
|
|
||
| The `projects` field supports the following configuration methods: | ||
|
|
||
| - **Directory path**: Specify a directory, and Rstest will automatically recognize all subdirectories under that directory as projects. | ||
| - **Configuration file path**: Specify a configuration file path, and Rstest will run tests according to that file's configuration. | ||
| - **Glob pattern**: Use glob patterns to match multiple directories or files, and Rstest will use the matching results as projects. | ||
| - **Inline configuration object**: Directly define project configuration objects in the `projects` field. This allows you to define multiple test projects within a single project without creating separate configuration files for each test project. | ||
| - **Nested projects**: Define projects nested within the rstest config of sub-projects. | ||
|
|
||
| ```ts name='rstest.config.ts' | ||
| import { defineConfig } from '@rstest/core'; | ||
|
|
||
| export default defineConfig({ | ||
| projects: [ | ||
| // A monorepo: each package directory is a project | ||
| 'packages/*', | ||
|
|
||
| // All projects under the apps directory that provide an rstest config file | ||
| 'apps/**/rstest.config.ts', | ||
|
|
||
| // A specific project directory | ||
| '<rootDir>/services/auth', | ||
|
|
||
| // A specific project's config file | ||
| './projects/web/rstest.config.ts', | ||
|
|
||
| // inline project configs | ||
| { | ||
| name: 'node', | ||
| include: ['tests/node/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'], | ||
| }, | ||
| { | ||
| name: 'react', | ||
| include: ['tests/react/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'], | ||
| testEnvironment: 'jsdom', | ||
| }, | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| ### Root configuration | ||
|
|
||
| When the `projects` field exists in the root directory's rstest config file, Rstest will not treat it as a test project. In this case, the root directory's rstest.config file is only used to define `projects` and [global configuration](#global-configuration). | ||
|
|
||
| If you want to treat the root directory as a project as well, you can define the test configuration for the root directory in `projects`. | ||
|
|
||
| ```ts name='rstest.config.ts' | ||
| import { defineConfig } from '@rstest/core'; | ||
|
|
||
| export default defineConfig({ | ||
| projects: [ | ||
| { | ||
| name: 'root', | ||
| include: ['<rootDir>/tests/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'], | ||
| }, | ||
| 'packages/*', | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| #### Global configuration | ||
|
|
||
| The following configurations are global configurations and are invalid when configured in projects. If you need to modify global configuration, you need to configure it in the root project's rstest config or override it through CLI options. | ||
|
|
||
| - `reporters`: Global reporters configuration. | ||
| - `pool`: Global pool configuration. | ||
| - `isolate`: Global isolate configuration. | ||
| - `coverage`: Global coverage configuration. | ||
| - `bail`: Global bail configuration. | ||
|
|
||
| ### Project configuration | ||
|
|
||
| Project configuration does not inherit the configuration from the root directory. Only the `projects` field and [global configuration](#global-configuration) in the root directory are effective. | ||
|
|
||
| If there are reusable configuration items between your sub-projects, you can extract shared configurations and introduce them in sub-projects respectively: | ||
|
|
||
| ```ts title='packages/pkg-a/rstest.config.ts' | ||
| import { defineConfig, mergeRstestConfig } from '@rstest/core'; | ||
| import sharedConfig from '../shared/rstest.config'; | ||
|
|
||
| export default mergeRstestConfig(sharedConfig, { | ||
| name: 'pkg-a', | ||
| }); | ||
| ``` | ||
|
|
||
| You can override all project configurations through [CLI options](/guide/basic/cli#cli-options). | ||
|
|
||
| ### Nested projects | ||
|
|
||
| Rstest supports defining nested projects in sub-project rstest config files. This allows you to define more test projects in sub-projects without defining all projects in the root project. | ||
|
|
||
| This is especially useful when your sub-projects need to support multiple test environments or multiple configurations. | ||
|
|
||
| For example, define Node.js and browser test environments for `packages/pkg-a`: | ||
|
|
||
| ```ts title='packages/pkg-a/rstest.config.ts' | ||
| import { defineConfig } from '@rstest/core'; | ||
|
|
||
| export default defineConfig({ | ||
| projects: [ | ||
| { | ||
| name: 'node', | ||
| include: ['tests/node/**/*.{test,spec}.?(c|m)[jt]s?(x)'], | ||
| }, | ||
| { | ||
| name: 'react', | ||
| include: ['tests/react/**/*.{test,spec}.?(c|m)[jt]s?(x)'], | ||
| testEnvironment: 'jsdom', | ||
| }, | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| ### Inspect configuration | ||
|
|
||
| If you want to view the final effective configuration of Rstest, you can enable [debug mode](/guide/advanced/debugging#enabling-debug-mode) through the `DEBUG=rstest` environment variable. Rstest will write the final effective Rstest configuration and build configuration to the output directory. | ||
|
|
||
| ## Filtering projects | ||
|
|
||
| You can filter projects through the [--project](/guide/basic/test-filter#filtering-by-project-name) CLI option, or you can filter specific files under projects by directly filtering file names or file paths. | ||
9aoy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For more information, please refer to the [Test Filtering](/guide/basic/test-filter) chapter. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,8 @@ | ||
| ["cli", "configure-rstest", "test-filter", "vscode-extension", "upgrade-rstest"] | ||
| [ | ||
| "cli", | ||
| "configure-rstest", | ||
| "test-filter", | ||
| "projects", | ||
| "vscode-extension", | ||
| "upgrade-rstest" | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.