test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

Unable to use with Vitest in browser mode

Open lavoscore opened this issue 1 year ago • 3 comments

Environment

  • Operating System: Linux
  • Node Version: v18.20.3
  • Nuxt Version: 3.13.2
  • CLI Version: 3.14.0
  • Nitro Version: 2.9.7
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-912ubv

run pnpm test:browser and check the components directory for Foo.vue and Foo.test.ts

Describe the bug

I'm following steps 1 and 2 from the setup, but when running vitest in browser mode I get the following error in the browser UI:

ReferenceError: process is not defined ❯ /node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vite/dist/client/env.mjs:12:519

Could that be because process is in fact referenced inside https://github.com/nuxt/test-utils/blob/main/src/config.ts, when I'm running the test runner under a browser environment, and not in Node? If so, how can I configure vitest to run in browser mode under Nuxt environment?

Additional context

No response

Logs

No response

lavoscore avatar Oct 18 '24 19:10 lavoscore

Can confirm that I am getting the same error. Nuxt: 3.13.0 Vitest + @vitest/browser: 2.1.3

I tried several different package versions with no luck. Error shows up on both, WebdriverIO and playwright, firefox and chrome. Sometimes the error doesn't pop up though.

Either way, test discovery does not populate in browser mode.

halkony avatar Oct 24 '24 07:10 halkony

Has there been any update on this?

I'm trying to get @nuxt/test-utils to play nice with Storybooks (v9) new testing features, but so far there have been no luck, because of this issue.

AskeLange avatar Jun 19 '25 13:06 AskeLange

Here's a Nuxt v4 reproduction of this issue while attempting to test an Minimum Repro of Nuxt UI + Nuxt in Vitest Browser Mode. Nuxt UI utilizes the Nuxt instance throughout and will also require this issue to be solved.

https://github.com/JessicaSachs/nuxt-vitest-browser-mode

JessicaSachs avatar Aug 28 '25 21:08 JessicaSachs