Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sonic1981 opened this issue Jun 8, 2022 · 14 comments
Closed

Comments

@sonic1981
Copy link

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 sonic1981 changed the title [Bug]: Enabling the code-coverage flag without babel installed produces and error [Bug]: Enabling the code-coverage flag without babel installed produces a error Jun 8, 2022
@eric-gt
Copy link

eric-gt commented Jun 9, 2022

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.

devalevenkatesh added a commit to aws/amazon-chime-sdk-component-library-react that referenced this issue Jun 10, 2022
- Fix jest config to address source map issue while running unit tests.
- Had to lower the `functions` coverage, after moving from `babel` to `v8`
for coverage checking.
- If `v8` is not used in jest it falls back to use babel and needs three
more dependencies to install:
```
npm install --save-dev babel-jest @babel/core @babel/preset-env
```

Source: https://stackoverflow.com/questions/72491664/jest-fails-coverage-reports-with-no-element-indexed/72500248#72500248
Issue: jestjs/jest#12925
@vertic4l
Copy link

vertic4l commented Jul 1, 2022

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.

@github-actions
Copy link

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 github-actions bot added the Stale label Jul 31, 2022
@sonic1981
Copy link
Author

Not stale

@github-actions github-actions bot removed the Stale label Jul 31, 2022
@daraclare
Copy link

Not stale, having the exact same issue.

@amustaque97
Copy link

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 :)

frederikprijck added a commit to auth0/auth0-spa-js that referenced this issue Aug 25, 2022
@github-actions
Copy link

github-actions bot commented Sep 8, 2022

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 github-actions bot added the Stale label Sep 8, 2022
@SimenB
Copy link
Member

SimenB commented Sep 8, 2022

This sounds like a duplicate of #12998 (comment) - 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 SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2022
@dzienisz
Copy link

I have the same error

@SimenB
Copy link
Member

SimenB commented Sep 12, 2022

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

@sonic1981
Copy link
Author

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

@SimenB
Copy link
Member

SimenB commented Sep 13, 2022

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.

@sonic1981
Copy link
Author

I'll give it a go

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants