Skip to content

[Feature]: Supports control whether to collect external file coverage #1045

@9aoy

Description

@9aoy

What problem does this feature solve?

Rstest's current default behavior for coverage collection differs from both Jest and Vitest when it comes to files outside the project root (e.g., modules from sibling workspace packages in a monorepo).

Current behavior comparison:

Framework Default behavior External coverage control
Jest External files excluded No built-in option
Vitest External files excluded coverage.allowExternal (default false)
Rstest (current) External files included No option available

This default-on behavior is inconsistent with the ecosystem convention (both Jest and Vitest default to excluding external files). It can also produce noisy reports that include coverage for node_modules symlinked packages or unrelated workspace dependencies that the user doesn't intend to track.

Referenced from: #85 (comment)

What does the proposed API look like?

We should align with the Jest/Vitest default (exclude external files), and provide an option for users who need cross-package coverage in monorepo setups.

// rstest.config.ts
import { defineConfig } from '@rstest/core';

export default defineConfig({
  coverage: {
    enabled: true,
    // Allow coverage collection for files outside the project root
    allowExternal: true, // default: false
  },
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions