Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 11, 2023
1 parent 7c0ad50 commit 4e22f76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/vitest/src/runtime/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ export async function loadEnvironment(name: string, method: 'setup' | 'setupVM')
if (name in environments)
return environments[name as 'jsdom']
const pkg = await import(`vitest-environment-${name}`)
if (!pkg || !pkg.default || typeof pkg.default !== 'object' || typeof pkg.default[method] !== 'function') {
if (!pkg || !pkg.default || typeof pkg.default !== 'object') {
throw new Error(
`Environment "${name}" is not a valid environment. `
+ `Package "vitest-environment-${name}" should have default export with "${method}" method.`,
)
}
if (typeof pkg.default[method] !== 'function') {
throw new TypeError(
`Environment "${name}" is not a valid environment. `
+ `Package "vitest-environment-${name}" doesn't support ${method === 'setupVM' ? 'vm' : 'non-vm'} environment because it doesn't provide "${method}" method.`,
)
}
return pkg.default
}
4 changes: 3 additions & 1 deletion packages/vitest/src/runtime/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { distDir } from '../paths'
import { startVitestExecutor } from './execute'
import { createCustomConsole } from './console'
import { loadEnvironment } from './environment'
import { createSafeRpc } from './rpc'

const entryFile = pathToFileURL(resolve(distDir, 'entry-vm.js')).href

Expand Down Expand Up @@ -46,7 +47,7 @@ export async function run(ctx: WorkerContext) {
environment: performance.now(),
prepare: performance.now(),
},
rpc,
rpc: createSafeRpc(rpc),
}

installSourcemapsSupport({
Expand All @@ -67,6 +68,7 @@ export async function run(ctx: WorkerContext) {
context.__vitest_worker__ = state
// this is unfortunately needed for our own dependencies
// we need to find a way to not rely on this by default
// because browser doesn't provide these globals
context.process = process
context.global = context
context.console = createCustomConsole(state)
Expand Down

0 comments on commit 4e22f76

Please sign in to comment.