forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.test.ts
45 lines (36 loc) · 1.17 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
import { afterAll, expect, test } from 'vitest'
import { getAuthToken } from '../src/env'
const NODE_ENV = process.env.NODE_ENV
afterAll(() => {
process.env.NODE_ENV = NODE_ENV
})
test('reassigning NODE_ENV', () => {
expect(process.env.NODE_ENV).toBeDefined()
process.env.NODE_ENV = 'development'
expect(process.env.NODE_ENV).toBe('development')
})
test('reads envs from .env file', () => {
expect(import.meta.env.VITE_TEST_ENV).toBe('local')
})
test('can reassign env locally', () => {
import.meta.env.VITEST_ENV = 'TEST'
expect(import.meta.env.VITEST_ENV).toBe('TEST')
})
test('can reassign env everywhere', () => {
import.meta.env.AUTH_TOKEN = '123'
expect(getAuthToken()).toBe('123')
process.env.AUTH_TOKEN = '321'
expect(getAuthToken()).toBe('321')
})
test('can see env in "define"', () => {
expect(import.meta.env.TEST_NAME).toBe('hello world')
expect(process.env.TEST_NAME).toBe('hello world')
})
test('has worker env', () => {
expect(process.env.VITEST_WORKER_ID).toBeDefined()
expect(process.env.VITEST_POOL_ID).toBeDefined()
})
test('custom env', () => {
expect(process.env.CUSTOM_ENV).toBe('foo')
expect(import.meta.env.CUSTOM_ENV).toBe('foo')
})