Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly resolve external dependencies loaded by custom environments #4196

Merged
merged 1 commit into from Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/vitest/src/runtime/child.ts
Expand Up @@ -54,9 +54,8 @@ async function init(ctx: ChildContext) {

const environment = await loadEnvironment(ctx.environment.name, {
root: ctx.config.root,
fetchModule(id) {
return rpc.fetch(id, 'ssr')
},
fetchModule: id => rpc.fetch(id, 'ssr'),
resolveId: (id, importer) => rpc.resolveId(id, importer, 'ssr'),
})
if (ctx.environment.transformMode)
environment.transformMode = ctx.environment.transformMode
Expand Down
5 changes: 2 additions & 3 deletions packages/vitest/src/runtime/vm.ts
Expand Up @@ -39,9 +39,8 @@ export async function run(ctx: WorkerContext) {

const environment = await loadEnvironment(ctx.environment.name, {
root: ctx.config.root,
fetchModule(id) {
return rpc.fetch(id, 'ssr')
},
fetchModule: id => rpc.fetch(id, 'ssr'),
resolveId: (id, importer) => rpc.resolveId(id, importer, 'ssr'),
})

if (!environment.setupVM) {
Expand Down
5 changes: 2 additions & 3 deletions packages/vitest/src/runtime/worker.ts
Expand Up @@ -37,9 +37,8 @@ async function init(ctx: WorkerContext) {

const environment = await loadEnvironment(ctx.environment.name, {
root: ctx.config.root,
fetchModule(id) {
return rpc.fetch(id, 'ssr')
},
fetchModule: id => rpc.fetch(id, 'ssr'),
resolveId: (id, importer) => rpc.resolveId(id, importer, 'ssr'),
})
if (ctx.environment.transformMode)
environment.transformMode = ctx.environment.transformMode
Expand Down
97 changes: 26 additions & 71 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/env-custom/package.json
Expand Up @@ -6,6 +6,8 @@
"coverage": "vitest run --coverage"
},
"devDependencies": {
"@types/debug": "^4.1.8",
"debug": "^4.3.4",
"vitest": "workspace:*",
"vitest-environment-custom": "file:./vitest-environment-custom"
}
Expand Down
7 changes: 7 additions & 0 deletions test/env-custom/vitest-environment-custom/index.ts
@@ -1,6 +1,10 @@
import vm from 'node:vm'
import debug from 'debug'
import type { Environment } from 'vitest'

// test that external packages (debug) are loaded correctly
const log = debug('test:env')

export default <Environment>{
name: 'custom',
transformMode: 'ssr',
Expand Down Expand Up @@ -28,6 +32,9 @@ export default <Environment>{
teardown() {
delete global.testEnvironment
delete global.option

if (global.__exists)
log('should not log')
},
}
},
Expand Down