-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
When running vitest bench, the env.mode variable is set to test, where we expect it is set to benchmark as explained in the docs:
Use process.env.VITEST or mode property on defineConfig (will be set to test/benchmark if not overridden) to conditionally apply different configuration in vite.config.ts
Reproduction
Running vitest bench with the following vitest.config.ts will log mode: test
import { defineConfig } from 'vitest/config'
export default defineConfig((env) => {
console.log('mode:', env.mode)
// ...
})I found two possible culprits, the first one being
vitest/packages/vitest/src/node/create.ts
Lines 26 to 27 in 00e8112
| // this will make "mode" = "test" inside defineConfig | |
| mode: options.mode || process.env.NODE_ENV || mode, |
I think mode should be put ahead of process.env.NODE_ENV, since it is the computed mode. This is the change I made in the linked PR.
Another possible way of fixing it would be to change
| process.env.NODE_ENV ??= options.mode || 'test' |
And use process.env.NODE_ENV ??= options.mode || mode || 'test' instead. However I do not think that setting NODE_ENV to benchmark is such a good idea, as where are in a test environment, and more often that not users will expect their benchmark code to be executed with NODE_ENV=test.
System Info
System:
OS: macOS 14.0
CPU: (8) arm64 Apple M1 Pro
Memory: 63.02 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.15.0 - ~/Library/Caches/fnm_multishells/74906_1698658724643/bin/node
npm: 9.5.0 - ~/Library/Caches/fnm_multishells/74906_1698658724643/bin/npm
Browsers:
Chrome: 118.0.5993.117
Firefox: 119.0
Safari: 17.0
npmPackages:
vite: latest => 4.5.0
vitest: workspace:* => 1.0.0-beta.3Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.