jest: [Bug]: `--coverage` regression in jest v28.1.2

The --coverage flag has become unusable for us on the Apollo Server project as of the most recent patch. Tests fail unexpectedly with an unhelpful error.

Version

28.1.2

Steps to reproduce

  1. git clone git@github.com:apollographql/apollo-server.git && cd apollo-server && git checkout 19143b99100310fb54b62caab4f306adc12fe954 && npm i (clone / init repo, checkout known good state commit)
  2. ALLOW_CONSOLE=true npm run test:ci (this runs jest with --coverage)
  3. Note tests all passing
  4. npm i -D jest@28.1.2 jest-config@28.1.2 (update from 28.1.1 to 28.1.2)
  5. ALLOW_CONSOLE=true npm run test:ci
  6. Note surprising test failures with incomprehensible errors like the following:
 FAIL  packages/server/src/__tests__/express/integration.test.ts
  ● Test suite failed to run

    No element indexed by 57

      at ArraySet_at [as at] (../../node_modules/source-map/lib/array-set.js:109:9)
      at BasicSourceMapConsumer.SourceMapConsumer_originalPositionFor [as originalPositionFor] (../../node_modules/source-map/lib/source-map-consumer.js:673:30)
          at Array.map (<anonymous>)
          at Function.getOwnPropertyDescriptors (<anonymous>)

Expected behavior

I expect the latest version of jest to work as it has on the previous patch when using the --coverage flag

Actual behavior

Jest fails tests unexpectedly with unhelpful errors

Additional context

Possibly related, though this only happened to us on the most recent patch: https://github.com/facebook/jest/issues/12925

The proposed workaround of installing babel dependencies to the project did not work for us.

Environment

System:
    OS: macOS 12.3.1
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 16.15.1 - ~/Desktop/ApolloRepos/apollo-server/.volta/tools/image/node/16.15.1/bin/node
    npm: 8.13.1 - ~/Desktop/ApolloRepos/apollo-server/.volta/tools/image/npm/8.13.1/bin/npm
  npmPackages:
    jest: ^28.1.2 => 28.1.2

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

The bug isn’t in jest - it’s via babel/trace-mapping. All of which are in semver ranger

The bug is https://github.com/jridgewell/trace-mapping/commit/165983e26d98abf2157c91469c1670f60235d8b0. Combined with presortedDecodedMap used by @ampproject/remapping v2.1.2 to generate based on a {...map} clone of a TraceMap instance. This incorrectly detects the clone as a TraceMap, and returns the instance, which contains private data that’s now incorrect for the new mappings.

Note that presortedDecodedMap is no longer used by remapping (I upgraded it to use @jridgewell/gen-mapping). I’ll fix the bug in trace-mapping, but this can also be resolved by upgrading the @ampproject/remapping transitive dependency (through @babel/core).

Just seeing this, I’ll take a look.