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
1 change: 1 addition & 0 deletions packages/vitest/src/node/config.ts
Expand Up @@ -190,6 +190,7 @@ export function resolveConfig(
?? resolve(resolved.root, file),
),
)
resolved.coverage.exclude.push(...resolved.setupFiles.map(file => file.replace(`${resolved.root}/`, '')))
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved

// the server has been created, we don't need to override vite.server options
resolved.api = resolveApiConfig(options)
Expand Down
9 changes: 9 additions & 0 deletions test/core/test/vi.spec.ts
Expand Up @@ -77,6 +77,15 @@ describe('testing vi utils', () => {
expect(state.config.clearMocks).toBe(false)
})

test('coverage.exclude contains setupFiles in it', () => {
const state = getWorkerState()

if (typeof state.config.setupFiles === 'string')
expect(state.config.coverage.exclude).contains(state.config.setupFiles.replace(`${state.config.root}/`, ''))
else
state.config.setupFiles.forEach(file => expect(state.config.coverage.exclude).contains(file.replace(`${state.config.root}/`, '')))
})

// TODO: it's unstable in CI, skip until resolved
test.skip('loads unloaded module', async () => {
let mod: any
Expand Down
2 changes: 2 additions & 0 deletions test/core/testSetup.ts
@@ -0,0 +1,2 @@
// eslint-disable-next-line no-console
console.log('Test Setup File')
1 change: 1 addition & 0 deletions test/core/vitest.config.ts
Expand Up @@ -43,6 +43,7 @@ export default defineConfig({
testTimeout: 2000,
setupFiles: [
'./test/setup.ts',
resolve(__dirname, './testSetup.ts'),
],
testNamePattern: '^((?!does not include test that).)*$',
coverage: {
Expand Down