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

Can not load config with environment set to 'happy-dom'

Open FlorianWerndl opened this issue 6 months ago • 2 comments

Environment


  • Operating System: Linux
  • Node Version: v20.19.1
  • Nuxt Version: 3.17.6
  • CLI Version: 3.25.1
  • Nitro Version: 2.11.13
  • Package Manager: [email protected]
  • Builder: -
  • User Config: future, modules, compatibilityDate, devtools, postcss, tailwindcss
  • Runtime Modules: @nuxt/test-utils/[email protected], @nuxtjs/[email protected], @pinia/[email protected]
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-w6vnmxtk

Describe the bug

Run pnpm run test, see error that config can't be loaded. Works with environment set to different value.

Additional context

No response

Logs


FlorianWerndl avatar Jul 21 '25 11:07 FlorianWerndl

Hey @FlorianWerndl have you found a workaround? I'm unable to add testing to my project.

Zachiah avatar Aug 01 '25 15:08 Zachiah

Hi @Zachiah

this is how my config looks likes now. All unit.spec.* files are running with happy-dom and all nuxt.spec.* files with nuxt (using also happy-dom afaik).

import { defineVitestProject } from '@nuxt/test-utils/config';
import { configDefaults, defineConfig } from 'vitest/config';

export default defineConfig({
  test: {
    reporters: ['default', 'junit'],
    outputFile: './coverage/junit.xml',
    coverage: {
      provider: 'v8',
      reporter: ['text', 'json', 'html'],
      reportsDirectory: './coverage',
      include: ['app/**/**.*'],
      exclude: [
        ...(configDefaults.coverage?.exclude ?? []),
        'app/assets/**',
        'app/types/**',
        'app/utils/constants.js',
      ],
    },
    projects: [
      await defineVitestProject({
        test: {
          name: 'happy-dom',
          environment: 'happy-dom',
          globals: true,
          include: ['**/*.unit.spec.{ts,js}'],
        },
      }),
      await defineVitestProject({
        test: {
          name: 'nuxt',
          environment: 'nuxt',
          globals: true,
          include: ['**/*.nuxt.spec.{ts,js}'],
        },
      }),
    ],
    setupFiles: ['./vitest.setup.ts'],
  },
});

FlorianWerndl avatar Aug 02 '25 09:08 FlorianWerndl