You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Infer the test environment from the command varlock run launches #1145
When varlock run launches a test runner, infer the test environment from the command itself, so VARLOCK_ENV is test without passing a flag.
Motivation
The Bun guide now recommends varlock run -- bun test. But varlock run resolves before the runner starts, and it's the runner that sets NODE_ENV=test, so VARLOCK_ENV comes out as development. Repro on 1.21.0:
varlock run -- bun test prints ENV_NAME = development NODE_ENV = test.
The builtin variables docs cover this and recommend passing the flag explicitly (VARLOCK_ENV=test varlock run -- vitest), so every test script in every package of a monorepo carries it. Forgetting it on one package runs its tests against development config without any error.
Proposed Solution
In varlock run, when VARLOCK_ENV is not already set, look at the command being run: bun test, vitest, jest, node --test, mocha (and the same through bunx/npx) resolve with VARLOCK_ENV=test. An explicit VARLOCK_ENV or @currentEnv value still wins. It could be an opt-in root decorator if guessing from argv is too implicit.
Alternatives
Pass the flag in every test script (what the docs recommend today).
A varlock test -- <cmd> shorthand that sets the test environment.
Additional Information
The same timing problem applies to anything that sets its own NODE_ENV after startup, but test runners are by far the common case.
Activity
pullfrog commentedon Sep 28, 2026