Closed meoyawn closed 2 years ago
@meoyawn what is your command line to run vitest? Now the plugin just invokes vitest run -t first demo.test.ts
command line.
@linux-china thanks for responding
I run tests with vitest run src/
, it loads vitest.config.ts
(with loadEnv
) then runs everything
@linux-china oh, I just realized the problem was my monorepo. I have several subpackages in a monorepo: front
, back
, shared
monorepo file structure:
package.json
back/package.json
back/vitest.config.ts
(not loaded)
back/src/__tests__/demo.test.ts
only one of my subpackages needs to load .env.test
, so I just specified it in root vitest.config.ts
:
import { defineConfig, loadEnv } from "vite"
import { join } from "path"
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, join(process.cwd(), "back"), "")
Object.assign(process.env, env)
return {}
})
alright, my issue is solved. Thanks again
Hi, thank you so much for this
I am reading
.env.test
files in my tests like this invitest.config.ts
:but my env vars are not loaded when running
vitest
with this pluginAny help appreciated