Skip to content

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

@wilhen01

Description

@wilhen01

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

> [email protected] 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions