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: clean coverage-c8 tmp before reporting (fix #1917) #1925

Merged
merged 2 commits into from
Aug 28, 2022

Conversation

sun0day
Copy link
Contributor

@sun0day sun0day commented Aug 27, 2022

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

Comment on lines 34 to 38
// clean tmp dir before run
if (tmpExist) {
rmSync(this.options.tempDirectory, { recursive: true, force: true })
tmpExist = false
}
Copy link
Member

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.

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

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

Copy link
Member

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.

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?

async start(filters?: string[]) {
try {
await this.initCoverageProvider()
}

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v0.22 with c8 coverage does not clear tmp
3 participants