Skip to content

Vitest@4 timer duration not stopping in watch mode and with type checking enabled #8841

@webdevbynight

Description

@webdevbynight

Describe the bug

I have Vitest configured like this to enable type checking:

import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    silent: true,
    typecheck: {
      enabled: true,
      tsconfig: "./tsconfig.test.json",
      include: ["**/test/*.test.ts"],
    },
  },
});

The TS config for .test.ts files is the following:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "noEmit": true,
    "types": ["node", "vitest/globals"]
  },
  "include": ["packages/*/test/**/*", "packages/*/src/**/*"],
  "exclude": ["node_modules", "**/dist"]
}

The basic tsconfig.json file is the following:

{
  "compilerOptions": {
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "ES2023",
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,
    "verbatimModuleSyntax": true,
    "erasableSyntaxOnly": true,
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,
    "module": "NodeNext",
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true
  },
  "exclude": ["**/dist", "**/bin/**/*", "**/test", "**/vitest.config.*", "node_modules"]
}

When running Vitest in watch mode, the timer displayed in the “Duration” line of the CLI output does not stop once the tests are run, particularly when any test files are changed.

Such a bug did not happen in Vitest 3 with the settings above.

Such a bug does not happen in Vitest 4 when type checking is disabled (no typecheck property provided) or when Vitest is not run in watch mode.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-fwawgwnx?file=vite.config.ts,tsconfig.test.json,test%2Fsuite.test.ts,test%2Fbasic.test.ts&initialPath=__vitest__/

System Info

System:
    OS: macOS 15.7.1
    CPU: (8) arm64 Apple M2
    Memory: 135.48 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.21.0 - /Users/webdevbynight/.nvm/versions/node/v22.21.0/bin/node
    npm: 10.9.4 - /Users/webdevbynight/.nvm/versions/node/v22.21.0/bin/npm
    pnpm: 10.19.0 - /Users/webdevbynight/Library/pnpm/pnpm
    bun: 1.1.38 - /Users/webdevbynight/.bun/bin/bun
  Browsers:
    Chrome: 141.0.7390.123
    Firefox: 144.0
    Safari: 26.0.1
  npmPackages:
    vitest: 4.0.3 => 4.0.3

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: typecheckIssues and PRs related to typechecking featurep3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions