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).
Fix upstream: https://github.com/istanbuljs/babel-plugin-istanbul/pull/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
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...
~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
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
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/"
}
👋 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.
Since this has been fixed upstream you can now use this with yarn in package.json:
"resolutions": {
"babel-plugin-istanbul": "4.1.6"
}
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.
@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)
Oh, good point.
@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?
i am not sure what we are suppose to do i am using jest 24.9.0 and i still have the error
Most helpful comment
Awesome, thanks @bcoe! Bump in jest handled in #5799.
@rbong or just
yarn upgradeoryarn remove jest && yarn add --dev jest. It's within semver range, soresolutionsshouldn't be needed.