-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Delete tmp directory from coverage report after running #2108
Comments
@sheremet-va I'd like to work on this feature if you think it's worth adding a new config :) |
I think it's a bug. We have code for deleting coverage folder. |
Do you mean to delete the entire coverage folder on rerun? I saw this line: vitest/packages/vitest/src/node/core.ts Line 153 in 0cae8ac
But what I'm looking for is to delete only the tmp directory. |
I think I've looked into this before. Even if you tell v8 to stop coverage collection with |
@AriPerkkio, I didn't notice that behavior, but it's still worth deleting the tmp dir. In my case, it created a new 1MB file, and it's way better than the current behavior. |
Sure, I'd like it to work that way. If possible, the tmp directory should always be removed after coverage report is generated. Users should not be interested in pure v8 reports. It might be worth looking into whether we even need to set |
Would it be possible to remove the whole coverage directory if it only includes tmp, for instance when using a console text reporter? |
@kaioduarte #2144 will reduce the size of leftover @everett1992 I don't think it's possible. It seems that vitest has to set We could remove the coverage report here outside vitest process, but adding coverage logic here is not ideal. vitest/packages/vitest/src/node/cli-wrapper.ts Lines 125 to 126 in 6f856c4
The "leftover" v8 reports are written when this process exits: vitest/packages/vitest/src/node/cli.ts Lines 97 to 98 in 6f856c4
Manual testing to see whether NODE_V8_COVERAGE works in worker_threads
// script.js
console.log('script::NODE_V8_COVERAGE', process.env.NODE_V8_COVERAGE); // run.js
const { execFileSync } = require("child_process");
const { Worker } = require("worker_threads");
const { existsSync, rmSync } = require("fs");
const NODE_V8_COVERAGE = "/workspaces/example-project/temp-coverage";
if (existsSync(NODE_V8_COVERAGE)) {
rmSync(NODE_V8_COVERAGE, { recursive: true, force: true })
}
checkDirectory('#1')
// This will enable V8 coverage report
execFileSync("/usr/local/bin/node", ["script.js"], {
stdio: 'inherit',
env: { NODE_V8_COVERAGE }
});
checkDirectory('#2')
if (existsSync(NODE_V8_COVERAGE)) {
console.log('Removing', NODE_V8_COVERAGE)
rmSync(NODE_V8_COVERAGE, { recursive: true, force: true })
}
checkDirectory('#3')
// This will NOT enable V8 coverage report
const worker = new Worker('./script.js', { env: { NODE_V8_COVERAGE } })
new Promise((resolve, reject) => {
worker.on('exit', resolve);
worker.on('error', reject);
}).then(() => {
checkDirectory('#4')
});
// Helpers
function checkDirectory(label) {
console.log(label, 'existsSync(NODE_V8_COVERAGE)', existsSync(NODE_V8_COVERAGE))
} |
Thanks for investigating, @AriPerkkio! |
Clear and concise description of the problem
The
/coverage/tmp
directory is preserved after the code coverage report is finished. That's fine for local development, but it's not on CI when we need to publish the results to an analysis tool like CodeClimate.For example, this is the size of the temp directory for a project I'm working on:
Suggested solution
Add an option to the coverage config to remove the tmp directory.
Alternative
For now, I can remove the files after running the coverage script, like:
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: