-
Notifications
You must be signed in to change notification settings - Fork 717
TypeError when Setting Up Vitest #3213
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
Comments
That's weird I tried to do the same but I did not got the same logs, instead the test just passed |
Hey @averrois! I forgot to mention that this error only happens when we call With the starter, you can call // src/App.spec.ts
import { describe, it, expect } from 'vitest';
import { mount } from '@vue/test-utils';
import App from './App.vue';
describe('App', () => {
it('should render', () => {
const wrapper = mount(App);
expect(wrapper.exists()).toBe(true);
});
}); Can you please test if it still working for you? |
Hey @benjamincanac Just following up to see if there are any updates on this issue. This is the last blocker preventing me from integrating Nuxt UI into my company's projects. I really appreciate your time and all the work you put into this project! |
Looks like the vite.config.ts/vitest.config.ts
import { defineConfig, Plugin } from "vite"
import vue from "@vitejs/plugin-vue"
import ui from "@nuxt/ui/vite"
// https://vitejs.dev/config/
export default defineConfig({
test: {
globals: true,
},
optimizeDeps: {
exclude: ["@nuxt/ui"]
},
plugins: [
{
enforce: "pre",
name: "test",
resolveId: (id)=>{
console.log(id)
if(id === '#imports') {
console.log("resolved")
}
}
} satisfies Plugin,
vue(),
ui({
ui: {
colors: {
primary: "green",
neutral: "slate"
}
}
}),
]
}) resolved imports
reproduction: https://github.com/OrbisK/nuxt-ui-vue-starter/tree/test/repoduction |
Event this fails: example.test.js import App from './App.vue';
it("dont care", ()=>{}) |
Facing the same issue. I’ve disabled Vitest in the CI. I really hope a fix for this one. |
I found a workaround/solution! From what I understand, Vitest skips transformation for "external" files — by default, all packages under node_modules aren’t transformed. This includes the @nuxt/ui package. Adding @nuxt/ui to the // vitest.config.ts
import { fileURLToPath } from 'node:url'
import { mergeConfig, defineConfig } from 'vitest/config'
import viteConfig from './vite.config'
export default mergeConfig(
viteConfig,
defineConfig({
test: {
globals: true,
environment: 'jsdom',
root: fileURLToPath(new URL('./', import.meta.url)),
server: {
deps: {
inline: ['@nuxt/ui']
}
}
},
})
) Maybe this could be added inside the |
Wow nice found @fm96-dev! |
Environment
Version
3.0.0-alpha.10
Reproduction
Start a new project with the starter CLI:
npx nuxi init -t github:nuxtlabs/nuxt-ui3-vue-starter test-app
Install vitest and vue test-utils
bun add -D vitest @vue/test-utils
Add test script to package.json
"test": "vitest"
Run the test script
Description
I'm encountering a
TypeError
while trying to set up Vitest in my project (Vue). The error message is as follows:Additional context
No response
Logs
The text was updated successfully, but these errors were encountered: