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

chore: coverage 移除多余的callback #27

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading