Skip to content

[Bug]: Different reporter order leads to coverageMap missing in custom reporter starting in Jest 28 #14052

@danieldiekmeier

Description

@danieldiekmeier

Version

29.5.0

Steps to reproduce

  1. Clone repo: https://github.com/danieldiekmeier/jest-custom-reporter-reproduction
  2. npm i
  3. npm test

In the output and in the reporter.js file, you can see that I had to use a setInterval to keep my custom reporter running until after the CoverageReporter is finished collecting the coverage. In Jest 27, this wasn't necessary – by the time my custom reporter ran, the CoverageReporter was already finished.

Expected behavior

I expect my custom reporters to run last (like they did in Jest 27). Alternatively, it'd be fine if I could influence the order somehow.

Actual behavior

The coverage reporter runs after my custom reporter, making it impossible to use its results in custom reporters.

Additional context

This is the new code in Jest >=28.0.0, which registers the CoverageReporter after the custom reporter: https://github.com/facebook/jest/blob/v28.0.0/packages/jest-core/src/TestScheduler.ts#L329-L364

Up until Jest 27.5.1, the code looked like this, registering the CoverageReporter first: https://github.com/facebook/jest/blob/v27.5.1/packages/jest-core/src/TestScheduler.ts#L349-L380

This is probably a duplicate of the automatically closed #13479.

Environment

System:
  OS: macOS 13.3
  CPU: (10) arm64 Apple M1 Pro
Binaries:
  Node: 16.19.1 - ~/.asdf/installs/nodejs/16.19.1/bin/node
  npm: 9.6.0 - ~/.asdf/plugins/nodejs/shims/npm
npmPackages:
  jest: ^29.5.0 => 29.5.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions