Skip to content

Commit

Permalink
chore: coverage 移除多余的callback
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuineng authored and yihuineng committed Jan 29, 2024
1 parent e50ef23 commit 259bf28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions lib/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,31 @@ const reporter = new Reporter();

const useRemap = process.env.MACACA_REPORTER_USE_REMAP;

module.exports = (callback) => {
module.exports = () => {
const coverageDir = path.join(cwd, 'coverage', '.temp');

if (!_.isExistedDir(coverageDir)) {
return callback();
logger.info(`coverageDir not exist: ${coverageDir}`);
return;
}
const coverageFiles = fs
.readdirSync(coverageDir)
.filter(i => path.extname(i) === '.json');

if (!coverageFiles.length) {
return callback();
logger.info('coverageFiles not found');
return;
}
coverageFiles.map(i => {
const file = path.join(coverageDir, i);
const content = fs.readFileSync(file, 'utf8');
coverageFiles.forEach(cFile => {
const content = fs.readFileSync(path.join(coverageDir, cFile), 'utf8');
const __coverage__ = CircularJson.parse(content);

if (useRemap) {
const _collector = remap(__coverage__, {
warn: () => {},
warnMissingSourceMaps: false,
mapFileName: filename => {
const originName = filename
.replace(/\.vue\.[jt]s(\?.+)?$/, '.vue');
return originName;
return filename.replace(/\.vue\.[jt]s(\?.+)?$/, '.vue');
},
});
collector.add(_collector.getFinalCoverage());
Expand All @@ -68,10 +67,10 @@ module.exports = (callback) => {
]);
reporter.write(collector, true, () => {
if (!isCI) {
logger.info('is not ci, clean coverageDir');
_.rimraf(coverageDir);
}
const coverageHtml = path.join(cwd, 'coverage', 'index.html');
logger.info(chalk.cyan(`coverage reporter generated: ${coverageHtml}`));
callback();
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaca-reporter",
"version": "1.9.16",
"version": "1.9.17",
"description": "Reporter for mocha and other frameworks.",
"keywords": [
"macaca",
Expand Down

0 comments on commit 259bf28

Please sign in to comment.