For AI agents: the complete documentation index is available at https://rstest.rs/llms.txt, the full documentation bundle is available at https://rstest.rs/llms-full.txt, and this page is available as Markdown at https://rstest.rs/guide/basic/projects.md.
close
  • English
  • Test projects

    Rstest lets you run multiple test projects in a single Rstest process, each with its own test configuration and environment.

    In an unfiltered, one-shot Node.js run without coverage, bail, or failure selection, a project can start running tests while another is still building. Runs with globalSetup or a reporter that needs the complete file selection in onTestRunStart wait for all projects to build before dispatching tests.

    In Node.js mode, Rstest limits concurrent environment builds to the number of CPUs available to the process by default. The pool.maxWorkers option controls how many workers execute test files.

    Use cases

    • Monorepo projects: Each sub-package or app has its own test setup or build config.
    • Mixed environments: Run Node.js, jsdom, and Browser Mode tests side by side.
    • Directory-specific settings: Apply distinct timeouts, setup files, or plugins to different test folders.

    Example

    Point projects at your workspace directories in the root config. Rstest treats each matching subdirectory as an independent project and loads its own rstest.config.ts if present:

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      projects: [
        // Treat each package directory as a project
        'packages/*',
      ],
    });

    Configuration

    When projects is defined, Rstest runs each matched project with its own config and merges all test results into a single report.

    • If projects is omitted, Rstest treats the current directory as a single project.
    • If projects is an empty array ([]), Rstest throws a No projects found error.
    • Every resolved project must have a unique name; duplicate names fail at startup with the list of conflicting projects.

    Configuration syntax

    Each entry in projects can be:

    • Directory path: Loads the project in that directory (and its config file, if present).
    • Configuration file path: Loads that specific config file as a project.
    • Glob pattern: Matches multiple project directories or config files.
    • Inline configuration object: Defines a project directly inside projects via defineInlineProject without creating a separate file.
    • Nested projects: Sub-project configs can declare their own projects array.
    rstest.config.ts
    import { defineConfig, defineInlineProject } from '@rstest/core';
    
    export default defineConfig({
      projects: [
        // Each package directory is a project
        'packages/*',
    
        // All projects under apps/ 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
        defineInlineProject({
          name: 'node',
          include: ['tests/node/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
        }),
        defineInlineProject({
          name: 'react',
          include: ['tests/react/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
          testEnvironment: 'jsdom',
        }),
      ],
    });

    Root configuration

    When the root config defines projects, the root directory itself is no longer treated as a test project—the root config only supplies projects and global configuration.

    To also run tests in the root directory, add an inline project for it inside projects:

    rstest.config.ts
    import { defineConfig, defineInlineProject } from '@rstest/core';
    
    export default defineConfig({
      projects: [
        defineInlineProject({
          name: 'root',
          include: ['<rootDir>/tests/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
        }),
        'packages/*',
      ],
    });

    Global configuration

    The following options are global and cannot be set per project. Configure them in the root config file, or override the options that expose a CLI flag (such as --reporters, --pool, --isolate, --coverage, --bail, or --teardownTimeout) from the command line:

    • reporters: Global reporters configuration.
    • pool: Worker pool configuration.
    • isolate: Environment isolation toggle.
    • coverage: Code coverage configuration.
    • bail: Failure threshold to stop the run.
    • teardownTimeout: Process exit timeout for rstest run.
    • resolveSnapshotPath: Snapshot file path resolver (config-only).
    • onConsoleLog: Console log filter (config-only).
    • output.distPath: Global output directory path (config-only).

    Project configuration

    Define project configuration

    A project config supports most Rstest options, excluding global configuration.

    Use defineInlineProject for inline objects inside any projects array (including nested projects), and defineProject for the top-level export of a project config file.

    • defineProject accepts an object or a sync/async factory function (() => ... / async () => ...), and can omit name (Rstest infers it following the name rules).
    • defineInlineProject requires name on every inline project item.
    packages/pkg-a/rstest.config.ts
    import { defineProject } from '@rstest/core';
    
    export default defineProject({
      name: 'pkg-a',
      include: ['tests/**/*.{test,spec}.{js,cjs,mjs,ts,tsx}'],
    });

    Share configuration

    Project configs do not inherit options from the root config—only projects and global configuration in the root config apply across the run.

    To share common settings across sub-projects, extract a shared config and combine it with mergeProjectConfig or mergeRstestConfig:

    packages/pkg-a/rstest.config.ts
    import { mergeProjectConfig } from '@rstest/core';
    import sharedConfig from '../shared/rstest.config';
    
    export default mergeProjectConfig(sharedConfig, {
      name: 'pkg-a',
    });

    CLI options (such as --testTimeout, --testEnvironment, or --globals) override matching fields across all projects.

    Nested projects

    Sub-project config files can define their own projects array instead of declaring every variant in the root config.

    For example, split packages/pkg-a into separate Node.js and jsdom projects:

    packages/pkg-a/rstest.config.ts
    import { defineProject, defineInlineProject } from '@rstest/core';
    
    export default defineProject({
      projects: [
        defineInlineProject({
          name: 'node',
          include: ['tests/node/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
        }),
        defineInlineProject({
          name: 'react',
          include: ['tests/react/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
          testEnvironment: 'jsdom',
        }),
      ],
    });

    Projects in browser mode

    Each Browser Mode project compiles and runs with its own build configuration, so projects with different stacks or plugins can run in the same Rstest process.

    Currently 'playwright' is the only supported provider. Within a run, you can target different browsers across projects (via browser.instances), open multiple headed debug windows or mix headed and headless instances in both run and watch, or mix Browser Mode projects with testEnvironment: 'node' or 'jsdom' projects, subject to these constraints:

    • Unique reported project names: Multi-browser projects report as <project> (<browser>), which must not collide with another project's name; see Multi-browser reporting.
    • V8 coverage requires Chromium: When coverage.provider is 'v8', every selected browser must be Chromium; see Launch rules.
    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    
    export default defineConfig({
      projects: ['./project-a/rstest.config.ts', './project-b/rstest.config.ts'],
    });
    project-a/rstest.config.ts
    import { pluginReact } from '@rsbuild/plugin-react';
    import { defineProject } from '@rstest/core';
    
    export default defineProject({
      name: 'project-a',
      plugins: [pluginReact()],
      include: ['tests/**/*.test.tsx'],
      browser: {
        enabled: true,
        provider: 'playwright',
        instances: [{ browserName: 'chromium' }],
      },
    });
    project-b/rstest.config.ts
    import { defineProject } from '@rstest/core';
    
    export default defineProject({
      name: 'project-b',
      include: ['tests/**/*.test.ts'],
      browser: {
        enabled: true,
        provider: 'playwright',
        instances: [{ browserName: 'firefox', headless: true }],
      },
    });

    Inspect configuration

    To inspect the final resolved configuration for each project, enable debug mode with DEBUG=rstest. Rstest writes the resolved Rstest and Rsbuild configs to the output directory.

    Filtering projects

    Use --project to run specific projects by name or glob pattern, or pass file filters to select files across projects. See Filtering tests for details.