question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Using --outputFile --json suppresses CLI coverage output

See original GitHub issue

Version

27.5.1

Steps to reproduce

  1. Clone https://github.com/wilhen01/jest-outputfile-bug-repro
  2. npm install
  3. npm run test-outputfile to see output using --outputFile --json
  4. npm run test-no-outputfile to see output without those flags

Expected behavior

With code coverage configured. via jest.config.js I would expect to see CLI coverage output, regardless of the use of --outputFile --json

e.g.

 PASS  test/hello.test.ts
  hello world function
    ✓ returns the correct string (1 ms)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |     100 |      100 |     100 |     100 |
 index.ts |     100 |      100 |     100 |     100 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.83 s, estimated 2 s
Ran all test suites.

Actual behavior

When using --outputFile --json the CLI coverage output is suppressed. Regular test output on the command line remains.

e.g.

❯ npm run test-outputfile

> jest-outputfile-bug-repro@1.0.0 test-outputfile
> jest --outputFile test-results.json --json

 PASS  test/hello.test.ts
  hello world function
    ✓ returns the correct string (1 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.935 s, estimated 3 s
Ran all test suites.
Test results written to: test-results.json

Additional context

No response

Environment

System:
    OS: macOS 12.2
    CPU: (10) x64 Apple M1 Pro
  Binaries:
    Node: 14.19.0 - ~/.nvm/versions/node/v14.19.0/bin/node
    npm: 8.5.0 - ~/.nvm/versions/node/v14.19.0/bin/npm
  npmPackages:
    jest: latest => 27.5.1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:19

github_iconTop GitHub Comments

1reaction
andersondanilocommented, Dec 20, 2022

While the PR is not merged, an workarround to get the same file can be:

jest --coverage --testResultsProcessor=my-results-processor.js

my-results-processor.js

const { writeFileSync } = require('fs')
const { join } = require('path')
const { formatTestResults } = require('@jest/test-result')

module.exports = (testResults) => 
  writeFileSync(
    join(process.cwd(), 'coverage', 'my-result.json'),
    JSON.stringify(formatTestResults(testResults))
  )

  return testResults
}
1reaction
SimenBcommented, Aug 28, 2022

There is #12536 fwiw

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest ---outputFile removes CLI coverage output - Stack Overflow
With --outputFile specified code coverage is still run and results are put in the coverage directory, but the CLI output doesn't include ...
Read more >
Clang-Tidy — Extra Clang Tools 16.0.0git documentation
Some clang-tidy checks provide a check-specific way to silence the diagnostics, e.g. bugprone-use-after-move can be silenced by re-initializing the variable ...
Read more >
Changelog - Node Tap
Do not limit the --coverage-report option to just the built-in reporters. ... Friendlier output on invalid argument assertion failures from the tap CLI....
Read more >
TSConfig Reference - Docs on every TSConfig option
It has no interaction with the include , exclude , or files tsconfig.json settings. Note that TypeScript will never write an output file...
Read more >
Release notes & updates – Azure CLI - Microsoft Learn
June 4, 2019. Version 2.0.66. Core. Fixed bug where commands fail if --output yaml is used with --query ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found