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] instance is not available in server utils unit tests with useRuntimeConfig() #949

Open
alexcroox opened this issue Sep 16, 2024 · 3 comments
Labels
bug Something isn't working pending triage

Comments

@alexcroox
Copy link

alexcroox commented Sep 16, 2024

Environment

Reproduction

https://stackblitz.com/edit/github-gu1sj1-si6cpn?file=server%2Futils%2Fexample-util.nuxt.spec.ts&startScript=start

Run -> npm run test

Describe the bug

After some recent dependancy upgrades around Nuxt I'm getting the [nuxt] instance unavailable error on tests that call functions in server/utils that use useRuntimeConfig.

See the reproduction link for an example. Thanks.

Additional context

No response

Logs

No response

Copy link

stackblitz bot commented Sep 16, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@danielroe danielroe transferred this issue from nuxt/nuxt Sep 18, 2024
@dosubot dosubot bot added the bug Something isn't working label Sep 18, 2024
@danielroe
Copy link
Member

The runtime environment for nuxt test utils is for testing client-side/browser code, rather than server code. (See #531.) So I wouldn't expect it to work.

Does code using useRuntimeConfig work fine when outside the server/ folder?

@alexcroox
Copy link
Author

alexcroox commented Sep 18, 2024

ah that's a real shame. It used to work before compatibility version 4 was introduced, here is a repro with it working fine in the old folder structure: https://stackblitz.com/edit/github-gu1sj1-xnyzbk?file=server%2Futils%2Fexample-util.nuxt.spec.ts&startScript=start

and yes useRuntimeConfig works outside the server folder in v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending triage
Projects
None yet
Development

No branches or pull requests

2 participants