Skip to content

Commit

Permalink
fix(Jest-badge): catch all error
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Aug 20, 2021
1 parent 7458a39 commit a33e3fd
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions scripts/badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ const getCoveragePercentage = (
summaryFilePath: string,
coverageType: string
) => {
const summary = fs.readFileSync(summaryFilePath, 'utf8');
return JSON.parse(summary)['total'][coverageType]['pct'];
try {
const summary = fs.readFileSync(summaryFilePath, 'utf8');
return JSON.parse(summary)['total'][coverageType]['pct'];
} catch (error) {
consola.info(error.message);
return 0;
}
};

const getBadgeColor = (percentage: number) => {
Expand Down Expand Up @@ -58,24 +63,24 @@ const generateCoverageFile = async (
badgeStyle: string,
outputDir: string
) => {
cp.spawnSync('mkdir', ['-p', outputDir]);
const badgeUrl = getBadgeUrl(summaryFilePath, coverageType, badgeStyle);
const output = path.join(outputDir, `coverage-${coverageType}.svg`);
const file = await downloadBadgeFile(badgeUrl);
fs.writeFileSync(output, file, { encoding: 'utf8' });
};

const main = () => {
try {
generateCoverageFile(
SummaryFilePath,
CoverageType[3],
BadgeStyle[0],
OutputBadgePath
);
cp.spawnSync('mkdir', ['-p', outputDir]);
const badgeUrl = getBadgeUrl(summaryFilePath, coverageType, badgeStyle);
const output = path.join(outputDir, `coverage-${coverageType}.svg`);
const file = await downloadBadgeFile(badgeUrl);
fs.writeFileSync(output, file, { encoding: 'utf8' });
} catch (error) {
consola.info(error.message);
}
};

const main = () => {
generateCoverageFile(
SummaryFilePath,
CoverageType[3],
BadgeStyle[0],
OutputBadgePath
);
};

main();

0 comments on commit a33e3fd

Please sign in to comment.