jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: Enabling the code-coverage flag without babel installed produces a error

Open sonic1981 opened this issue 2 years ago • 6 comments

Version

28.1.0

Steps to reproduce

  1. Install jest but do not install babel
  2. Run the following command npx jest --collect-coverage

Expected behavior

Code coverage should work

Actual behavior

You receive the error:

DeleteById › it should throw an ArgumentError if any of inputs are null

    No element indexed by 26

      at ArraySet.at (node_modules/@cspotcode/source-map-consumer/lib/array-set.js:88:11)
      at BasicSourceMapConsumer.originalPositionFor (node_modules/@cspotcode/source-map-consumer/lib/source-map-consumer.js:508:30)
      at mapSourcePosition (node_modules/@cspotcode/source-map-support/source-map-support.js:297:42)
      at wrapCallSite (node_modules/@cspotcode/source-map-support/source-map-support.js:461:20)
      at Function.prepareStackTrace (node_modules/@cspotcode/source-map-support/source-map-support.js:541:41)
      at getThrown (node_modules/expect/build/toThrowMatchers.js:31:60)
      at Object.<anonymous> (node_modules/expect/build/toThrowMatchers.js:57:16)
      at __EXTERNAL_MATCHER_TRAP__ (node_modules/expect/build/index.js:346:30)

Additional context

Installing babel npm install --save-dev babel-jest @babel/core @babel/preset-env fixes this issue.

The default provider is babel for this source but this is not listed as a dependancy.

It could be good enough to produce a more meaningful error message.

Environment

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 16.13.2 - ~/.asdf/installs/nodejs/16.13.2/bin/node
    npm: 8.1.2 - ~/.asdf/plugins/nodejs/shims/npm
  npmPackages:
    jest: ^28.1.0 => 28.1.0

sonic1981 avatar Jun 08 '22 10:06 sonic1981

I experienced this error suddenly migrating from [email protected] to [email protected].

the following test, which expects a Promise to reject with an instance of a custom Error

if('should return an error when requesting a writeable stream for an unsupported provider', async () => {
  await expect (
    async () => await provider.getWritableStream(StorageType.NONE, {})
  ).rejects.toThrow(CustomErrorType);
}):

returns the error

    No element indexed by 34

      at ArraySet_at [as at] (../node_modules/jest-runner/node_modules/source-map/lib/array-set.js:109:9)
          at Array.map (<anonymous>)
      at getThrown (../node_modules/expect/build/toThrowMatchers.js:31:60)

when running jest --coverage

All tests pass when running jest without the --coverage flag.

Setting coverageProvider to v8 in the jest config fixes the error.

I'm trying to write a minimal case repro but I'm having trouble reproducing it in a vanilla Node & Typescript project.

eric-gt avatar Jun 09 '22 17:06 eric-gt

Interestingly, babel-jest @babel/core @babel/preset-env comes with jest-config and ts-jest which we are using. But one of our colleagues has the exact same issue No element indexed by 26 and we don't know what's causing it.

vertic4l avatar Jul 01 '22 14:07 vertic4l

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 31 '22 14:07 github-actions[bot]

Not stale

sonic1981 avatar Jul 31 '22 16:07 sonic1981

Not stale, having the exact same issue.

daraclare avatar Aug 08 '22 16:08 daraclare

I faced a similar issue; in my case, I could fix the test case by removing console.log statements from the code. Because of console.log in my test case promises were getting rejected instead of resolved. Once I removed that, test case is passing now :)

amustaque97 avatar Aug 09 '22 04:08 amustaque97

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Sep 08 '22 04:09 github-actions[bot]

This sounds like a duplicate of https://github.com/facebook/jest/issues/12998#issuecomment-1212426850 - can you update @jridgewell/trace-mapping and see if that fixes it for you?

If it does not, please open up a new issue with a reproduction.

SimenB avatar Sep 08 '22 08:09 SimenB

I have the same error

dzienisz avatar Sep 12 '22 20:09 dzienisz

If it does not, please open up a new issue with a reproduction.

SimenB avatar Sep 12 '22 20:09 SimenB

If it does not, please open up a new issue with a reproduction.

Hi @SimenB

I think you're misunderstanding the issue. The fix in that pr is a fix in Babel. I'm saying I shouldn't need to install Babel to get this to work, or at least I'd expect jest to tell me that the problem can be fixed by installing Babel.

My understanding is that jest should work correctly, including code coverage, using V8.

So this does not fix the issue I'm afraid

sonic1981 avatar Sep 13 '22 05:09 sonic1981

Then please open up a reproducing repo like the template asks you to. Your current steps don't.


That said, it is listed as a dependency within Jest: https://github.com/facebook/jest/blob/c8452412fa0e0f56955a3975aec996d4ec5b6702/packages/jest-transform/package.json#L20

All your installation command in the OP does is update the versions

The bug is in an older version of dependencies, not in Jest - so just update the versions in your lockfile. The bugged dependencies have been fixed so your steps to reproduce no longer do.

SimenB avatar Sep 13 '22 06:09 SimenB

I'll give it a go

sonic1981 avatar Sep 13 '22 06:09 sonic1981

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Oct 14 '22 00:10 github-actions[bot]