Do you want to request a feature or report a bug?
bug
What is the current behavior?
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.
If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
https://github.com/namjul/jest-babel-lodash-issue
What is the expected behavior?
Test should run without errors.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Ubuntu 16.04.1 LTS, node v6.11.0 npm 3.10.10 also tested with node v8.1.3 npm 5.0.3
previous issue: https://github.com/lodash/babel-plugin-lodash/issues/179
I think babel-plugin-istanbul is the place you should place this issue
Have you tried moving thebabel-plugin-lodash plugin to a non-test environment config?
{
"plugins": [],
"env": {
"development": {
"plugins": ["lodash"]
},
"production": {
"plugins": ["lodash"]
},
"test": {
"plugins": []
}
}
}
then when running tests, use:
BABEL_ENV=test jest --coverage
Note: If you are using a more complicated Babel configuration, using Babel's env option, keep in mind that Jest will automatically define NODE_ENV as test. It will not use development section like Babel does by default when no NODE_ENV is set.
https://facebook.github.io/jest/docs/en/getting-started.html#additional-configuration
https://github.com/istanbuljs/babel-plugin-istanbul/issues/116#issuecomment-317015896
https://github.com/namjul/jest-babel-lodash-issue/issues/1
Most helpful comment
Have you tried moving the
babel-plugin-lodashplugin to a non-test environment config?then when running tests, use:
https://facebook.github.io/jest/docs/en/getting-started.html#additional-configuration
https://github.com/istanbuljs/babel-plugin-istanbul/issues/116#issuecomment-317015896
https://github.com/namjul/jest-babel-lodash-issue/issues/1