Open cadenzah opened 6 days ago
Hey @cadenzah! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together!
To generate a coverage report in your Nuxt project when modifying the srcDir
configuration in nuxt.config.js
, you need to ensure that the coverage configuration in your vitest.config.ts
file is correctly set up to include the new source directory.
Here is an example of how you can modify your vitest.config.ts
to account for the srcDir
configuration:
import { fileURLToPath } from 'node:url'
import { defineVitestConfig } from '@nuxt/test-utils/config'
export default defineVitestConfig({
test: {
dir: 'tests',
coverage: {
reportsDirectory: 'coverage',
},
includeSource: ['srcDir/**'], // Add this line to include your new source directory
environmentOptions: {
nuxt: {
rootDir: fileURLToPath(new URL('./', import.meta.url)),
domEnvironment: (process.env.VITEST_DOM_ENV as 'happy-dom' | 'jsdom') ?? 'happy-dom',
mock: {
indexedDb: true,
},
},
},
setupFiles: './tests/setup/mocks.ts',
globals: true,
},
})
In this example, the includeSource
property in the coverage
configuration is set to include the new source directory specified by srcDir
. Adjust the path in the includeSource
array to match the actual path of your source directory [1].
To continue talking to Dosu, mention @dosu.
The guide provided by Dosu unfortunately does not fix the issue. Hope the maintainers see this and look into it.
FYI @danielroe
Environment
Working directory: /home/projects/github-h9agvz Nuxt project info:
Build Modules: -
Reproduction
https://stackblitz.com/edit/github-h9agvz?file=vitest.config.ts,nuxt.config.ts
Describe the bug
The coverage report (by either v8 or istanbul) does not get generated if I change the
srcDir
configuration innuxt.config.js
. It seems it works well if I use the default setting. You can reproduce the issue with the link I provided.If I click on the Coverage icon button on
vitest-ui
web page, It shows the error text:Cannot GET /coverage/index.html
.If I run
vitest
with--ui
andcoverage.enabled
option totrue
then the coverage report'shtml
files should be generated in/coverage
directory, but what I get is onlytmp
directory withcoverage.json
files included. It seems the.html
files are not generated properly so that the output directory get empty.I even tried to change
reportsDirectory
orroot
invitest.config.js
but nothing changes.Additional context
Sometimes if I run
vitest --ui
then after the preparation is ready, the open browser should show the Vitest UI, but it showsCannot GET /
. After that if I click the URL printed on the console (UI started at http://localhost:51204/__vitest__/), then it goes to the UI page. Also, if I click the Coverage icon on that page, it shows the error text ofCannot GET /coverage/index.html
as well.Logs
No response