nuxt / test-utils

🧪 Test utilities for Nuxt
http://nuxt.com/docs/getting-started/testing
MIT License
287 stars 75 forks source link

alias in test files while using workspace not working #723

Open ThiloHettmer opened 5 months ago

ThiloHettmer commented 5 months ago

Environment

os: Ubuntu 22.04 node: 21.0.0 nuxt: 3.9.3 @nuxt/test-utils: 2.4.3 vitest: 1.0.4 pnpm: 8.3.1

Reproduction

https://github.com/ThiloHettmer/test-utils-alias-issue/tree/main

Describe the bug

Hi all,

we use a monorepo with multiple layers and apps. The aliases are declared in root via an alias.ts file. They work in our application but not in test files. I've tried alot of things to resolve these aliases but could not get it to work. Note: we want to start the vitest from the root folder and got a vitest.workspace.ts file.

Perhaps I'm just missing something.

Thanks, and gd

Additional context

No response

Logs

No response

joris-fonck-loreal commented 3 months ago

Hello,

You can resolve it by using extends property instead of plain string.

export default defineWorkspace([
  {
    extends: './path/to/app/vitest.config.js'
  }
])

but unfortunately, a new error occurs: ref is not defined (If you are using vue ref for example). This is related to nuxt auto-imports feature. I don't know how to solve it at the moment.