Skip to content

Commit 5749d2c

Browse files
authoredFeb 12, 2024··
fix(coverage): .tmp directory conflicts with --shard option (#5184)
1 parent e1bd8d5 commit 5749d2c

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed
 

‎packages/coverage-istanbul/src/provider.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ export class IstanbulCoverageProvider extends BaseCoverageProvider implements Co
9898
relativePath: !this.options.allowExternal,
9999
})
100100

101-
this.coverageFilesDirectory = resolve(this.options.reportsDirectory, '.tmp')
101+
const shard = this.ctx.config.shard
102+
const tempDirectory = `.tmp${shard ? `-${shard.index}-${shard.count}` : ''}`
103+
104+
this.coverageFilesDirectory = resolve(this.options.reportsDirectory, tempDirectory)
102105
}
103106

104107
resolveOptions() {

‎packages/coverage-v8/src/provider.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
101101
relativePath: !this.options.allowExternal,
102102
})
103103

104-
this.coverageFilesDirectory = resolve(this.options.reportsDirectory, '.tmp')
104+
const shard = this.ctx.config.shard
105+
const tempDirectory = `.tmp${shard ? `-${shard.index}-${shard.count}` : ''}`
106+
107+
this.coverageFilesDirectory = resolve(this.options.reportsDirectory, tempDirectory)
105108
}
106109

107110
resolveOptions() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { readdirSync } from 'node:fs'
2+
import { expect, test } from 'vitest'
3+
4+
test('temporary directory is postfixed with --shard value', () => {
5+
const files = readdirSync('./coverage')
6+
7+
expect(files).toContain('.tmp-1-4')
8+
expect(files).not.toContain('.tmp')
9+
})

‎test/coverage-test/testing-options.mjs

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ const testCases = [
4343
},
4444
assertionConfig: null,
4545
},
46+
{
47+
testConfig: {
48+
name: 'temp directory with shard',
49+
include: ['option-tests/shard.test.ts'],
50+
shard: '1/4',
51+
},
52+
assertionConfig: null,
53+
},
4654
]
4755

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

0 commit comments

Comments
 (0)
Please sign in to comment.