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/debug/debugging.md.
close
  • English
  • Debugging

    Debug mode

    Enable debug mode with the DEBUG=rstest environment variable (comma-separated values containing rstest, rsbuild, builder, or * are accepted, case-insensitively):

    DEBUG=rstest pnpm test

    In debug mode, Rstest:

    • Writes temporary test build outputs to disk
    • Writes the resolved Rstest, Rsbuild, and Rspack configs to disk
    • Prints full error stack traces
    • Sets logger level to verbose and disables terminal screen clearing in watch mode

    Rstest config file

    In debug mode, Rstest writes the resolved configs to dist/.rstest-temp/.rsbuild/ (or <output.distPath.root>/.rsbuild/ if configured):

    • rstest.config.mjs: resolved Rstest config
    • rsbuild.config.mjs: generated Rsbuild config
    • rspack.config.<project>.mjs: generated Rspack config for each project (for example, rspack.config.rstest.mjs)

    For the default configuration, dist/.rstest-temp/.rsbuild/rstest.config.mjs looks similar to:

    dist/.rstest-temp/.rsbuild/rstest.config.mjs
    export default {
      root: '/path/to/project',
      name: 'rstest',
      include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'],
      // ...
    };

    See Configure Rstest for all configuration options.

    View test temporary outputs

    In debug mode or when dev.writeToDisk is enabled, Rstest writes compiled test bundles and source maps to dist/.rstest-temp (or output.distPath.root).

    Inspect bundle coverage

    If a Node.js test bundle is larger than expected, enable V8 coverage and set DEBUG=rstest:bundle-coverage to inspect which generated files the test runner received and which parts executed:

    DEBUG=rstest:bundle-coverage pnpm rstest run --coverage --coverage.provider v8

    Rstest writes .rstest/bundle-coverage-<timestamp>.json under the project root and prints its path. For each test file, assets records the byte size of each generated file, and rawV8 records V8 execution ranges before source-map remapping. Pass a test file filter to rstest run to inspect a single bundle.

    A dependency fully replaced by rs.mock() can still be bundled. Use output.externals to exclude it from the bundle.

    If your coding agent supports skills, install rstest-debugging and use the prompt below:

    npx skills add rstackjs/agent-skills --skill rstest-debugging
    For your Agent
    Investigate bundle coverage

    Copy this prompt and send it to your coding agent.

    Debugging test workers

    Rstest strips --inspect* and --debug-port flags passed to the host node process before spawning workers so worker ports do not collide. Running node --inspect ./node_modules/@rstest/core/bin/rstest.js only attaches the debugger to the main Rstest process.

    To attach a Node.js inspector to a test worker, pass --inspect-brk through pool.execArgv, limit execution to one worker with --pool.maxWorkers=1, and disable timeouts with --testTimeout=0:

    npx rstest run --pool.execArgv=--inspect-brk --pool.maxWorkers=1 --testTimeout=0

    When pool.execArgv includes --inspect* (or the host process itself is being inspected), Rstest automatically configures inline source maps (inline-nosources-source-map) and splits chunks to 1 MB so breakpoints resolve cleanly to your test source files.

    Debugging browser mode

    To inspect DOM state, console output, or browser DevTools during Browser Mode tests, run with --browser.headless=false to open a visible browser window:

    npx rstest run --browser.headless=false

    When browser.headless is true (the default in CI), Rstest saves a PNG screenshot under .rstest/screenshots/ on test failure unless browser.screenshotFailures is disabled.

    Debugging async leaks and memory

    • Pass --detectAsyncLeaks to fail test files that leave active async resources (such as unclosed timers) behind and report their creation stacks. See detectAsyncLeaks.
    • Pass --logHeapUsage to print V8 heapUsed after each test file and test case in Node.js pools. See logHeapUsage.

    Debugging in VS Code

    You can debug tests in VS Code using debugger statements or editor breakpoints by opening a JavaScript Debug Terminal and running your test command there.

    To debug the current test file with F5 or the Run and Debug panel, add a launch configuration to .vscode/launch.json:

    .vscode/launch.json
    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Debug Current Test File",
          "type": "node",
          "request": "launch",
          "program": "${workspaceFolder}/node_modules/@rstest/core/bin/rstest.js",
          "args": ["run", "${file}"],
          "console": "integratedTerminal",
          "internalConsoleOptions": "neverOpen",
          "skipFiles": ["<node_internals>/**"]
        }
      ]
    }