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(coverage): .tmp directory conflicts with --shard option #5184

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/coverage-istanbul/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
relativePath: !this.options.allowExternal,
})

this.coverageFilesDirectory = resolve(this.options.reportsDirectory, '.tmp')
const shard = this.ctx.config.shard
const tempDirectory = `.tmp${shard ? `-${shard.index}-${shard.count}` : ''}`

this.coverageFilesDirectory = resolve(this.options.reportsDirectory, tempDirectory)
}

resolveOptions() {
Expand Down
5 changes: 4 additions & 1 deletion packages/coverage-v8/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
relativePath: !this.options.allowExternal,
})

this.coverageFilesDirectory = resolve(this.options.reportsDirectory, '.tmp')
const shard = this.ctx.config.shard
const tempDirectory = `.tmp${shard ? `-${shard.index}-${shard.count}` : ''}`

this.coverageFilesDirectory = resolve(this.options.reportsDirectory, tempDirectory)
}

resolveOptions() {
Expand Down
9 changes: 9 additions & 0 deletions test/coverage-test/option-tests/shard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { readdirSync } from 'node:fs'
import { expect, test } from 'vitest'

test('temporary directory is postfixed with --shard value', () => {
const files = readdirSync('./coverage')

expect(files).toContain('.tmp-1-4')
expect(files).not.toContain('.tmp')
})
8 changes: 8 additions & 0 deletions test/coverage-test/testing-options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ const testCases = [
},
assertionConfig: null,
},
{
testConfig: {
name: 'temp directory with shard',
include: ['option-tests/shard.test.ts'],
shard: '1/4',
},
assertionConfig: null,
},
]

for (const provider of ['v8', 'istanbul']) {
Expand Down