Skip to content

Commit 5f6c905

Browse files
authored
Add code coverage with 100% threshold (#56)
1 parent a7c0461 commit 5f6c905

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,17 @@ jobs:
8888
- run: yarn lint
8989
- run: yarn build
9090
- run: yarn jest
91+
92+
- name: Code Coverage Summary Report
93+
uses: irongut/CodeCoverageSummary@v1.3.0
94+
with:
95+
filename: coverage/cobertura-coverage.xml
96+
format: markdown
97+
output: both
98+
99+
- name: Add Coverage PR Comment
100+
uses: marocchino/sticky-pull-request-comment@v2
101+
if: github.event_name == 'pull_request'
102+
with:
103+
recreate: true
104+
path: code-coverage-results.md

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### dependabot: \#49 Bump cross-spawn from 7.0.3 to 7.0.6
1717

18+
### Added
19+
20+
- Code coverage with 100% threshold
21+
1822
## [1.2.0] - 2025-01-13
1923

2024
### Added

jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,14 @@ module.exports = {
44
testEnvironment: "node",
55
resetMocks: false,
66
setupFiles: ["jest-localstorage-mock"],
7+
collectCoverage: true,
8+
coverageReporters: ["text", "html", "cobertura"],
9+
coverageThreshold: {
10+
global: {
11+
branches: 100,
12+
functions: 100,
13+
lines: 100,
14+
statements: 100,
15+
},
16+
},
717
};

src/lib/localStorage.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ describe("localStorage tests", () => {
66
jest.clearAllMocks();
77
});
88

9+
test("localStorage not supported", () => {
10+
const { localStorage } = global;
11+
delete (global as Partial<typeof global>).localStorage;
12+
expect(() => {
13+
getLocalStorageItem("test");
14+
}).toThrow("localStorage not supported");
15+
global.localStorage = localStorage;
16+
});
17+
918
test("getLocalStorageItem not existing", () => {
1019
expect(getLocalStorageItem("test")).toBeUndefined();
1120
});

src/lib/object.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ describe("object tests", () => {
2626
});
2727

2828
test.each([
29+
// Invalid objects
30+
[null as unknown as object, null],
31+
[undefined as unknown as object, undefined],
32+
33+
// Valid objects
2934
[{}, {}],
3035
[{ hello: "world" }, { hello: "world" }],
3136
[{ hello: null }, {}],

src/lib/string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function isNullOrEmpty(value?: string): boolean {
1717
* @returns true if the value parameter is null/undefined, Empty, or if value consists exclusively of white-space characters
1818
*/
1919
export function isNullOrWhitespace(value?: string): boolean {
20-
return isNullOrEmpty(value) || (value ?? "").trim().length === 0;
20+
return isNullOrEmpty(value) || (value as string).trim().length === 0;
2121
}
2222

2323
/**

0 commit comments

Comments
 (0)