-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Unexpected token import when running Non-Related React tests #2524
Comments
Unfortunately, we're not able to provide support for using Mocha in conjunction with CRA. I would suggest you stop trying to fight against our configuration and utilize Jest, or switch to a different project. With that said, I noticed a few things: This looks like you're trying to use This is due to improper babel configuration (a missing plugin; see comments below). I'm not sure why your tests are working locally but not in Travis; are you committing all of the files? Also, you should be using |
I think it's unfortunate that the team is so biased to only supporting Jest. A good tool should allow some flexibility especially on test frameworks. That's one of the reasons I don't suggest to clients to get locked into "complete solutions' for things. As far as the screenshots above with the errors, those are from Travis trying to run my build. It was working just fine before with the same test script and this create-react-app, but all of a sudden had a fit. I wonder if it's due to upgrading to Node8 but I doubt it. And I realize Facebook wants people Regardless thanks for taking a look at it |
btw which harmony module syntax are you referring to?
|
It's not that we're bias towards Jest, but it is currently the best test runner for React projects. The purpose of this project is to make opinionated choices and promote zero configuration. It is not feasible for us to track multiple testing frameworks, such as Jest, Mocha, Ava, Karma, etc. There would be too many gaps and potential feature disparity between them.
There's actually many benefits to a "complete solution". As for being "locked into" create-react-app, this is completely false.
You should look back at what commit caused this to start happening, but I'm not sure how the breakage is related to us.
We don't "want people" using
What "solution" are you referring to? I use
Many people eject because we provide excellent defaults & practices and can be used as a fantastic scaffolding solution. Additionally, many people who eject do so wrongly. e.g. for Sass support.
Then it sounds to me like you are disregarding your client's desire to use this tool. Using this tool includes using Jest. Using Mocha is burdening them unnecessarily.
While I respect your opinion, I respectfully disagree. We have no proprietary requirements. Like I said before, you're fighting against the tool instead of working with it. Why are you so opposed to trying Jest? |
|
I can get it working in 1 minute tops..I'd love to know what is so "hard" about it..seriously. |
I am not asking FB to support it. But obviously since everything is closed off, you can't do anything so naturally yea you can't plug anything into this like you could with any custom app. |
no my client doesn't care what I use to test with. I'm the one leading the project. I was just trying to accommodate the use of create-react-app but figured out that I should have never used it to begin with...now I know.
sorry I'll call BS on that always. That's a reason FB uses to say "look Mocha is a pain" when it never was at all. |
This was simply an observation I've made based on this issue (broken testing) and #2167.
I'm not entirely sure how there's anything different with a CRA app versus your own application; both would require setup. I'm going to close this issue because your original concern has been answered. |
I won't get into why I'm opposed to Jest. And if I'm used to mocha or if someone's used to something else, at the least you should keep things open enough so that it allows it. If you want to know what I have against FB and Jest you can read it here: https://www.codementor.io/daveschinkel13/running-mocha-enzyme-with-creat-react-app-84flnngkk you're promoting excuses for developers not to write unit tests. |
one final thing before I stop my rant
right, usually it takes 1 minute but create-react-app closes off everyone. create-react-app is what caused me the pain with mocha, not setting up mocha as I normally do for any project which is dead easy. I get it like I said, but I don't think you should be closing things off to the point where you can't use a different test framework, that's ridiculous...luckily I came up with a work around |
Where are you getting this information from? We actually recommend using enzyme for testing. We actually only have a small section about snapshot testing.
We do not claim that snapshot testing checks any sort of functionality.
Closing things off is that this tool does -- like I said before, if you don't agree with it, switch to a different tool (I know you said you cannot for this project). |
I'm talking about the Jest website, did you read the thread I had with #2167 (comment). It's a waste of time, we're not going to agree on it. Have a good one! |
I still don't see what you're referring to I'm not using the harmony flag. And that link says nothing about babel-core vs. node-babel
What exactly are you referring to, what's wrong with babel-core/register? It's been working fine for me for 2 years. that |
Normally in any react project that is not a create-react-app app, you'd simply add the "ES2015" preset to get rid of this but for some reason, and knowing create-react-app is its own "animal" with how it works with babel under the hood because "everything is automated for you" which leaves me a black hole to deal with.
So that's why I'm posting this here. I have been able to run my react mocha tests just fine after adding the
react-app
preset in my package.json a long time ago. But I can't run my new develop mocha tests, for some reason I keep getting this error still:above is an error during my travis build when it tries to run yarn run test.
This is output from Travis, not my local running of yarn run test.
My setup
I've got deployment code using ES6 imports in src/deploy/ and I have mocha unit tests exercising that code The deploy code is making various calls to aws S3 using their cli API to make calls. Travis looks at my
travis.yml
, and runs these scripts for this apps build process..babelrc
- I added this because adding thereact
preset solved an error where jsx was not parsing in my react for some reason all of a sudden (I don't know why it decided to start to complain) and kept getting the errorunexpected token on <MemoryRouter in app.spec.js
in my test. Adding thereact
preset solved that{
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread"]
}
Adding the "es2015" allowed me to rid the error
Unexpected token import
on my deployment tests when I run them locally...after adding the.babelrc
to solve my other jsx parse error.Adding the
transform-object-rest-spread
was necessary or else my deploy code wasn't able to use the rest-spreadSo I can't fix this error above. If I take out .babelrc or take out "es2015" my tests no longer run locally. If I keep "es2015" + "react" presets, the tests run locally, but fail on travis, the error you see above in the screenshot.
I do not know why all of a sudden this test started to complain with the jsx parsing either:
I also recently upgraded to Node 8 and npm 5.0.3 to take advantage of some of the new utilities.
Any ideas?
The text was updated successfully, but these errors were encountered: