Skip to content

Vitest unit test coverage fails with 14 or more basic tests (13 or less work fine) #31827

@wein2011

Description

@wein2011

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

The issue was identified when running a large test suite against @angular/build: 21.0.0-rc.3.

When you add 13 tests everything works fine. However, when you add the 14th test, the tests run and pass, but the coverage reporter will report the following issue at the top level:

Unable to lookup source: ...\coverage-reporter (EISDIR: illegal operation on a directory, read)
Error: Unable to lookup source: ...\coverage-reporter (EISDIR: illegal operation on a directory, read)
    at Context.defaultSourceLookup [as sourceFinder] (...\coverage-reporter\node_modules\istanbul-lib-report\lib\context.js:17:15)
    at Context.getSource (...\coverage-reporter\node_modules\istanbul-lib-report\lib\context.js:71:21)
    at annotateSourceCode (...\coverage-reporter\node_modules\istanbul-reports\lib\html\annotator.js:249:40)
    at HtmlReport.onDetail (...\coverage-reporter\node_modules\istanbul-reports\lib\html\index.js:414:33)
    at Visitor.value (...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:38:38)
    at ReportNode.visit (...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:88:21)
    at ...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:92:19
    at Array.forEach ()
    at ReportNode.visit (...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:91:28)
    at ...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:92:19

This also causes all other test files in the report to have extra path information in the file name.

Minimal Reproduction

The attached zip file includes a minimal reproduction on Windows 11.

  1. Unzip
  2. Run: npm install
  3. Run: ng test --browsers ChromiumHeadless
  4. Open coverage\coverage-reporter\index.html

You will notice two issues:

  1. The top level directory is not app, but the directory above coverage-reporter
  2. When you click on the first line and then coverage-reporter, you will see the above error message.

Now delete any one of the test files (e.g. test4.spec.ts) and rerun: ng test --browsers ChromiumHeadless. The index.html file will now be correct.

coverage-reporter.zip

Exception or Error

Unable to lookup source: ...\coverage-reporter (EISDIR: illegal operation on a directory, read)
Error: Unable to lookup source: ...\coverage-reporter (EISDIR: illegal operation on a directory, read)
    at Context.defaultSourceLookup [as sourceFinder] (...\coverage-reporter\node_modules\istanbul-lib-report\lib\context.js:17:15)
    at Context.getSource (...\coverage-reporter\node_modules\istanbul-lib-report\lib\context.js:71:21)
    at annotateSourceCode (...\coverage-reporter\node_modules\istanbul-reports\lib\html\annotator.js:249:40)
    at HtmlReport.onDetail (...\coverage-reporter\node_modules\istanbul-reports\lib\html\index.js:414:33)
    at Visitor.value (...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:38:38)
    at ReportNode.visit (...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:88:21)
    at ...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:92:19
    at Array.forEach ()
    at ReportNode.visit (...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:91:28)
    at ...\coverage-reporter\node_modules\istanbul-lib-report\lib\tree.js:92:19

Your Environment

Angular CLI       : 21.0.0-rc.4
Angular           : 21.0.0-rc.2
Node.js           : 22.18.0
Package Manager   : npm 10.9.3
Operating System  : win32 x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.0.0-rc.4       │ ^21.0.0-rc.3      │
│ @angular/cli              │ 21.0.0-rc.4       │ ^21.0.0-rc.3      │
│ @angular/common           │ 21.0.0-rc.2       │ ^21.0.0-rc.2      │
│ @angular/compiler         │ 21.0.0-rc.2       │ ^21.0.0-rc.2      │
│ @angular/compiler-cli     │ 21.0.0-rc.2       │ ^21.0.0-rc.2      │
│ @angular/core             │ 21.0.0-rc.2       │ ^21.0.0-rc.2      │
│ @angular/forms            │ 21.0.0-rc.2       │ ^21.0.0-rc.2      │
│ @angular/platform-browser │ 21.0.0-rc.2       │ ^21.0.0-rc.2      │
│ @angular/router           │ 21.0.0-rc.2       │ ^21.0.0-rc.2      │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
│ vitest                    │ 4.0.9             │ ^4.0.9            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions