Skip to content
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

Nuxt module import in E2E environment #677

Closed
peterbud opened this issue Dec 26, 2023 · 3 comments
Closed

Nuxt module import in E2E environment #677

peterbud opened this issue Dec 26, 2023 · 3 comments

Comments

@peterbud
Copy link

Environment


  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.9.0
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: pnpm@8.10.5
  • Builder: -
  • User Config: modules, devtools, runtimeConfig
  • Runtime Modules: @nuxt/test-utils/module@3.9.0, ()
  • Build Modules: -

Reproduction

With the latest nuxt test-utils I was trying to mock a server side import. Before even able to mock the server side import, I have realized that the plain vanilla minimal nuxt module seems to be ignored/not executed when running e2e test.

See repro here:
https://stackblitz.com/edit/nuxt-vitest-x6ycht

Describe the bug

Basic setup is to have a server side import coming from a module. an API is using that import to return a value. Running pnpm dev works, and the API returns the value as expected.

Running an E2E test in the nuxt environment however fails, showing error messages which are hinting that the module import has not been executed:

(node-resolve plugin) Could not resolve import "#auth" in /home/projects/nuxt-vitest-x6ycht/server/api/test.get.ts using imports defined in /home/projects/nuxt-vitest-x6ycht/package.json.

Maybe my test config needs to be improved? Or is it a bug?

Additional context

No response

Logs

No response

@danielroe
Copy link
Member

Currently the vitest environment only allows for testing client-side code. (So any aliases added to your nitro config are not respected.)

We can track supporting server side unit testing in #531.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2023
@peterbud
Copy link
Author

Thanks Daniel. I had the impression that E2E is also including the Nuxt server component. Thanks for the clarification.

@danielroe
Copy link
Member

You can definitely test the server side with e2e, but that starts a server with setup and performs fetch requests to it. You don't directly import the server code into your test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants