Skip to content

Commit

Permalink
fix: fix default import.meta.env.PROD = false
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 18, 2024
1 parent 413ec5e commit 643bed6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/vitest/src/runtime/setup-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ function setupDefines(defines: Record<string, any>) {
function setupEnv(env: Record<string, any>) {
if (typeof process === 'undefined')
return
for (const key in env)
// same boolean-to-string assignment as VitestPlugin.configResolved
const { PROD, DEV, ...restEnvs } = env
process.env.PROD = PROD ? '1' : ''
process.env.DEV = DEV ? '1' : ''
for (const key in restEnvs)
process.env[key] = env[key]
}

Expand Down
9 changes: 6 additions & 3 deletions test/core/test/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ test('define process and using import.meta.env together', () => {
})

test('PROD, DEV, SSR should be boolean', () => {
expect(typeof import.meta.env.PROD).toEqual('boolean')
expect(typeof import.meta.env.DEV).toEqual('boolean')
expect(typeof import.meta.env.SSR).toEqual('boolean')
expect(import.meta.env.PROD).toBe(false)
expect(import.meta.env.DEV).toBe(true)
expect(import.meta.env.SSR).toBe(true)

Check failure on line 60 in test/core/test/env.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

test/env.test.ts > PROD, DEV, SSR should be boolean

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ test/env.test.ts:60:31

Check failure on line 60 in test/core/test/env.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

test/env.test.ts > PROD, DEV, SSR should be boolean

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ test/env.test.ts:60:31

Check failure on line 60 in test/core/test/env.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-14, 20)

test/env.test.ts > PROD, DEV, SSR should be boolean

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ test/env.test.ts:60:31

Check failure on line 60 in test/core/test/env.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 20)

test/env.test.ts > PROD, DEV, SSR should be boolean

AssertionError: expected false to be true // Object.is equality - Expected + Received - true + false ❯ test/env.test.ts:60:31
expect(process.env.PROD).toBe('')
expect(process.env.DEV).toBe('1')
expect(process.env.SSR).toBe('1')

import.meta.env.SSR = false
expect(import.meta.env.SSR).toEqual(false)
Expand Down

0 comments on commit 643bed6

Please sign in to comment.