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

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

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 3
  • Comments: 19 (10 by maintainers)

Most upvoted comments

I, at @danieldiekmeier​s previous company (Hi Daniel! 👋), still care though 😅

@i-dont-know-javascript Hello! My solution was to stop using Jest. I never planned to open a PR about this, but even getting this bug triaged/acknowledged took literally MONTHS. I no longer care either way.

Still needs triage!

This can’t be stale, it’s still in triage!

Thanks for reminding this issue. It was me who changed order of reporters some time ago.

Reverting it would be a breaking change. I think the problem is not the order, but the fact one of built-in reporters is adding coverage data to aggregatedResult. It sounds like better idea to populate the coverageMap before calling the onRunComplete method of each reporter. For example, here:

https://github.com/facebook/jest/blob/257f250a977264656eca386629c7ce3b6481f21b/packages/jest-core/src/ReporterDispatcher.ts#L83-L92

I will try to put this together. That is a breaking change as well, so it has to wait till next major.

thank you very much, you da real MVP! ❤️

Maybe time to switch to Vitest?

psssst, not here on literally the jest bugtracker!!1! 🤫 (yes for new stuff, but some things will probably™ stay for a while longer in jest)

Hi Kai, I hope you have a great vacation! If my mitigation is still in your code, I’m proud and sorry. 😄 ~Maybe time to switch to Vitest?~

I updated the reproduction (https://github.com/danieldiekmeier/jest-custom-reporter-reproduction) to Jest v30, and the problem is indeed still the same. I also expanded the README to better contrast the two different behaviours of v27 and >=v28. (Since it’s been two years, I needed a few minutes to remember 😄)

I, at @danieldiekmeier​s previous company (Hi Daniel! 👋), still care though 😅

@Schweinepriester

just curious if you still care?