Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove setup files from coverage #2574

Merged
merged 8 commits into from Jan 19, 2023
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)))

// the server has been created, we don't need to override vite.server options
resolved.api = resolveApiConfig(options)
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',
],
},
})