Open seanogdev opened 5 months ago
Does this happen with vitest@1.4.0
or just 1.5.0
?
Just tested, it appears to be happening in both
@seanogdev I tested with "pnpm": { "overrides": { "vitest": "1.4.0" } }
and it's generating .eslintrc-auto-import.json
at the root, so this change might be due to https://github.com/vitest-dev/vitest/pull/5476 since v1.5.0.
(Btw, you had packages/config/pnpm-lock.yaml
but I wasn't sure if it's intended, so I tested before testing)
Btw, where is this file supposed to be generated? Is it at root or at packages/app
?
Also this might be partially a plugin side issue with current Vitest workspace's limitation https://github.com/vitest-dev/vitest/issues/5277#issuecomment-2049955873 since it looks like process.cwd
is used here https://github.com/unplugin/unplugin-auto-import/blob/128d050107af1b57ffe2fe2b32018e4110042bde/src/core/ctx.ts#L36 and also relative path https://github.com/unplugin/unplugin-auto-import/blob/128d050107af1b57ffe2fe2b32018e4110042bde/src/core/ctx.ts#L48
It looks like the plugin supports eslint.filepath
, so for now, I think you can explicitly set it like this:
AutoImport({
imports: ["vue"],
eslintrc: {
enabled: true,
filepath: fileURLToPath(
new URL("../../.eslintrc-auto-import.json", import.meta.url)
),
},
})
I started experiencing this issue, with and without vitest.workspace.js
, when I installed the vitest.explorer extension. I work around it simply by resolving the relative paths explicitly, similar to how you suggested it above.
It looks like the issue has something to do with the current working directory because:
given a directory structure like this:
vitest.workspace.js
packages/a/vite.config.js
packages/b/vite.config.js
packages/c/vite.config.js
and package/b/vite.config.js
like this:
AutoImport({
imports: ["vue"],
eslintrc: {
enabled: true,
filepath: ".eslintrc-auto-import.json"
},
})
the .eslintrc-auto-import.json
file is generated, seemingly randomly, at one of these locations:
package/a/.eslintrc-auto-import.json
package/b/.eslintrc-auto-import.json
package/c/.eslintrc-auto-import.json
instead of always at the location relative to package/b/vite.config.js
, which is package/b/.eslintrc-auto-import.json
in this case.
I am seeing an issue where a define
of process.env.FOO
in one workspace is affecting another when running vitest run
from the root. The workspace that has the define
imports TypeScript files from the other workspace using relative path imports. This means that technically the build must be done differently for the 2 different test invocations, but it seems only a single build is occurring that has the define
s undesirably applied.
My workaround is to only apply the define
s when Vite is building and not when Vitest is testing, which works for my needs:
// TODO(sqs): Workaround for
// https://github.com/vitest-dev/vitest/issues/5541#issuecomment-2093886235; we only want and
// need to apply the `define`s when building, not when testing. The `define`s leak into the
// `agent` tests and cause some failures because process.env.CODY_SHIM_TESTING gets `define`d to
// `false`.
define: process.env.VITEST ? null : {
...Object.fromEntries(
Object.entries(fakeProcessEnv).map(([key, value]) => [
`process.env.${key}`,
JSON.stringify(value),
])
),
},
Describe the bug
Noticing that when we run vitest in a workspace, there are certain side effects happening.
For example, we have https://github.com/unplugin/unplugin-auto-import installed, this generates an eslint file that gives us a file to generate globals for what is auto importable so eslint doesnt complain.
Noticing that when we run vitest in the root, the generate file gets added to other packages and too the workspace
Reproduction
https://github.com/seanogdev/vitest-workspace-issue
System Info
Used Package Manager
pnpm
Validations