Conversation
✅ Deploy Preview for rstest-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds support for global setup files in Rstest, enabling developers to run setup and teardown code once before all tests and after all tests complete. This is useful for managing global resources like databases, test servers, and other services that should be initialized once per test run rather than per test file.
Key Changes
- Added
globalSetupconfiguration option that accepts a string or array of file paths - Implemented two supported formats: named exports (
setup/teardownfunctions) or default export returning a teardown function - Global teardown callbacks execute in reverse order (LIFO) with error handling
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/en/config/test/global-setup.mdx | Added English documentation for globalSetup feature |
| website/docs/zh/config/test/global-setup.mdx | Added Chinese documentation for globalSetup feature |
| website/docs/en/config/test/_meta.json | Added global-setup to English docs navigation |
| website/docs/zh/config/test/_meta.json | Added global-setup to Chinese docs navigation |
| website/theme/components/ConfigOverview.tsx | Added globalSetup to config overview |
| packages/core/src/types/config.ts | Added globalSetup type definitions to config interfaces |
| packages/core/src/types/core.ts | Added _globalSetups flag to ProjectContext to track execution state |
| packages/core/src/types/reporter.ts | Added unhandledErrors parameter to reporter interface |
| packages/core/src/config.ts | Implemented globalSetup config normalization and path resolution |
| packages/core/src/core/globalSetup.ts | Core implementation of global setup/teardown logic |
| packages/core/src/core/runTests.ts | Integrated global setup execution before tests and teardown after tests |
| packages/core/src/core/listTests.ts | Added global setup support to test listing functionality |
| packages/core/src/core/rstest.ts | Initialized _globalSetups flag in project contexts |
| packages/core/src/core/rsbuild.ts | Updated build configuration to include global setup files |
| packages/core/src/core/plugins/entry.ts | Added global setup files to entry watch plugin |
| packages/core/src/pool/index.ts | Modified env handling to capture process.env changes from globalSetup |
| packages/core/src/reporter/index.ts | Updated reporter to handle unhandled errors from global setup |
| packages/core/src/reporter/summary.ts | Added error logging for global setup failures |
| packages/core/src/utils/error.ts | Added isRelativePath utility and improved source path resolution |
| packages/core/src/runtime/worker/index.ts | Added teardown comment for clarity |
| packages/core/tests/config.test.ts | Added tests for globalSetup config handling |
| packages/core/tests/snapshots/config.test.ts.snap | Updated config test snapshots |
| packages/core/tests/core/snapshots/rstest.test.ts.snap | Updated rstest context snapshots |
| e2e/globalSetup/index.test.ts | E2E tests for basic and error scenarios |
| e2e/globalSetup/fixtures/basic/* | Test fixtures for basic global setup functionality |
| e2e/globalSetup/fixtures/error/* | Test fixtures for global setup error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The
globalSetupoption in Rstest allows you to run setup and teardown code that executes once before all tests and after all tests complete. This is useful for:Related Links
Checklist