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: clean coverage-c8 tmp before reporting (fix #1917) #1925
Conversation
packages/coverage-c8/src/provider.ts
Outdated
// clean tmp dir before run | ||
if (tmpExist) { | ||
rmSync(this.options.tempDirectory, { recursive: true, force: true }) | ||
tmpExist = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no need to re-implement this logic. It is already done in clean
function.
vitest/packages/coverage-c8/src/provider.ts
Lines 35 to 41 in 5b190e8
async clean(clean = true) { | |
if (clean && existsSync(this.options.reportsDirectory)) | |
await fs.rm(this.options.reportsDirectory, { recursive: true, force: true }) | |
if (!existsSync(this.options.tempDirectory)) | |
await fs.mkdir(this.options.tempDirectory, { recursive: true }) | |
} |
This function should be called from packages/vitest
as it was before 0.22
release. I think it broke somewhere in #1676.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether onBeforeFilesRun
supports calling async clean
. If support, I can change onBeforeFilesRun
to call async clean
. Besides, I think it's better to handle clean
logic inside C8CoverageProvider
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can call C8CoverageProvider.clean
in initCoverageProvider
vitest/packages/vitest/src/node/core.ts
Lines 119 to 127 in 5b190e8
async initCoverageProvider() { | |
if (this.coverageProvider !== undefined) | |
return | |
this.coverageProvider = await getCoverageProvider(this.config.coverage) | |
if (this.coverageProvider) { | |
await this.coverageProvider.initialize(this) | |
this.config.coverage = this.coverageProvider.resolveOptions() | |
} | |
return this.coverageProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage provider is instructed to clean here.
vitest/packages/vitest/src/node/core.ts
Line 108 in 5b190e8
await this.coverageProvider?.clean(this.config.coverage.clean) |
But it seems that this.coverageProvider
has not yet been initialized at this point. This is clearly a bug.
The this.coverageProvider.clean()
should be moved so that it is called after this.initCoverageProvider()
. Maybe here into start
?
vitest/packages/vitest/src/node/core.ts
Lines 148 to 151 in 5b190e8
async start(filters?: string[]) { | |
try { | |
await this.initCoverageProvider() | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. I will modify my commit code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done @AriPerkkio
fix #1917
Clean tmp dir before coverage-c8 report each time.
Same as:
https://github.com/bcoe/c8/blob/7f1069dcce6821a6794557b39d6a13f620c64bad/bin/c8.js#L31-L35