Skip to content

Commit 7c6a8c2

Browse files
committed
fix: make coverage work when using projects option
1 parent 580d4b7 commit 7c6a8c2

File tree

14 files changed

+140
-1
lines changed

14 files changed

+140
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `[jest-reporters]` Fix issue where console output not displayed for GHA reporter even with `silent: false` option ([#15864](https://github.com/jestjs/jest/pull/15864))
1111
- `[jest-runtime]` Fix issue where user cannot utilize dynamic import despite specifying `--experimental-vm-modules` Node option ([#15842](https://github.com/jestjs/jest/pull/15842))
1212
- `[jest-test-sequencer]` Fix issue where failed tests due to compilation errors not getting re-executed even with `--onlyFailures` CLI option ([#15851](https://github.com/jestjs/jest/pull/15851))
13+
- `[jest-runner, jest-transform]` Fix coverage report doesn't show correct code coverage when using `projects` config option ([#15880](https://github.com/jestjs/jest/pull/15880)), fixes ([#5417](https://github.com/jestjs/jest/issues/5417))
1314

1415
### Chore & Maintenance
1516

e2e/__tests__/__snapshots__/coverageReport.test.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,15 @@ Functions : 50% ( 3/6 )
138138
Lines : 60% ( 12/20 )
139139
================================================================================"
140140
`;
141+
142+
exports[`outputs coverage report with projects option 1`] = `
143+
"------------|---------|----------|---------|---------|-------------------
144+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
145+
------------|---------|----------|---------|---------|-------------------
146+
All files | 66.66 | 100 | 50 | 66.66 |
147+
client | 66.66 | 100 | 50 | 66.66 |
148+
client.js | 66.66 | 100 | 50 | 66.66 | 13
149+
server | 66.66 | 100 | 50 | 66.66 |
150+
server.js | 66.66 | 100 | 50 | 66.66 | 13
151+
------------|---------|----------|---------|---------|-------------------"
152+
`;

e2e/__tests__/coverageReport.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,13 @@ test('generates coverage when using the testRegex config param ', () => {
189189
expect(stdout).toMatchSnapshot();
190190
expect(exitCode).toBe(0);
191191
});
192+
193+
test('outputs coverage report with projects option', () => {
194+
const projectDir = path.resolve(__dirname, '../coverage-with-projects');
195+
const {stdout, exitCode} = runJest(projectDir, ['--no-cache', '--coverage'], {
196+
stripAnsi: true,
197+
});
198+
199+
expect(stdout).toMatchSnapshot();
200+
expect(exitCode).toBe(0);
201+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"jest": {
3+
"projects": [
4+
"<rootDir>/packages/client",
5+
"<rootDir>/packages/server"
6+
],
7+
"collectCoverageFrom": [
8+
"packages/client/**/*.js",
9+
"packages/server/**/*.js"
10+
],
11+
"testEnvironment": "node"
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
function add(a, b) {
9+
return a + b;
10+
}
11+
12+
function subtract(a, b) {
13+
return a - b;
14+
}
15+
16+
module.exports = {add, subtract};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const {add} = require('./client');
9+
10+
test('add function', () => {
11+
expect(add(1, 2)).toBe(3);
12+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node"
4+
}
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
function multiply(a, b) {
9+
return a * b;
10+
}
11+
12+
function divide(a, b) {
13+
return a / b;
14+
}
15+
16+
module.exports = {divide, multiply};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
const {multiply} = require('./server');
9+
10+
test('multiply function', () => {
11+
expect(multiply(2, 3)).toBe(6);
12+
});

0 commit comments

Comments
 (0)