-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vitest doesn't work in programmatic way if the root path isn't the current working dir #860
Comments
This comment was marked as outdated.
This comment was marked as outdated.
It seems doesn't help 😓 |
This comment was marked as outdated.
This comment was marked as outdated.
Looking, we guess that the Nuxt // vitest.config.ts
+ import { fileURLToPath } from 'node:url'
import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({
test: {
environment: 'nuxt',
+ environmentOptions: {
+ nuxt: {
+ rootDir: fileURLToPath(new URL('.', import.meta.url)),
+ }
+ }
}
}) Do you have a better suggestion for default behaviour - for example, I guess we could look for a |
It works. Thanks. Will close this issue. For the default behavior I don't have a strong preference. However, for programmatic usage, this is the only doc that I have found https://nuxt.com/docs/api/kit/programmatic maybe it's better to have one more guide page and some examples about how to run dev server, prepare, build, lint, test a Nuxt app, and etc. I actually created another discussion about this: nuxt/nuxt#26398 So far I have figured out most of them by reading source code 😅. And the vitest config is the last piece left. |
Environment
The background is I'm trying to make the Nuxt apps work in @teambit.
I tried to run Vitest via Node APIs and have found the app doesn't render properly in the tests if the current working dir is not the root path of the project.
Reproduction
https://github.com/Jinjiang/reproductions/tree/nuxtjs-vitest-20240514
Describe the bug
First, prepare a js file
./debug/run.mjs
like:then:
node ./debug/run.mjs
, it workscd debug && node ./run.mjs
, it doesn'tAdditional context
No response
Logs
The text was updated successfully, but these errors were encountered: