Skip to content

Commit f5688b2

Browse files
committed
Distinguish node execution flow for coverage
1 parent 5d7d10a commit f5688b2

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
module.exports = {
33
preset: "ts-jest",
44
testEnvironment: "node",
5+
collectCoverageFrom: ["src/**/*.ts"],
56
};

src/index.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ export function sum(numbers: number[]): number {
22
return numbers.reduce((acc, value) => acc + value, 0);
33
}
44

5-
const MONDAY_COUNT = 1;
6-
const TUESDAY_COUNT = 2;
7-
const WEDNESDAY_COUNT = 3;
8-
const THURSDAY_COUNT = 4;
9-
const FRIDAY_COUNT = 5;
5+
// eslint-disable-next-line unicorn/prefer-module
6+
if (require.main === module) {
7+
const MONDAY_COUNT = 1;
8+
const TUESDAY_COUNT = 2;
9+
const WEDNESDAY_COUNT = 3;
10+
const THURSDAY_COUNT = 4;
11+
const FRIDAY_COUNT = 5;
1012

11-
console.info(
12-
sum([
13-
MONDAY_COUNT,
14-
TUESDAY_COUNT,
15-
WEDNESDAY_COUNT,
16-
THURSDAY_COUNT,
17-
FRIDAY_COUNT,
18-
]),
19-
);
13+
console.info(
14+
sum([
15+
MONDAY_COUNT,
16+
TUESDAY_COUNT,
17+
WEDNESDAY_COUNT,
18+
THURSDAY_COUNT,
19+
FRIDAY_COUNT,
20+
]),
21+
);
22+
}

0 commit comments

Comments
 (0)