[Question]: do we manually clean the cache or raw files?
Closed this issue · 6 comments
I found there some cache files when there is a failure, I wonder do we need to manually clean them in the onStart hook before the next test?
Also I found the raw files are still there when tests are finished, do we need to delete them after the tests? I found I can't do that in the onEnd() hook, the tests will fail.
Before all tests begin, it is best to clear the cache with API cleanCache
:
// clean previous cache before the start of testing
const MCR = require('monocart-coverage-reports');
const options = require('path-to/same-options.js');
MCR(options).cleanCache();
Unless your running environment is new and no cache.
If it's about merging coverage reports, It's best to remove all raw cache in the onEnd hook:
const coverageOptions = {
outputDir: './coverage-reports/merged',
onEnd: () => {
// remove the raw files if it useless
fs.rmSync('./coverage-reports/unit/raw', {
recursive: true,
force: true
})
}
};
Can I do the clean cache in the onStart() hook?
It probably cannot. onStart hook only supports mcr
CLI, and it's not for the purpose of clearing the cache either, because you always need to clear the cache after creating a new report.
const coverageReport = MCR(options);
coverageReport.cleanCache();
Unless you're running in multi-process, with multiple stages of testing to be completed, we can't clear the cache until all stages are finished.
see multiprocessing support, that's why we still need the cleanCache
API.
Ok, the challenge is I don't know where I should put the code in monocart report config, could you provide a more concrete example?
Which library are you using now?
- monocart-reporter It should not need to clean cache because the custom reporter will remove the entire directory.
- jest-monocart-coverage It already supports automatic cache clearing. see here
- monocart-coverage-reports Find the code where you create the coverage report, and then execute the
cleanCache
API, something like:
const coverageReport = MCR(options);
coverageReport.cleanCache();
There is no config option for cleaning cache. (Or consider supporting this option in next version)
Or could you provide more information about your situation? There might be some cases I'm don't know.
Anyway, I added the new option cleanCache
in version monocart-coverage-reports@2.5.9 please try it