-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Adding jest and jest babel preset to the react-native init command #9719
Adding jest and jest babel preset to the react-native init command #9719
Conversation
By analyzing the blame information on this pull request, we identified @ide and @bestander to be potential reviewers. |
Maybe it’s only me, but I don’t think this should be part of the |
cc @cpojer We were talking about this today. |
We're doing the same with create react app: https://twitter.com/dan_abramov/status/771496951858733057 |
@davidaurelio create-react-app ships like this too and I believe it is a really good default. Most people are confused about testing RN and Jest is the only framework that can provide a real unmocked version of react-native. The mocks we provide for components help with snapshot testing and a lot of people are adopting it. Our open source software should be all about integrated experiences. It shouldn't be about Jest or packager or any one tool, but literally just be one thing that seamlessly works together. If testing isn't a part of this, then that is a decision we have to make, but then we also have to discuss why we ship a packager, dev server and bundler with a UI framework in this repo ;) Ideally I would like the react native CLI to go the same way that create-react-app is going. I think that would be ideal and we could hide this dependency completely from the user. And alternative approach for this PR could be to ship |
packageJSONPath | ||
) | ||
); | ||
packageJSON.scripts.test = 'jest' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;
After personal discussion with @kentaromiura and @cpojer: I would be happy with an opt-out flag. |
After discussing this offline I'll add an opt out flag any suggestion for the name? |
|
|
Worth mentioning that we were talking about adding different kind of templates. I think a minimal template would be useful if we want to have one without jest. |
We need to rework CLI to have responsive/progressive output first. |
Also please add opt-out to e2e tests |
I would really like to decouple adding a test framework from the CLI rewrite because no one is actively working on this and people are continuously asking how to setup react-native testing – this does exactly that for them. With an opt-out, it will be the same as before. In the future we can rewrite the cli and make it more awesome; add separate templates to choose from and more options. For now, I'd like to figure out a way to get this in that makes most people happy so we can move forward and iterate towards the ideal CLI later. I also wanna point out the Jest 15 improvements we made for the react-native preset: http://facebook.github.io/jest/blog/2016/09/01/jest-15.html#jest-react-native-improvements |
@kentaromiura updated the pull request - view changes |
@@ -27,6 +26,11 @@ module.exports = yeoman.generators.NamedBase.extend({ | |||
type: Boolean, | |||
defaults: false | |||
}); | |||
this.option('skip-jest', { | |||
desc: 'Skip installing jest', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Jest" (capitalized) in writing please. jest
is the name of the cli tool for "Jest".
@kentaromiura and @cpojer, that is a huge improvement to the platform, having an idiomatic test tool, I am sure the community will be happy. A few concerns:
That is my point. |
@bestander I think what you recommend makes sense. We should add some more progress output during npm install, but that should happen in a separate PR.
|
|
Oh yeah. We should literally just make sure the default component doesn't throw: https://github.com/facebookincubator/create-react-app/blob/master/template/src/App.test.js#L5 – that is an awesome example and doesn't overwhelm people. |
@kentaromiura updated the pull request - view changes |
@cpojer I totally agree, ship this now and we can add templates later. Thanks a lot for doing this @kentaromiura. |
There are three issues here:
I agree that 1 is not an option for this PR. |
|
Re 3, If you add a simple |
@kentaromiura updated the pull request - view changes |
@kentaromiura updated the pull request - view changes |
That is amazing, @kentaromiura, so easy to create a snapshot test now! |
This is awesome indeed. I have one recommendation: a lot of beginners use react and a lot of people in general aren't sure what the value of testing is. Snapshot testing is definitely the right answer to test react components, however I believe we shouldn't ship with a default one. I did this in my initial PR to create-react-app but @gaearon brought up some really good points that they will be confusing. One concern is that undoubtedly this test will fail as soon as someone starts modifying their app and there isn't much value in this initial test. Instead, can we change it so it doesn't have an assertion at all and simply makes sure rendering doesn't throw? See https://github.com/facebookincubator/create-react-app/blob/master/template/src/App.test.js We can then add documentation on how to use snapshot testing on the website and upsell people into creating snapshots. I think they aren't very valuable when you are just getting started to write code and are much more useful once you are done with a few components. What do you think? |
Also need to add |
@kentaromiura updated the pull request - view changes |
@kentaromiura updated the pull request - view changes |
@facebook-github-bot shipit |
Thanks for importing. If you are an FB employee go to Phabricator to review internal test results. |
@bestander can you follow up and let us know what kind of documentation or announcement we should be preparing and for when? :) |
1 similar comment
@bestander can you follow up and let us know what kind of documentation or announcement we should be preparing and for when? :) |
@cpojer easy :) |
8689b0f
Summary: Adding jest and its presets to the react-native init command **Test plan (required)** run react-native init foo (using `npm link` to use the local `react-native` version) inside foo there are now a .babelrc file and the package.json is set up as described by https://facebook.github.io/jest/docs/tutorial-react-native.html#setup Closes facebook/react-native#9719 Differential Revision: D3843037 Pulled By: bestander fbshipit-source-id: 004e27ebd3f257a202ed43f378d6fe6cc23ced52
Adding jest and its presets to the react-native init command
Test plan (required)
run react-native init foo (using
npm link
to use the localreact-native
version)inside foo there are now a .babelrc file and the package.json is set up as described by
https://facebook.github.io/jest/docs/tutorial-react-native.html#setup