Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/config/coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ List of files excluded from coverage as glob patterns.

See [Including and excluding files from coverage report](/guide/coverage.html#including-and-excluding-files-from-coverage-report) for examples.

The internal implementation will by default write some configuration files into it, as listed below:
```ts
[
'vitest.config.ts',
'vitest.config.mts',
'vitest.config.cts',
'vitest.config.js',
'vitest.config.mjs',
'vitest.config.cjs',
'vite.config.ts',
'vite.config.mts',
'vite.config.cts',
'vite.config.js',
'vite.config.mjs',
'vite.config.cjs',
'**\/virtual:*',
'**\/__x00__*',
'**/node_modules/**'
]
```

## coverage.clean

- **Type:** `boolean`
Expand Down
7 changes: 4 additions & 3 deletions packages/vitest/src/node/config/resolveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import { getWorkersCountByPercentage } from '../../utils/workers'
import { BaseSequencer } from '../sequencers/BaseSequencer'
import { RandomSequencer } from '../sequencers/RandomSequencer'
import { basename } from 'node:path'

Check failure on line 29 in packages/vitest/src/node/config/resolveConfig.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Expected "node:path" (builtin) to come before "../sequencers/RandomSequencer" (parent)

function resolvePath(path: string, root: string) {
return normalize(
Expand Down Expand Up @@ -394,7 +395,7 @@

// Add hard-coded default coverage exclusions. These cannot be overidden by user config.
// Override original exclude array for cases where user re-uses same object in test.exclude.
resolved.coverage.exclude = [
resolved.coverage.exclude = [...new Set([
...resolved.coverage.exclude,

// Exclude setup files
Expand All @@ -410,15 +411,15 @@
...resolved.include,

// Configs
resolved.config && slash(resolved.config),
resolved.config && basename(slash(resolved.config)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show example what cases this fixes? Does the configuration file show up in coverage in some cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vitest

As shown in the image above, resolved.config contains the full path, but it should be the same file as the second value in the configFiles array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it cause issues with full path? For example, if you use vitest --config some-custom-config.ts, does that show up in coverage report?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't seem to cause any problems at the moment. Actually, this PR wasn't initially intended to address this issue.

Initially, it was here: #9348 (comment). My configuration caused the configuration content to be loaded twice, resulting in duplicate content in the second load. So, I wanted to remove duplicates.

Later, with @sheremet-va's guidance #9348 (comment), I adjusted the configuration so that Vitest's configuration loading logic worked correctly, loading only once. Then I noticed that this configuration file might also be duplicated, so I tried removing duplicates there as well. Of course, I think it's probably fine not to modify this one.

...configFiles,

// Vite internal
'**\/virtual:*',
'**\/__x00__*',

'**/node_modules/**',
].filter(pattern => typeof pattern === 'string')
])].filter(pattern => typeof pattern === 'string')

resolved.forceRerunTriggers = [
...resolved.forceRerunTriggers,
Expand Down
Loading