( name: string, root: string, traces: Traces, )
| 55 | } |
| 56 | |
| 57 | export 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 | |
| 72 | function resolveEnvironmentFromModule(name: string, packageId: string, pkg: { default: Environment }) { |
| 73 | if (!pkg || !pkg.default || typeof pkg.default !== 'object') { |
no test coverage detected