Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- `[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))
- `[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))
- `[jest-util]` Make sure `process.features.require_module` is `false` ([#15867](https://github.com/jestjs/jest/pull/15867))
- `[jest-config]` Keep CLI coverage output when using `--json` with `--outputFile` ([#15918](https://github.com/jestjs/jest/pull/15918))

### Chore & Maintenance

Expand Down
18 changes: 18 additions & 0 deletions e2e/__tests__/__snapshots__/coverageReport.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,21 @@ Functions : 50% ( 3/6 )
Lines : 60% ( 12/20 )
================================================================================"
`;

exports[`prints coverage when using --outputFile with --json 1`] = `
"-------------------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------------------------|---------|----------|---------|---------|-------------------
All files | 60 | 0 | 50 | 60 |
coverage-report | 47.36 | 0 | 25 | 50 |
file.js | 100 | 100 | 100 | 100 |
notRequiredInTestSuite.js | 0 | 0 | 0 | 0 | 8-19
otherFile.js | 100 | 100 | 100 | 100 |
sum.js | 87.5 | 100 | 50 | 100 |
sumDependency.js | 0 | 0 | 0 | 0 | 8-13
coverage-report/cached-duplicates/a | 100 | 100 | 100 | 100 |
identical.js | 100 | 100 | 100 | 100 |
coverage-report/cached-duplicates/b | 100 | 100 | 100 | 100 |
identical.js | 100 | 100 | 100 | 100 |
-------------------------------------|---------|----------|---------|---------|-------------------"
`;
15 changes: 15 additions & 0 deletions e2e/__tests__/coverageReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,18 @@ test('generates coverage when using the testRegex config param ', () => {
expect(stdout).toMatchSnapshot();
expect(exitCode).toBe(0);
});

test('prints coverage when using --outputFile with --json', () => {
const outputFileName = 'sum.result.json';
const outputFilePath = path.join(DIR, outputFileName);

const {stdout, exitCode} = runJest(DIR, [
'--json',
`--outputFile=${outputFileName}`,
'--coverage',
]);

expect(stdout).toMatchSnapshot();
expect(exitCode).toBe(0);
fs.unlinkSync(outputFilePath);
});
14 changes: 14 additions & 0 deletions packages/jest-config/src/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ it('sets coverageReporters correctly when argv.json is set', async () => {
expect(options.coverageReporters).toEqual(['json', 'lcov', 'clover']);
});

it('keeps text coverage reporter when argv.json and outputFile are set', async () => {
const {options} = await normalize(
{
rootDir: '/root/path/foo',
},
{
json: true,
outputFile: 'results.json',
} as Config.Argv,
);

expect(options.coverageReporters).toEqual(['json', 'text', 'lcov', 'clover']);
});

describe('rootDir', () => {
it('throws if the options is missing a rootDir property', async () => {
expect.assertions(1);
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-config/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,9 @@ export default async function normalize(
newOptions.testMatch = [];
}

// If argv.json is set, coverageReporters shouldn't print a text report.
if (argv.json) {
// If argv.json is set without an outputFile, coverageReporters shouldn't print
// a text report to avoid polluting the JSON written to stdout.
if (argv.json && !argv.outputFile) {
newOptions.coverageReporters = (newOptions.coverageReporters || []).filter(
reporter => reporter !== 'text',
);
Expand Down
Loading