[nuxt] instance is not available in server utils unit tests with useRuntimeConfig() · Issue #949 · nuxt/test-utils · GitHub
Skip to content

[nuxt] instance is not available in server utils unit tests with useRuntimeConfig() #949

Open

Description

@alexcroox

Environment

  • Operating System: Darwin
  • Node Version: v20.10.0
  • Nuxt Version: 3.13.2
  • CLI Version: 3.13.2
  • Nitro Version: 2.9.7
  • Package Manager: npm@10.2.3
  • Builder: -
  • User Config: compatibilityDate, devtools, future, experimental, ssr, typescript, routeRules, hooks, runtimeConfig, extends, modules, sourcemap, ui, postcss, tailwindcss, vite, nitro, components, css, imports, content, ogImage, i18n
  • Runtime Modules: @nuxt/test-utils/module@3.14.2, @pinia/nuxt@0.5.4, @nuxt/ui@2.18.4, @nuxtjs/i18n@8.5.3, @nuxt/fonts@0.7.2, @vueuse/nuxt@11.0.3, @nuxt/eslint@0.5.7, nuxt-eslint-auto-explicit-import@0.0.2, @nuxt/image@1.8.0, @nuxtjs/fontaine@0.4.3, @nuxt/content@2.13.2, @codecov/nuxt-plugin@1.0.1, @nuxtjs/seo@2.0.0-rc.21
  • Build Modules: -

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

Activity

  1. bolt-new-by-stackblitz commented on Sep 16, 2024

    @bolt-new-by-stackblitz
  2. transferred this issue fromnuxt/nuxton Sep 18, 2024
  3. danielroe commented on Sep 18, 2024

    @danielroe
    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?

  4. alexcroox commented on Sep 18, 2024

    @alexcroox
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions