-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vitest): allow rewriting process.env.NODE_MODE when using web tra…
…nsform mode (#3957)
- Loading branch information
1 parent
edb322f
commit eca4b87
Showing
4 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @vitest-environment jsdom | ||
|
||
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') | ||
}) | ||
|
||
test('ignores import.meta.env in string literals', () => { | ||
expect('import.meta.env').toBe('import' + '.meta.env') | ||
}) |