Guides
Testing multiple runtimes
Test detection and conditional branches without modifying process globals.
Testing multiple runtimes
Test detection
expect(detectRuntime({ globals: { Bun: { version: '1.1.0' } } })).toBe('bun')
expect(detectRuntime({ globals: { Deno: { version: { deno: '2.0.0' } } } })).toBe('deno')
expect(detectRuntime({ globals: { process: { versions: { node: '22.0.0' } } } })).toBe('node')
Verify priority
Bun and Deno markers must win over Node-compatible globals:
expect(detectRuntime({
globals: {
Bun: { version: '1.1.0' },
process: { versions: { node: '22.0.0' } }
}
})).toBe('bun')
Test capabilities
const capabilities = detectRuntimeCapabilities({
runtime: 'node',
globals: { fetch, AbortController, setTimeout, clearTimeout, URL }
})
expect(capabilities.fetch).toBe(true)
expect(capabilities.timers).toBe(true)
Test errors
expect(() => detectRuntime({
globals: {},
throwOnUnknown: true
})).toThrow(UnsupportedRuntimeError)
Injected globals test your logic but do not replace integration tests. Run the suite in real Node.js, Bun, and Deno environments, with dedicated browser and workerd tests. Pay particular attention to permissions, minimum versions, Fetch and Web Streams differences, native error causes, and bundler behavior.