Skip to content

Commit

Permalink
fix(coverage): .tmp directory conflicts with --shard option (#5184)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Feb 12, 2024
1 parent e1bd8d5 commit 5749d2c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
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

0 comments on commit 5749d2c

Please sign in to comment.