stuartrobinson
stuartrobinson
TTCTheo's Typesafe Cult
Created by niels on 5/26/2023 in #questions
t3-env issues with Vitest test cases
That’s right
69 replies
TTCTheo's Typesafe Cult
Created by niels on 5/26/2023 in #questions
t3-env issues with Vitest test cases
I couldn't get this to work. Instead I added the following line to defineConfig:
process.env = loadEnv(mode, process.cwd(), '')
process.env = loadEnv(mode, process.cwd(), '')
Full code here:
import { defineConfig } from 'vitest/config'
import { loadEnv } from 'vite'

export default defineConfig(({ mode }) => {
// By default this plugin will only load variables that start with VITE_*
// To fix this we can use the loadEnv function from Vite
// We set the third parameter to '' to load all env regardless of the `VITE_` prefix.
process.env = loadEnv(mode, process.cwd(), '')
return {
test: {
globals: true,
includeSource: ['lib/**/*.{js,ts}', 'utils/**/*.{js,ts}'],
environment: 'happy-dom',
alias: {
'@/': new URL('./', import.meta.url).pathname,
},
},
}
})
import { defineConfig } from 'vitest/config'
import { loadEnv } from 'vite'

export default defineConfig(({ mode }) => {
// By default this plugin will only load variables that start with VITE_*
// To fix this we can use the loadEnv function from Vite
// We set the third parameter to '' to load all env regardless of the `VITE_` prefix.
process.env = loadEnv(mode, process.cwd(), '')
return {
test: {
globals: true,
includeSource: ['lib/**/*.{js,ts}', 'utils/**/*.{js,ts}'],
environment: 'happy-dom',
alias: {
'@/': new URL('./', import.meta.url).pathname,
},
},
}
})
And also specify the mode when running vitest:
vitest --mode development
vitest --mode development
69 replies