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

Rest properties are broken with Jest + node v6 #3694

Closed
vinhlh opened this issue Jan 5, 2018 · 18 comments
Closed

Rest properties are broken with Jest + node v6 #3694

vinhlh opened this issue Jan 5, 2018 · 18 comments

Comments

@vinhlh
Copy link

vinhlh commented Jan 5, 2018

Is this a bug report?

Might be

Environment

  • node v6.12.3
  • react-scripts v1.0.17

Steps to Reproduce

Add this test

it('run without crashing', () => {
  const arrayOfObjects = [{ awesome: true }]
  const [{ awesome, ...rest}] = arrayOfObjects

  expect(true).toBe(true)
});

Expected Behavior

No error

Actual Behavior

      const [{ awesome, ...rest }] = arrayOfObjects;
                        ^^^

    SyntaxError: Unexpected token ...
@miraage
Copy link

miraage commented Jan 5, 2018

Either update Node to 8.9+ or only use syntax supported by your Node version since no transformations being run against your tests code.

Node versions manager to consider:
https://github.com/creationix/nvm (I personally prefer this)
https://github.com/tj/n

@Timer
Copy link
Contributor

Timer commented Jan 5, 2018

Sounds like a bug to me; maybe we need to bump the version of babel-preset-env or make sure this transform is included during tests?

@miraage
Copy link

miraage commented Jan 5, 2018

@vinhlh looks like I misunderstood your question. Is your test file located outside src directory?
AFAIK babel only applies to files inside src.

@werne2j
Copy link

werne2j commented Jan 6, 2018

@Timer i'd like to take this issue if no one else has. This issue happens even if the test is inside the src directory.

@Timer
Copy link
Contributor

Timer commented Jan 7, 2018

All yours, @werne2j! Let me know your findings. 😄

@werne2j
Copy link

werne2j commented Jan 10, 2018

@Timer i may need some help with this issue. To me, it looks like the issue is in
react-scripts/scripts/util/createJestConfig.js involving the testMatch.
When i revert the test match to what it was before this commit
5c8000f#diff-40a56a7d41499eab85303b5e977f9742
the tests seem to work fine.

Not sure if that is the actual issue but thats what i have seen so far

@Timer
Copy link
Contributor

Timer commented Jan 11, 2018

That sounds odd @werne2j, what would a test match have to do with syntax features? 🤔

@werne2j
Copy link

werne2j commented Jan 11, 2018

@Timer it shouldn't have anything to do with it. Thinking about it, i'm sure that is not the issue but i can't seem to figure out what the real issue is

@gaearon gaearon modified the milestones: 1.0.x, 1.0.18 Jan 14, 2018
@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

Confirmed I reproduce this on master.

@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

Can reproduce on next too.

@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

This looks like babel/babel#7099 to me.

@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

Pushing this back to 2.x since it's a legit Babel bug and probably not fixable on our side. We'll need to wait for it to get resolved upstream.

@gaearon gaearon modified the milestones: 2.x, 2.0.0, 1.0.18 Jan 14, 2018
@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

Apparently we can work around this by always including the destructuring transform.
Here's why: babel/babel#7215 (comment)

@Timer
Copy link
Contributor

Timer commented Jan 14, 2018

Fixed via #3788

@Timer Timer closed this as completed Jan 14, 2018
@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

Just ported to next, hopefully it works

@werne2j
Copy link

werne2j commented Jan 14, 2018

I thought I tried this but I must not have been testing it correctly. Glad you were able to get it working @gaearon! Thanks for the help!

@gaearon
Copy link
Contributor

gaearon commented Jan 14, 2018

No problem, thanks for trying!

@gaearon
Copy link
Contributor

gaearon commented Jan 15, 2018

This is out in react-scripts@1.1.0! Please let us know if something doesn’t quite work.
https://github.com/facebookincubator/create-react-app/releases/tag/v1.1.0

@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants