Skip to content

Commit

Permalink
feat: add default hashes in coverage badges
Browse files Browse the repository at this point in the history
  • Loading branch information
olavoparno committed Jun 7, 2021
1 parent 13a80f9 commit 90dff1e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
| Statements | Branches | Functions | Lines |
| --------------------------------------------------------------------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| ![Statements](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) | ![Branches](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) | ![Functions](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) | ![Lines](https://img.shields.io/badge/Coverage-100%25-brightgreen.svg) |
| ![Statements](https://img.shields.io/badge/statements-100%25-brightgreen.svg) | ![Branches](https://img.shields.io/badge/branches-100%25-brightgreen.svg) | ![Functions](https://img.shields.io/badge/functions-100%25-brightgreen.svg) | ![Lines](https://img.shields.io/badge/lines-100%25-brightgreen.svg) |

---

Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const hashesConst = {
{ key: 'statements', value: 'Statements' },
],
};
export const coverageUrlConst = (coverage: number, color: string): string =>
`https://img.shields.io/badge/Coverage-${coverage}${encodeURI('%')}-${color}.svg`;
export const coverageUrlConst = (alt: string, coverage: number, color: string): string =>
`https://img.shields.io/badge/${alt}-${coverage}${encodeURI('%')}-${color}.svg`;
2 changes: 1 addition & 1 deletion src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const getCoverageBadge = (coverageFile: string, hashKey: string): string
const coverage: number = parsedCoverage.total[hashKey].pct;
const color = getCoverageColor(coverage);

return coverageUrlConst(coverage, color);
return coverageUrlConst(hashKey, coverage, color);
} catch {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Tests editor', () => {
const brokenJsonCoverageBadges = getCoverageBadge(brokenJsonCoverageFile, 'nonExistingHash');
const wrongJsonCoverageBadges = getCoverageBadge('wrong json', 'nonExistingHash');

expect(existingCoverageBadge).toEqual('https://img.shields.io/badge/Coverage-95.45%25-brightgreen.svg');
expect(existingCoverageBadge).toEqual('https://img.shields.io/badge/bad-95.45%25-brightgreen.svg');
expect(nonExistingCoverageBadges).toBeFalsy();
expect(brokenJsonCoverageBadges).toBeFalsy();
expect(wrongJsonCoverageBadges).toBeFalsy();
Expand Down
10 changes: 5 additions & 5 deletions tests/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCoveragePath, getReadmePath, readFileAsync } from "../src/helpers";
import { getCoveragePath, getReadmePath, readFileAsync } from '../src/helpers';

describe('test helpers file', () => {
it('should getCoveragePath from arguments', () => {
Expand All @@ -19,7 +19,7 @@ describe('test helpers file', () => {
process.argv.pop();
});

it ('should fail to read an async file', async () => {
await readFileAsync('./foo/bar.biz', 'utf-8').catch(e => expect(e).toEqual('file not found: ./foo/bar.biz'))
})
})
it('should fail to read an async file', async () => {
await readFileAsync('./foo/bar.biz', 'utf-8').catch((e) => expect(e).toEqual('file not found: ./foo/bar.biz'));
});
});

0 comments on commit 90dff1e

Please sign in to comment.