Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
5fb08c4
feat!: use module-runner instead of vite-node
sheremet-va Jun 21, 2025
a1a6b33
Merge branch 'main' of github.com:vitest-dev/vitest into feat/use-mod…
sheremet-va Jun 22, 2025
16a5081
chore: rename
sheremet-va Jun 22, 2025
1b537ee
refactor: move files around
sheremet-va Jun 22, 2025
74e62b7
refactor: cleanup
sheremet-va Jun 22, 2025
049a2a5
fix: make sure /@vite/client works
sheremet-va Jun 22, 2025
a4d0b4e
fix: stub via externalization
sheremet-va Jun 22, 2025
bd3adf9
chore: cleanup
sheremet-va Jun 22, 2025
2545faa
fix: support source maps and CJS syntax
sheremet-va Jun 22, 2025
7e52121
fix: support in-source tests
sheremet-va Jun 22, 2025
3953e97
refactor: always run using vm module
sheremet-va Jun 22, 2025
ae62dc3
fix: always apply module runner transform
sheremet-va Jun 22, 2025
99fcdc5
chore: cleanup
sheremet-va Jun 22, 2025
3262f45
chore: cleanup
sheremet-va Jun 22, 2025
5af5d7a
refactor: rename plugin
sheremet-va Jun 23, 2025
7d38865
chore: suffering
sheremet-va Jun 24, 2025
89aa583
Merge branch 'feat/use-module-runner' of github.com:sheremet-va/vites…
sheremet-va Jun 30, 2025
55b1c95
chore: rename __vitest_executor to moduleRunner
sheremet-va Jun 30, 2025
79d725b
chore: cleanup
sheremet-va Jun 30, 2025
5995115
fix: add vitest packages to external
sheremet-va Jun 30, 2025
6d230ae
chore: remove vite-node references from vitest
sheremet-va Jun 30, 2025
0ea260d
fix: remove vitenode completely from vitest package
sheremet-va Jun 30, 2025
79b56a1
refactor: cleanup
sheremet-va Jun 30, 2025
af1e142
chore: replace executeId with import everywhere
sheremet-va Jun 30, 2025
a8bc33d
refactor: use environment in the v8 coverage provider instead of the …
sheremet-va Jul 1, 2025
247d39a
fix: allow virtual modules
sheremet-va Jul 1, 2025
2e181d4
fix: externalize even in "client" consumer
sheremet-va Jul 1, 2025
364c50c
feat: return externalisation logic
sheremet-va Jul 2, 2025
d19de34
test: fix dynamicImportSettled
sheremet-va Jul 2, 2025
33c4223
fix: don't reuse id
sheremet-va Jul 2, 2025
d1c18c9
fix: correctly provide vm options
sheremet-va Jul 2, 2025
c8101db
chore: check for @fs
sheremet-va Jul 3, 2025
52f4a92
fix: always externalize vitest import
sheremet-va Jul 3, 2025
1ff8ab0
Merge branch 'main' of github.com:vitest-dev/vitest into feat/use-mod…
sheremet-va Jul 3, 2025
217f919
chore: undog comment
sheremet-va Jul 3, 2025
ffdbedf
chore: lint
sheremet-va Jul 3, 2025
86c16ee
Merge branch 'main' of github.com:vitest-dev/vitest into feat/use-mod…
sheremet-va Jul 4, 2025
989e4d0
fix: add missing moduleExecutionInfo
sheremet-va Jul 4, 2025
2cbfff3
fix: disable vite externalization
sheremet-va Jul 4, 2025
f37946e
chore: testing
sheremet-va Jul 10, 2025
f5d02f0
Merge branch 'main' of github.com:vitest-dev/vitest into feat/use-mod…
sheremet-va Jul 15, 2025
34859d5
chore: reuse the test evaluator
sheremet-va Jul 15, 2025
3b258ca
refactor: make serverModuleRunner
sheremet-va Jul 15, 2025
2529166
fix: create a separate environment for vm tests
sheremet-va Jul 15, 2025
380235c
chore: cleanup
sheremet-va Jul 15, 2025
bad7358
chore: mark as TODO for now
sheremet-va Jul 15, 2025
038070f
test: fix check
sheremet-va Jul 16, 2025
efd87f1
fix: normalize cached vitest path on windows
sheremet-va Jul 16, 2025
05b79c7
fix: externalize builtin modules
sheremet-va Jul 16, 2025
1c3192f
fix: inline code ourselves
sheremet-va Jul 16, 2025
fcecf8b
fix: actually use the code
sheremet-va Jul 16, 2025
b5adefd
fix: resolve dynamic import
sheremet-va Jul 18, 2025
38c051d
fix: create require only with absolute path
sheremet-va Jul 18, 2025
919f0c2
fix: introduce VITEST_MODULE_DIRECTORIES
sheremet-va Jul 18, 2025
1a98977
test: fix assertion
sheremet-va Jul 18, 2025
2e73790
chore: skip test
sheremet-va Jul 18, 2025
32e7f69
fix: reintroduce transform time
sheremet-va Jul 18, 2025
5c7ce8e
fix: import from vite/module-runner to avoid pulling in node types
sheremet-va Jul 18, 2025
0bb6e38
chore: lint
sheremet-va Jul 21, 2025
eb26cf5
fix: use correct exports object
sheremet-va Jul 21, 2025
406860c
fix: properly retrieve source map on Windows
sheremet-va Jul 21, 2025
b4c20bc
Merge branch 'main' of github.com:vitest-dev/vitest into feat/use-mod…
sheremet-va Jul 21, 2025
cefdcb8
refactor: undo source map fix
sheremet-va Jul 21, 2025
c534db6
fix: load environment via url
sheremet-va Jul 21, 2025
87d5744
fix: return support for typescript environments
sheremet-va Jul 21, 2025
8c2f9f8
fix: ignore rolldown module runner url
sheremet-va Jul 21, 2025
407ce73
fix(windows): normalize absolute paths
sheremet-va Jul 21, 2025
fdb1e15
fix(windows): properly resolve path
sheremet-va Jul 21, 2025
22878f2
fix: wrap external id
sheremet-va Jul 21, 2025
4c2e2d9
fix: correct filename check for import.meta.vitest on windows
sheremet-va Jul 21, 2025
48a641c
fix: use proper filename in debug info
sheremet-va Jul 21, 2025
efab68e
fix: conver it do import url
sheremet-va Jul 21, 2025
cc77e36
chore: fix ? query
sheremet-va Jul 21, 2025
47c1fd2
chore: cleanup
sheremet-va Jul 21, 2025
b08246e
fix(vm): remove unused checks
sheremet-va Jul 22, 2025
e6dee84
refactor: improve types
sheremet-va Jul 22, 2025
082b41d
docs: mention migration to module runner
sheremet-va Jul 22, 2025
7139cb6
Merge branch 'main' of github.com:vitest-dev/vitest into feat/use-mod…
sheremet-va Jul 22, 2025
4a80230
fix: don't print runnerError, update validation check
sheremet-va Jul 23, 2025
1a57f79
fix: override correct `optimizeDeps` key
sheremet-va Jul 23, 2025
2febb1f
fix: properly update dynamic env access if not running in Vitest
sheremet-va Jul 25, 2025
53e4e10
Merge branch 'main' of github.com:vitest-dev/vitest into feat/use-mod…
sheremet-va Jul 25, 2025
daf0a28
chore: type fix
sheremet-va Jul 25, 2025
60794d6
fix(coverage): ignore css files
sheremet-va Jul 25, 2025
9b0be2f
fix(coverage): ignore transforms made by `vitest:meta-env-replacer`
AriPerkkio Jul 25, 2025
88d21f4
fix: inherit external and noExternal
sheremet-va Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ strict-peer-dependencies=false
provenance=true
shell-emulator=true
registry=https://registry.npmjs.org/
VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/
VITEST_MODULE_DIRECTORIES=/node_modules/,/packages/
6 changes: 3 additions & 3 deletions docs/advanced/runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ export default CustomRunner
```

::: warning
Vitest also injects an instance of `ViteNodeRunner` as `__vitest_executor` property. You can use it to process files in `importFile` method (this is default behavior of `TestRunner` and `BenchmarkRunner`).
Vitest also injects an instance of `ModuleRunner` from `vite/module-runner` as `moduleRunner` property. You can use it to process files in `importFile` method (this is default behavior of `TestRunner` and `BenchmarkRunner`).

`ViteNodeRunner` exposes `executeId` method, which is used to import test files in a Vite-friendly environment. Meaning, it will resolve imports and transform file content at runtime so that Node can understand it:
`ModuleRunner` exposes `import` method, which is used to import test files in a Vite-friendly environment. Meaning, it will resolve imports and transform file content at runtime so that Node can understand it:

```ts
export default class Runner {
async importFile(filepath: string) {
await this.__vitest_executor.executeId(filepath)
await this.moduleRunner.import(filepath)
}
}
```
Expand Down
38 changes: 8 additions & 30 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Handling for dependencies resolution.

#### deps.optimizer {#deps-optimizer}

- **Type:** `{ ssr?, web? }`
- **Type:** `{ ssr?, client? }`
- **See also:** [Dep Optimization Options](https://vitejs.dev/config/dep-optimization-options.html)

Enable dependency optimization. If you have a lot of tests, this might improve their performance.
Expand All @@ -245,7 +245,7 @@ When Vitest encounters the external library listed in `include`, it will be bund
- Your `alias` configuration is now respected inside bundled packages
- Code in your tests is running closer to how it's running in the browser

Be aware that only packages in `deps.optimizer?.[mode].include` option are bundled (some plugins populate this automatically, like Svelte). You can read more about available options in [Vite](https://vitejs.dev/config/dep-optimization-options.html) docs (Vitest doesn't support `disable` and `noDiscovery` options). By default, Vitest uses `optimizer.web` for `jsdom` and `happy-dom` environments, and `optimizer.ssr` for `node` and `edge` environments, but it is configurable by [`transformMode`](#testtransformmode).
Be aware that only packages in `deps.optimizer?.[mode].include` option are bundled (some plugins populate this automatically, like Svelte). You can read more about available options in [Vite](https://vitejs.dev/config/dep-optimization-options.html) docs (Vitest doesn't support `disable` and `noDiscovery` options). By default, Vitest uses `optimizer.client` for `jsdom` and `happy-dom` environments, and `optimizer.ssr` for `node` and `edge` environments.

This options also inherits your `optimizeDeps` configuration (for web Vitest will extend `optimizeDeps`, for ssr - `ssr.optimizeDeps`). If you redefine `include`/`exclude` option in `deps.optimizer` it will extend your `optimizeDeps` when running tests. Vitest automatically removes the same options from `include`, if they are listed in `exclude`.

Expand All @@ -260,15 +260,15 @@ You will not be able to edit your `node_modules` code for debugging, since the c

Enable dependency optimization.

#### deps.web {#deps-web}
#### deps.client {#deps-client}

- **Type:** `{ transformAssets?, ... }`

Options that are applied to external files when transform mode is set to `web`. By default, `jsdom` and `happy-dom` use `web` mode, while `node` and `edge` environments use `ssr` transform mode, so these options will have no affect on files inside those environments.
Options that are applied to external files when the environment is set to `client`. By default, `jsdom` and `happy-dom` use `client` environment, while `node` and `edge` environments use `ssr`, so these options will have no affect on files inside those environments.

Usually, files inside `node_modules` are externalized, but these options also affect files in [`server.deps.external`](#server-deps-external).

#### deps.web.transformAssets
#### deps.client.transformAssets

- **Type:** `boolean`
- **Default:** `true`
Expand All @@ -281,7 +281,7 @@ This module will have a default export equal to the path to the asset, if no que
At the moment, this option only works with [`vmThreads`](#vmthreads) and [`vmForks`](#vmforks) pools.
:::

#### deps.web.transformCss
#### deps.client.transformCss

- **Type:** `boolean`
- **Default:** `true`
Expand All @@ -294,7 +294,7 @@ If CSS files are disabled with [`css`](#css) options, this option will just sile
At the moment, this option only works with [`vmThreads`](#vmthreads) and [`vmForks`](#vmforks) pools.
:::

#### deps.web.transformGlobPattern
#### deps.client.transformGlobPattern

- **Type:** `RegExp | RegExp[]`
- **Default:** `[]`
Expand Down Expand Up @@ -560,7 +560,7 @@ import type { Environment } from 'vitest'

export default <Environment>{
name: 'custom',
transformMode: 'ssr',
viteEnvironment: 'ssr',
setup() {
// custom setup
return {
Expand Down Expand Up @@ -1676,28 +1676,6 @@ Will call [`vi.unstubAllEnvs`](/api/vi#vi-unstuballenvs) before each test.

Will call [`vi.unstubAllGlobals`](/api/vi#vi-unstuballglobals) before each test.

### testTransformMode {#testtransformmode}

- **Type:** `{ web?, ssr? }`

Determine the transform method for all modules imported inside a test that matches the glob pattern. By default, relies on the environment. For example, tests with JSDOM environment will process all files with `ssr: false` flag and tests with Node environment process all modules with `ssr: true`.

#### testTransformMode.ssr

- **Type:** `string[]`
- **Default:** `[]`

Use SSR transform pipeline for all modules inside specified tests.<br>
Vite plugins will receive `ssr: true` flag when processing those files.

#### testTransformMode&#46;web

- **Type:** `string[]`
- **Default:** `[]`

First do a normal transform pipeline (targeting browser), then do a SSR rewrite to run the code in Node.<br>
Vite plugins will receive `ssr: false` flag when processing those files.

### snapshotFormat<NonProjectOption />

- **Type:** `PrettyFormatOptions`
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type { Environment } from 'vitest/environments'

export default <Environment>{
name: 'custom',
transformMode: 'ssr',
viteEnvironment: 'ssr',
// optional - only if you support "experimental-vm" pool
async setupVM() {
const vm = await import('node:vm')
Expand All @@ -74,7 +74,7 @@ export default <Environment>{
```

::: warning
Vitest requires `transformMode` option on environment object. It should be equal to `ssr` or `web`. This value determines how plugins will transform source code. If it's set to `ssr`, plugin hooks will receive `ssr: true` when transforming or resolving files. Otherwise, `ssr` is set to `false`.
Vitest requires `viteEnvironment` option on environment object (fallbacks to the Vitest environment name by default). It should be equal to `ssr`, `client` or any custom [Vite environment](https://vite.dev/guide/api-environment) name. This value determines which environment is used to process file.
:::

You also have access to default Vitest environments through `vitest/environments` entry:
Expand Down
18 changes: 17 additions & 1 deletion docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,31 @@ $ pnpm run test:dev math.test.ts
```
:::

### Replacing `vite-node` with [Module Runner](https://vite.dev/guide/api-environment-runtimes.html#modulerunner)

Module Runner is a successor to `vite-node` implemented directly in Vite. Vitest now uses it directly instead of having a wrapper around Vite SSR handler. This means that certain features are no longer available:

- `VITE_NODE_DEPS_MODULE_DIRECTORIES` environment variable was replaced with `VITEST_MODULE_DIRECTORIES`
- Vitest no longer injects `__vitest_executor` into every [test runner](/advanced/runner). Instead, it injects `moduleRunner` which is an instance of [`ModuleRunner`](https://vite.dev/guide/api-environment-runtimes.html#modulerunner)
- `vitest/execute` entry point was removed. It was always meant to be internal
- [Custom environments](/guide/environment) no longer need to provide a `transformMode` property. Instead, provide `viteEnvironment`. If it is not provided, Vitest will use the environment name to transform files on the server (see [`server.environments`](https://vite.dev/guide/api-environment-instances.html))
- `vite-node` is no longer a dependency of Vitest
- `deps.optimizer.web` was renamed to [`deps.optimizer.client`](/config/#deps-optimizer-client). You can also use any custom names to apply optimizer configs when using other server environments

Vite has its own externalization mechanism, but we decided to keep using the old one to reduce the amount of breaking changes. You can keep using [`server.deps`](/config/#server-deps) to inline or externalize packages.

This update should not be noticeable unless you rely on advanced features mentioned above.

### Deprecated APIs are Removed

Vitest 4.0 removes some deprecated APIs, including:

- `poolMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
- `environmentMatchGlobs` config option. Use [`projects`](/guide/projects) instead.
- `workspace` config option. Use [`projects`](/guide/projects) instead.
- `deps.external`, `deps.inline`, `deps.fallbackCJS` config options. Use `server.deps.external`, `server.deps.inline`, or `server.deps.fallbackCJS` instead.

This release also removes all deprecated types. This finally fixes an issue where Vitest accidentally pulled in `node` types (see [#5481](https://github.com/vitest-dev/vitest/issues/5481) and [#6141](https://github.com/vitest-dev/vitest/issues/6141)).
This release also removes all deprecated types. This finally fixes an issue where Vitest accidentally pulled in `@types/node` (see [#5481](https://github.com/vitest-dev/vitest/issues/5481) and [#6141](https://github.com/vitest-dev/vitest/issues/6141)).

## Migrating from Jest {#jest}

Expand Down
10 changes: 5 additions & 5 deletions packages/browser/src/client/tester/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from 'vitest/internal/browser'
import { NodeBenchmarkRunner, VitestTestRunner } from 'vitest/runners'
import { createStackString, parseStacktrace } from '../../../../utils/src/source-map'
import { executor, getWorkerState } from '../utils'
import { getWorkerState, moduleRunner } from '../utils'
import { rpc } from './rpc'
import { VitestBrowserSnapshotEnvironment } from './snapshot'

Expand Down Expand Up @@ -117,7 +117,7 @@ export function createBrowserRunner(
await rpc().onAfterSuiteRun({
coverage,
testFiles: files.map(file => file.name),
transformMode: 'browser',
environment: '__browser__',
projectName: this.config.name,
})
}
Expand Down Expand Up @@ -223,7 +223,7 @@ export async function initiateRunner(

const BrowserRunner = createBrowserRunner(runnerClass, mocker, state, {
takeCoverage: () =>
takeCoverageInsideWorker(config.coverage, executor),
takeCoverageInsideWorker(config.coverage, moduleRunner),
})
if (!config.snapshotOptions.snapshotEnvironment) {
config.snapshotOptions.snapshotEnvironment = new VitestBrowserSnapshotEnvironment()
Expand All @@ -238,8 +238,8 @@ export async function initiateRunner(
})

const [diffOptions] = await Promise.all([
loadDiffConfig(config, executor as any),
loadSnapshotSerializers(config, executor as any),
loadDiffConfig(config, moduleRunner as any),
loadSnapshotSerializers(config, moduleRunner as any),
])
runner.config.diffOptions = diffOptions
getWorkerState().onFilterStackTrace = (stack: string) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/browser/src/client/tester/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ const state: WorkerGlobalState = {
config,
environment: {
name: 'browser',
transformMode: 'web',
viteEnvironment: 'client',
setup() {
throw new Error('Not called in the browser')
},
},
onCleanup: fn => getBrowserState().cleanups.push(fn),
moduleCache: getBrowserState().moduleCache,
evaluatedModules: getBrowserState().evaluatedModules,
resolvingModules: getBrowserState().resolvingModules,
moduleExecutionInfo: new Map(),
metaEnv: null as any,
rpc: null as any,
durations: {
environment: 0,
Expand Down
7 changes: 4 additions & 3 deletions packages/browser/src/client/tester/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
startTests,
stopCoverageInsideWorker,
} from 'vitest/internal/browser'
import { executor, getBrowserState, getConfig, getWorkerState } from '../utils'
import { getBrowserState, getConfig, getWorkerState, moduleRunner } from '../utils'
import { setupDialogsSpy } from './dialog'
import { setupConsoleLogSpy } from './logger'
import { VitestBrowserClientMocker } from './mocker'
Expand Down Expand Up @@ -101,6 +101,7 @@ async function prepareTestEnvironment(options: PrepareOptions) {

const state = getWorkerState()

state.metaEnv = import.meta.env
state.onCancel = onCancel
state.rpc = rpc as any

Expand Down Expand Up @@ -207,7 +208,7 @@ async function prepare(options: PrepareOptions) {

await Promise.all([
setupCommonEnv(config),
startCoverageInsideWorker(config.coverage, executor, { isolate: config.browser.isolate }),
startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.browser.isolate }),
(async () => {
const VitestIndex = await import('vitest')
Object.defineProperty(window, '__vitest_index__', {
Expand Down Expand Up @@ -249,7 +250,7 @@ async function cleanup() {
.catch(error => unhandledError(error, 'Cleanup Error'))
}
state.environmentTeardownRun = true
await stopCoverageInsideWorker(config.coverage, executor, { isolate: config.browser.isolate }).catch((error) => {
await stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.browser.isolate }).catch((error) => {
return unhandledError(error, 'Coverage Error')
})
}
Expand Down
9 changes: 5 additions & 4 deletions packages/browser/src/client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { VitestRunner } from '@vitest/runner'
import type { SerializedConfig, WorkerGlobalState } from 'vitest'
import type { EvaluatedModules, SerializedConfig, WorkerGlobalState } from 'vitest'
import type { IframeOrchestrator } from './orchestrator'
import type { CommandsManager } from './tester/utils'

Expand All @@ -13,10 +13,10 @@ export async function importFs(id: string): Promise<any> {
return getBrowserState().wrapModule(() => import(/* @vite-ignore */ name))
}

export const executor = {
export const moduleRunner = {
isBrowser: true,

executeId: (id: string): Promise<any> => {
import: (id: string): Promise<any> => {
if (id[0] === '/' || id[1] === ':') {
return importFs(id)
}
Expand Down Expand Up @@ -65,7 +65,8 @@ export function ensureAwaited<T>(promise: (error?: Error) => Promise<T>): Promis
export interface BrowserRunnerState {
files: string[]
runningFiles: string[]
moduleCache: Map<string, any>
resolvingModules: Set<string>
evaluatedModules: EvaluatedModules
config: SerializedConfig
provider: string
runner: VitestRunner
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/node/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject, defaultMocke

function setupClient(project: TestProject, rpcId: string, ws: WebSocket) {
const mockResolver = new ServerMockResolver(globalServer.vite, {
moduleDirectories: project.config.server?.deps?.moduleDirectories,
moduleDirectories: project.config?.deps?.moduleDirectories,
})
const mocker = project.browser?.provider.mocker

Expand Down
8 changes: 4 additions & 4 deletions packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider<ResolvedCover
const start = debug.enabled ? performance.now() : 0

const coverageMap = this.createCoverageMap()
let coverageMapByTransformMode = this.createCoverageMap()
let coverageMapByEnvironment = this.createCoverageMap()

await this.readCoverageFiles<CoverageMap>({
onFileRead(coverage) {
coverageMapByTransformMode.merge(coverage)
coverageMapByEnvironment.merge(coverage)
},
onFinished: async () => {
// Source maps can change based on projectName and transform mode.
// Coverage transform re-uses source maps so we need to separate transforms from each other.
const transformedCoverage = await transformCoverage(coverageMapByTransformMode)
const transformedCoverage = await transformCoverage(coverageMapByEnvironment)
coverageMap.merge(transformedCoverage)

coverageMapByTransformMode = this.createCoverageMap()
coverageMapByEnvironment = this.createCoverageMap()
},
onDebug: debug,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/coverage-v8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
},
"dependencies": {
"@bcoe/v8-coverage": "^1.0.2",
"@vitest/utils": "workspace:*",
"ast-v8-to-istanbul": "^0.3.3",
"debug": "catalog:",
"istanbul-lib-coverage": "catalog:",
Expand All @@ -73,7 +74,6 @@
"@types/istanbul-reports": "catalog:",
"@vitest/browser": "workspace:*",
"pathe": "catalog:",
"vite-node": "workspace:*",
"vitest": "workspace:*"
}
}
10 changes: 6 additions & 4 deletions packages/coverage-v8/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ const mod: CoverageProviderModule = {
try {
const result = coverage.result
.filter(filterResult)
.map(res => ({
...res,
startOffset: options?.moduleExecutionInfo?.get(fileURLToPath(res.url))?.startOffset || 0,
}))
.map((res) => {
return {
...res,
startOffset: options?.moduleExecutionInfo?.get(fileURLToPath(res.url))?.startOffset || 0,
}
})

resolve({ result })
}
Expand Down
Loading
Loading