Skip to content

feat: support global setup files#772

Merged
9aoy merged 13 commits intomainfrom
globalSetup
Dec 16, 2025
Merged

feat: support global setup files#772
9aoy merged 13 commits intomainfrom
globalSetup

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Dec 16, 2025

Summary

The globalSetup option 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:

  • Starting and stopping databases
  • Initializing test services
  • Cleaning up resources after test runs
import { defineConfig } from '@rstest/core';

export default defineConfig({
  globalSetup: ['./global-setup.ts'],
  // or multiple files
  globalSetup: ['./setup-db.ts', './setup-server.ts'],
  // your other config...
});

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 16, 2025 03:38
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 16, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit f2c6e92
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/69411ffb39610f0008eb6198
😎 Deploy Preview https://deploy-preview-772--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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 globalSetup configuration option that accepts a string or array of file paths
  • Implemented two supported formats: named exports (setup/teardown functions) 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.

9aoy and others added 10 commits December 16, 2025 11:47
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@9aoy 9aoy merged commit 77db591 into main Dec 16, 2025
22 checks passed
@9aoy 9aoy deleted the globalSetup branch December 16, 2025 11:26
@9aoy 9aoy mentioned this pull request Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants