-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathenv.test.ts
52 lines (42 loc) · 1.22 KB
/
env.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { detectRuntime, RuntimeEnv } from '../env'
const ogProcessEnv = { ...process.env }
afterEach(() => {
process.env = ogProcessEnv
// @ts-ignore
delete globalThis.window
// @ts-ignore
delete globalThis.WebSocketPair
// @ts-ignore
delete globalThis.EdgeRuntime
// @ts-ignore
delete globalThis.window
})
describe(detectRuntime, () => {
it('should return node since these tests run in node', () => {
expect(detectRuntime()).toEqual<RuntimeEnv>('node')
})
it('should return browser if correct env', () => {
// @ts-ignore
// eslint-disable-next-line
delete process.env
// @ts-ignore
globalThis.window = {}
expect(detectRuntime()).toEqual<RuntimeEnv>('browser')
})
it('should return cloudflare worker if correct env', () => {
// @ts-ignore
// eslint-disable-next-line
delete process.env
// @ts-ignore
globalThis.WebSocketPair = {}
expect(detectRuntime()).toEqual<RuntimeEnv>('cloudflare-worker')
})
it('should return edgeruntime if correct env', () => {
// @ts-ignore
// eslint-disable-next-line
delete process.env
// @ts-ignore
globalThis.EdgeRuntime = 'vercel'
expect(detectRuntime()).toEqual<RuntimeEnv>('vercel-edge')
})
})