Skip to content

Commit 78cfbf9

Browse files
authored
fix: avoid crashing on process.versions stub (#9174)
1 parent da0ade2 commit 78cfbf9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/vitest/src/utils/modules.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ const BUN_BUILTIN_NAMESPACE = 'bun:'
1111
// Some runtimes like Bun injects namespaced modules here, which is not a node builtin
1212
const nodeBuiltins = builtinModules.filter(id => !id.includes(':'))
1313

14+
const { bun: isBun, deno: isDeno } = process.versions
15+
1416
// TODO: Use `isBuiltin` from `node:module`, but Deno doesn't support it
1517
export function isBuiltin(id: string): boolean {
16-
if (process.versions.deno && id.startsWith(NPM_BUILTIN_NAMESPACE)) {
18+
if (isDeno && id.startsWith(NPM_BUILTIN_NAMESPACE)) {
1719
return true
1820
}
19-
if (process.versions.bun && id.startsWith(BUN_BUILTIN_NAMESPACE)) {
21+
if (isBun && id.startsWith(BUN_BUILTIN_NAMESPACE)) {
2022
return true
2123
}
2224
return isNodeBuiltin(id)
@@ -47,7 +49,7 @@ export function toBuiltin(id: string): string {
4749
) {
4850
return id
4951
}
50-
if (process.versions.deno || process.versions.bun) {
52+
if (isDeno || isBun) {
5153
return id
5254
}
5355
return `node:${id}`

test/core/test/stubbed-process.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ vi.stubGlobal('process', { badMock: true })
55
it('should not hang', () => {
66
expect(1).toBe(1)
77
})
8+
9+
it('should not crash (#9173)', async () => {
10+
await import('./fixtures/increment')
11+
})

0 commit comments

Comments
 (0)