N
Nuxt4w ago
Kilisei

Nuxt 3.15.4 vitest 3.0.8 not reporting coverage for .vue files

coverage: {
enabled: true,
all: true,
include: ['app', 'emails', 'i18n', 'server'],
reporter: ['text', 'html', 'json', 'json-summary', 'lcov'],
reportOnFailure: true,
thresholds: {
lines: 65,
},
},
coverage: {
enabled: true,
all: true,
include: ['app', 'emails', 'i18n', 'server'],
reporter: ['text', 'html', 'json', 'json-summary', 'lcov'],
reportOnFailure: true,
thresholds: {
lines: 65,
},
},
in you setup.ts we call clearNuxtState() if nuxt enviroment exists
2 Replies
kapa.ai
kapa.ai4w ago
Hi @Kilisei. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources, I can see that you're experiencing an issue with Vitest not properly reporting coverage for .vue files in your Nuxt 3.15.4 project. This appears to be a known issue, particularly with files in the pages/ directory. According to a GitHub issue, there's a bug where Vitest doesn't correctly measure coverage for Vue files in the pages/ directory specifically, while files in other directories don't seem to have the same problem GitHub Issue #31384. The issue report shows that when running coverage tests, files in the pages/ directory show 0% coverage without listing any uncovered lines, suggesting that Vitest isn't properly recognizing these files for coverage measurement. A workaround mentioned in the issue is to conditionally change the pages directory path in your nuxt.config.ts during testing:
export default defineNuxtConfig({
// other config
dir:
process.env.NODE_ENV === "test"
? {
pages: "_pages",
}
: undefined,
})
export default defineNuxtConfig({
// other config
dir:
process.env.NODE_ENV === "test"
? {
pages: "_pages",
}
: undefined,
})
This approach makes Nuxt use a different directory for pages during testing, which seems to allow Vitest to properly measure coverage. For your specific configuration, you're including 'app', 'emails', 'i18n', and 'server' directories in your coverage settings, but you might need to explicitly include other directories where your Vue files are located, or implement the workaround mentioned above if your Vue files are in the pages/ directory. Regarding your mention of clearNuxtState() in setup.ts, this is a good practice when testing with Nuxt to avoid state pollution between tests, but it's not directly related to the coverage reporting issue. If you're still experiencing issues after trying these approaches, you might want to check if there are any updates available for vitest-environment-nuxt, as there have been several version updates mentioned in the knowledge sources that might address coverage-related issues. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4w ago
<@569531317306261515> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?