jest
jest copied to clipboard
[Bug]: Enabling the code-coverage flag without babel installed produces a error
Version
28.1.0
Steps to reproduce
- Install jest but do not install babel
- 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
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.
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.
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.
Not stale
Not stale, having the exact same issue.
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 :)
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.
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.
I have the same error
If it does not, please open up a new issue with a reproduction.
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
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.
I'll give it a go
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.