I have a project running on Cloudflare Worker and I’m using jest and miniflare for unit-test.
However I’m unable to load env var from .env file into jest environment when running npm run test
.
My wrangler.toml
[miniflare] config:
[miniflare]
cache_persist = true
durable_objects_persist = true
kv_persist = true
env_path = ".env"
package.json:
"scripts": {
"build": "node build.js",
"dev": "miniflare --live-reload --debug --modules dist/index.mjs",
"dev:remote": "wrangler dev",
"test": "npm run build && node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js",
"types:check": "tsc && tsc -p test/tsconfig.json",
"deploy": "wrangler publish"
},
.env file:
ADMIN_TOKEN=xxxxxx
however process.env.ADMIN_TOKEN
is undefined when running in jest.