Skip to content

Vitest 4/Vite 8 breaks vitest coverage #12994

@aarongoldenthal

Description

@aarongoldenthal

What versions & operating system are you using?

System:
OS: Windows 11 10.0.26200
CPU: (20) x64 Intel(R) Core(TM) Ultra 7 265F
Memory: 37.17 GB / 63.71 GB
Binaries:
Node: 24.14.0 - C:\Program Files\nodejs\node.EXE
npm: 11.9.0 - C:\Program Files\nodejs\npm.CMD
npmPackages:
@cloudflare/vitest-pool-workers: ^0.13.3 => 0.13.3
wrangler: ^4.76.0 => 4.76.0

also....

System:
OS: Linux 6.6 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (20) x64 Intel(R) Core(TM) Ultra 7 265F
Memory: 30.39 GB / 31.20 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
Binaries:
Node: 24.14.0 - /usr/local/bin/node
Yarn: 1.22.22 - /usr/local/bin/yarn
npm: 11.9.0 - /usr/local/bin/npm
npmPackages:
@cloudflare/vitest-pool-workers: ^0.13.3 => 0.13.3
wrangler: ^4.76.0 => 4.76.0

Please provide a link to a minimal reproduction

https://github.com/aarongoldenthal/wrangler-vite-v8-coverage-test

Describe the Bug

Running vitest with coverage (istanbul) throws the following error and executes no tests:

TypeError: template is not a function
 ❯ requireVisitor node_modules/@vitest/coverage-istanbul/dist/provider.js:1024:40
    1022|      LogicalExpression: entries(coverLogicalExpression)
    1023|  };
    1024|  const globalTemplateAlteredFunction = template(`
       |                                        ^
    1025|         var Function = (function(){}).constructor;
    1026|         var global = (new Function(GLOBAL_COVERAGE_SCOPE))();
 ❯ requireInstrumenter node_modules/@vitest/coverage-istanbul/dist/provider.js:1325:25
 ❯ requireSrc$1 node_modules/@vitest/coverage-istanbul/dist/provider.js:1495:23
 ❯ node_modules/@vitest/coverage-istanbul/dist/provider.js:1518:18
 ❯ VitestModuleEvaluator._runInlinedModule node_modules/vitest/dist/module-evaluator.js:206:4
 ❯ ServerModuleRunner.directRequest node_modules/vite/dist/node/module-runner.js:1243:59
 ❯ ServerModuleRunner.cachedRequest node_modules/vite/dist/node/module-runner.js:1150:73
 ❯ Object.getProvider node_modules/@vitest/coverage-istanbul/dist/index.js:31:40
 ❯ Vitest.initCoverageProvider node_modules/vitest/dist/chunks/cli-api.DuT9iuvY.js:13181:28
 ❯ node_modules/vitest/dist/chunks/cli-api.DuT9iuvY.js:13302:6

The same tests run nominally when running without coverage, or with coverage and removing the cloudflareTest plugin from the vitest config.

This appears to be related to #12984.

Please provide any relevant error logs

No response

Metadata

Metadata

Labels

vitestRelating to the Workers Vitest integration

Type

No fields configured for Bug.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions