Error when using jest + collectCoverage/babel-plugin-lodash
See original GitHub issueI posted this issue before on https://github.com/facebook/jest/issues/3959 and https://github.com/lodash/babel-plugin-lodash/issues/179
Using babel-plugin-lodash, collectCoverage enabled and a lodash function as show below imported from test file, results into an error.
import { flow, flatten } from 'lodash/fp'
export const testFunction1 = flatten
// export const testFunction2 = flow(flatten)
example#testFunction1 npm test
will output
/home/nam/projects/jest-babel-lodash-issue/src/example.js:3
var testFunction1 = /* istanbul ignore next */exports.testFunction1 = ();
^
SyntaxError: Unexpected token )
example#testFunction2 npm test
will output
ReferenceError: /home/nam/projects/jest-babel-lodash-issue/src/example.js: Container is falsy
at NodePath._replaceWith (node_modules/babel-traverse/lib/path/replacement.js:170:11)
Removing collectCoverage
from package.json
lets the tests run without failure.
Removing babel-plugin-lodash from .babelrc or importing directly from lodash also runs without failure.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Configuring Jest
Indicates whether the coverage information should be collected while executing the test. Because this retrofits all executed files with coverage ...
Read more >Configuring Jest compiled - w3resource
In this tutorial we will focus on configuring Jest. Jest's configuration can be defined inside the package.json file of your project, ...
Read more >Invalid or unexpected token while Jest migration
Adding these plugins in babel.config solved the issue for me 'transform-class-properties', 'babel-plugin-parameter-decorator'.
Read more >jest lodash-es - You.com | The AI Search Engine You Control
I am writing a library using typescript, jest and lodash and I would like to ... Here's the Jest error, related to Jest...
Read more >Configuring Jest
When using the --config option, the JSON file must not contain a "jest" key: ... can be used here to have Jest stop...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ran into this too with babel-plugin-dotenv-import (which is very similar to
react-native-dotenv
). The solution is to import all dotenv defines in a single file and then ignore that file for coverage:Have you tried moving the
babel-plugin-lodash
plugin to a non-test environment config?then when running tests, use:
https://github.com/namjul/jest-babel-lodash-issue/issues/1 https://github.com/facebook/jest/issues/3959#issuecomment-317018979