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

Object spread error when collecting coverage with configured transform #5082

Closed
nwoltman opened this issue Dec 14, 2017 · 13 comments · Fixed by istanbuljs/babel-plugin-istanbul#141

Comments

@nwoltman
Copy link

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Tests fail to run and give the following error:

 FAIL  test\test.js
  ● Test suite failed to run

    jest-object-spread-bug/index.js: Unexpected token (7:2)
        5 | module.exports = {
        6 |   b: 2,
      > 7 |   ...obj,
          |   ^
        8 | };
        9 |

If the current behavior is a bug, please provide the steps to reproduce through a minimal
repository on GitHub that we can yarn install and yarn test.

Please see this demo repo: https://github.com/nwoltman/jest-object-spread-bug

What is the expected behavior?

Tests pass with 100% code coverage.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Jest 21.2.1
Node 8.9.1 (which supports object spread syntax)
OS: Windows 10, Ubuntu 17.10

jest.config.js

module.exports = {
  collectCoverage: true,
  testEnvironment: 'node',
  transform: {},
};

The error only occurs while collecting coverage.
The error does not occur if transform is not set.


Related to issue #4248 which was partially fixed by PR #4519.

This issue is also sort of like reopening #5070 since you shouldn't have to use your own transformer to transform object spread syntax if it is natively supported by Node (especially since tests work just fine when not collecting coverage).

@SimenB
Copy link
Member

SimenB commented Dec 17, 2017

Fix upstream: istanbuljs/babel-plugin-istanbul#141

If that is rejected, we can add the plugin on our side in here: https://github.com/facebook/jest/blob/df9234006a9c8592ede2539b0fb0832852272c77/packages/jest-runtime/src/script_transformer.js#L170-L180

@ChristopheBougere
Copy link

Same issue here, hope this will be released soon :)
Is there a simple way to use your fix in jest/packages/jest-runtime/src/script_transformer.js while it is not released? (I can install jest package from df9234006a9c8592ede2539b0fb0832852272c77, but the fix is in jest-runtime...

@SimenB
Copy link
Member

SimenB commented Dec 20, 2017

If you use yarn, you can do

"resolutions": {
  "babel-plugin-istanbul": "SimenB/babel-plugin-istanbul#f467aee1e356f173ceb07f549894c597fae66311"
}

Wait no, sorry. They transpile, so installing from github won't work. You can publish my fork though, then you can use resolutions

@ChristopheBougere
Copy link

Thanks but we're using npm.
However, we noticed that when installing jest locally it works, but with jest installed globally it fails.
I don't understand yet the reason (maybe a version of a sub-dependency...).
This can do the trick in the meantime

@rumax
Copy link

rumax commented Dec 24, 2017

Same issue:

"scripts": {
    "test": "jest",
...

"jest": {
    "coverageDirectory": "./coverage/",
    "collectCoverage": true
 }

"devDependencies": {
  "jest": "^22.0.4"

Node version is v8.9.1

npm test fails

      > 12 |     ...params,
           |     ^

Unexpected token

Without collectCoverage tests are green.

"jest": {
    "coverageDirectory": "./coverage/"
  }

@bcoe
Copy link
Contributor

bcoe commented Mar 9, 2018

👋 I just landed the upstream work @SimenB did on babel-plugin-istanbul, I've also given @SimenB commit access to the repo; sorry for blocking you for so long.

@rbong
Copy link

rbong commented Mar 17, 2018

Since this has been fixed upstream you can now use this with yarn in package.json:

  "resolutions": {
    "babel-plugin-istanbul": "4.1.6"
  }

@SimenB
Copy link
Member

SimenB commented Mar 18, 2018

Awesome, thanks @bcoe! Bump in jest handled in #5799.

@rbong or just yarn upgrade or yarn remove jest && yarn add --dev jest. It's within semver range, so resolutions shouldn't be needed.

@rbong
Copy link

rbong commented Mar 20, 2018

@SimenB I tried your solution, 4.1.6 is still tagged with "next" on npm so unfortunately resolutions are required in the short term until #5799 gets in or babel-plugin-istanbul tags 4.1.6 as "latest" (afaik)

@SimenB
Copy link
Member

SimenB commented Mar 20, 2018

Oh, good point.

@bcoe
Copy link
Contributor

bcoe commented Apr 7, 2018

@rbong @SimenB sorry for the slow turnaround, I just tagged 4.1.6 as latest on npm -- mind letting me know if this gets things working for you?

@flozero
Copy link

flozero commented Jul 21, 2020

i am not sure what we are suppose to do i am using jest 24.9.0 and i still have the error

@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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants