nuxt / nuxt/test-utils

pages are not covered in nuxt environment

Open
#1,352 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
Dominant language
TypeScript
Stars
437
Forks
120
Avg merge
22h 52m
Merged PRs (30d)
23

Description

Environment

"@nuxt/test-utils": "^3.19.2",
"vitest": "^3.2.3"

--

  • Operating System: Windows_NT
  • Node Version: v22.16.0
  • Nuxt Version: 3.17.6
  • CLI Version: 3.25.1
  • Nitro Version: 2.11.13
  • Package Manager: npm@10.9.2
  • Builder: -
  • User Config: runtimeConfig, ssr, alias, compatibilityDate, devtools, css, vite, modules
  • Runtime Modules: @nuxt/test-utils/module@3.19.2, @pinia/nuxt@0.11.1
  • Build Modules: -
Reproduction

Similar to here.
Ist about the nuxt environment.
I changed it from happy-dom to nuxt. Since then it is not coverging pages.
The Stackoverflow user had a much simpler set up without projects.

import {
  defineVitestConfig,
  defineVitestProject,
} from "@nuxt/test-utils/config";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import { configDefaults, defineConfig } from "vitest/config";

// 1️⃣ Nuxt-specific setup via defineVitestConfig
const nuxtConfig = defineVitestConfig({
  test: {
    environment: "nuxt",
    globals: true,
  },
});

// 2️⃣ Full Vitest config using core defineConfig
export default defineConfig({
  ...nuxtConfig,
  test: {
    coverage: {
      provider: "v8",
      reporter: ["text", "json", "html"],
      reportsDirectory: "./tests/coverage",
      exclude: [
        ...(configDefaults.coverage?.exclude ?? []),
        "**/*.cy.ts",
        "**/*.cy.tsx",
        "**/cypress/**",
        "nuxt.config.ts",
        "scripts/**",
      ],
      thresholds: { statements: 90, branches: 90, functions: 0, lines: 90 },
    },

    projects: [
      {
        test: {
          name: "Server (Node Environment)",
          include: ["tests/server/**/*.{test,spec}.ts"],
          globals: true,
          environment: "node",
        },
        plugins: [vue(), AutoImport({ imports: ["vue"], dts: true })],
      },
      await defineVitestProject({
        test: {
          name: "Happy NUXT Environment",
          include: [
            "tests/pages/**/*.{test,spec}.ts",
            "tests/components/**/*.{test,spec}.ts",
            "tests/composables/**/*.{test,spec}.ts",
            "tests/utils/**/*.{test,spec}.ts",
            "tests/plugins/**/*.{test,spec}.ts",
            "tests/layouts/**/*.{test,spec}.ts",
            "tests/directives/**/*.{test,spec}.ts",
            "tests/mixins/**/*.{test,spec}.ts",
            "tests/app.test.ts",
            "Tests/error.test.ts",
          ],
          exclude: ["tests/server/*.{test,spec}.ts"],
          globals: true,
          environment: "nuxt",
          setupFiles: ["./tests/setup.ts"],
        },
      }),
    ],
  },
});
Describe the bug

nuxt environment doesn't create coverage for pages
Image

Image

Additional context

I tried additionally and explicitly adding pages to includes. But it doesn't work.
Please, tag me, if it requires to be opened up in a different repository, such as vitest.

Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Vitest configuration shown in the issue, especially the coverage settings and the Nuxt project defined with defineVitestProject. Run the tests included under tests/pages and compare their results with the generated coverage reports. Done means Nuxt page files are represented in coverage without breaking the existing server and component test projects.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
frontend, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.