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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ 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')
})
2 changes: 2 additions & 0 deletions test/coverage-test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-console
console.log('Test Setup File')
4 changes: 4 additions & 0 deletions test/coverage-test/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { resolve } from 'pathe'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'

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