MCPcopy
hub / github.com/vitest-dev/vitest / loadNativeEnvironment

Function loadNativeEnvironment

packages/vitest/src/integrations/env/loader.ts:57–70  ·  view source on GitHub ↗
(
  name: string,
  root: string,
  traces: Traces,
)

Source from the content-addressed store, hash-verified

55}
56
57export async function loadNativeEnvironment(
58 name: string,
59 root: string,
60 traces: Traces,
61): Promise<Environment> {
62 const packageId = name[0] === '.' || name[0] === '/'
63 ? pathToFileURL(resolve(root, name)).toString()
64 : import.meta.resolve(`vitest-environment-${name}`, pathToFileURL(root).toString())
65 const pkg = await traces.$(
66 'vitest.runtime.environment.import',
67 () => import(packageId) as Promise<{ default: Environment }>,
68 )
69 return resolveEnvironmentFromModule(name, packageId, pkg)
70}
71
72function resolveEnvironmentFromModule(name: string, packageId: string, pkg: { default: Environment }) {
73 if (!pkg || !pkg.default || typeof pkg.default !== 'object') {

Callers 1

loadEnvironmentFunction · 0.85

Calls 5

$Method · 0.80
resolveFunction · 0.50
toStringMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected