Skip to content

Commit

Permalink
fix: remove setup files from coverage (#2574)
Browse files Browse the repository at this point in the history
Closes #2190
  • Loading branch information
g4rry420 committed Jan 19, 2023
1 parent 3d8ef76 commit 488e4b9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/vitest/src/node/config.ts
@@ -1,5 +1,5 @@
import { resolveModule } from 'local-pkg'
import { normalize, resolve } from 'pathe'
import { normalize, relative, resolve } from 'pathe'
import c from 'picocolors'
import type { ResolvedConfig as ResolvedViteConfig } from 'vite'

Expand Down Expand Up @@ -190,6 +190,7 @@ export function resolveConfig(
?? resolve(resolved.root, file),
),
)
resolved.coverage.exclude.push(...resolved.setupFiles.map(file => relative(resolved.root, file)))

resolved.forceRerunTriggers = [
...resolved.forceRerunTriggers,
Expand Down
13 changes: 13 additions & 0 deletions test/coverage-test/coverage-report-tests/generic.report.test.ts
Expand Up @@ -50,3 +50,16 @@ test('file using import.meta.env is included in report', async () => {

expect(files).toContain('importEnv.ts.html')
})

test('files should not contain a setup file', () => {
const coveragePath = resolve('./coverage')
const files = fs.readdirSync(coveragePath)

expect(files).not.toContain('coverage-test')
expect(files).not.toContain('setup.ts.html')

const coverageSrcPath = resolve('./coverage/src')
const srcFiles = fs.readdirSync(coverageSrcPath)

expect(srcFiles).not.toContain('another-setup.ts.html')
})
2 changes: 2 additions & 0 deletions test/coverage-test/setup.ts
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-console
console.log('Test Setup File')
2 changes: 2 additions & 0 deletions test/coverage-test/src/another-setup.ts
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-console
console.log('Another Setup File')
5 changes: 5 additions & 0 deletions test/coverage-test/vitest.config.ts
@@ -1,3 +1,4 @@
import { resolve } from 'pathe'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'

Expand All @@ -16,5 +17,9 @@ export default defineConfig({
all: true,
reporter: ['html', 'text', 'lcov', 'json'],
},
setupFiles: [
resolve(__dirname, './setup.ts'),
'./src/another-setup.ts',
],
},
})

0 comments on commit 488e4b9

Please sign in to comment.