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

jest + collectCoverage with babel-plugin-lodash results into error #3959

Closed
namjul opened this issue Jul 3, 2017 · 3 comments
Closed

jest + collectCoverage with babel-plugin-lodash results into error #3959

namjul opened this issue Jul 3, 2017 · 3 comments

Comments

@namjul
Copy link

namjul commented Jul 3, 2017

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: lodash/babel-plugin-lodash#179

@thymikee
Copy link
Collaborator

thymikee commented Jul 3, 2017

I think babel-plugin-istanbul is the place you should place this issue

@AndersDJohnson
Copy link

AndersDJohnson commented Jul 21, 2017

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


istanbuljs/babel-plugin-istanbul#116 (comment)
namjul/jest-babel-lodash-issue#1

andreineculau pushed a commit to tobiipro/support-firecloud that referenced this issue Apr 10, 2018
@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 May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants