I’m using vitest+vue3. When launching the debugger with launch.json
pressing F5
, in my Debug Console I can use modules imported by the script i’m debugging no problem.
but when I want to do the same but launching the debugger from one of my vitest test file *.spec.ts
I get an error
Uncaught ReferenceError ReferenceError: myImportedFunction is not defined
at eval (repl:1:1)
here is my config:
vitest.config.ts
:
import { fileURLToPath } from 'node:url'
import { configDefaults, defineConfig, mergeConfig } from 'vitest/config'
import viteConfig from './vite.config'
export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: 'happy-dom',
exclude: [...configDefaults.exclude, 'cypress/*', 'build/*'],
root: fileURLToPath(new URL('./', import.meta.url)),
setupFiles: ['./src/test-utils/vitest-setup.ts'],
},
})
)
vite.config.ts
:
import presetIcons from '@unocss/preset-icons'
import vue from '@vitejs/plugin-vue'
import path from 'node:path'
import UnoCSS from 'unocss/vite'
import Component from 'unplugin-vue-components/vite'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
Component(),
UnoCSS({
presets: [presetIcons()], // Presets
}),
tsconfigPaths(),
],
resolve: {
alias: {
'@': `${path.resolve(__dirname, 'src')}/`,
},
},
server: {
port: process.env.PORT ? Number(process.env.PORT) : 5173,
hmr: true,
},
optimizeDeps: {
entries: ['cypress/e2e/*.cy.ts']
}
})
tsconfig.vitest.json
:
{
"extends": "./tsconfig.app.json",
"exclude": [],
"compilerOptions": {
"composite": true,
"lib": [],
"types": ["node", "happy-dom"]
}
}