<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Code Guy Luke on Medium]]></title>
        <description><![CDATA[Stories by Code Guy Luke on Medium]]></description>
        <link>https://medium.com/@CodeGuyLuke?source=rss-9fa17c86af95------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GRqdQxfIl6cQ5Ed7NO65Ug.jpeg</url>
            <title>Stories by Code Guy Luke on Medium</title>
            <link>https://medium.com/@CodeGuyLuke?source=rss-9fa17c86af95------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:14:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@CodeGuyLuke/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating React Native app boilerplate with Flow, Jest, Enzyme, Prettier and ESLint]]></title>
            <link>https://medium.com/aurity/creating-react-native-app-boilerplate-with-flow-jest-enzyme-prettier-and-eslint-cefdbce3b3d?source=rss-9fa17c86af95------2</link>
            <guid isPermaLink="false">https://medium.com/p/cefdbce3b3d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[flow]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[jest]]></category>
            <dc:creator><![CDATA[Code Guy Luke]]></dc:creator>
            <pubDate>Mon, 05 Feb 2018 18:32:14 GMT</pubDate>
            <atom:updated>2018-07-10T13:42:46.367Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NlqpTTAM8DbGl4paBmjE_g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/m_HRfLhgABo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Christopher Gower</a> on <a href="https://unsplash.com/search/photos/test?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This has happened to me so many times! I have a new idea for an app or some awesome component, I want to get started as fast as possible, but of course I also want to do it right from the beginning. I end up spending a few hours setting up tests, app structure, linter etc., constantly thinking about that one feature I wanted to create… So much time lost on such obvious, repeatable actions!</p><p>I got tired of this, as many people in my shoes have, so I’ve prepared simple, clean and tidy boilerplate with only one component given as an example. You’ll find it <a href="https://github.com/lnavry/ReactNativeComponentsTester">here</a>. It is designed to be used right out of the box, so you can start quicker with testing your own components or implementing latest Facebook-wannabe idea.</p><p>If you don’t have a time for reading this step-by-step tutorial, you can just <a href="https://github.com/lnavry/ReactNativeComponentsTester">clone this project</a>, install dependencies and begin. With that being said, I recommend you at least take a glance at the guide below. During my research, I’ve found that there are many tutorials telling you how to start your RN project, as well as many separate guides for all the external packages, but no one comprehensive tutorial covering that all together. Well, until now, of course.</p><h3>1. Create React Native project</h3><p>Okie dokie, that’s a surprise, isn’t it? Yep, we need to create a RN project first. Some prefer using create-react-native-app (<a href="https://github.com/react-community/create-react-native-app">repo</a>), but in this tutorial I‘ll stick to the good ol’ react-native init command. We open the terminal in the directory where we want our app to sit in and then run:</p><pre>react-native init RNComponentsTester</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y3GZHHAwaKSFdxfpjcjhXA.png" /></figure><h3>2. ESLint setup</h3><p>Before writing even one line of code, I suggest setting up the linter. It’s a perfect point to start with, as it might save you headache when you start to build your components.</p><p>A widely popular choice is eslint-config-airbnb and I’m not so edgy not to follow. Our ESLint configuration will extend this config, but we will need a few plugins. Since we’re using Flow, it’s a good idea to install eslint-plugin-flowtype. To avoid troubles with imports and JSX syntax, we need to add appropriate plugins. Finally, we install it completely by executing:</p><pre>yarn add --dev eslint babel-eslint eslint-config-airbnb eslint-plugin-flowtype eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react</pre><p>All we have to do now is add .eslintrc file to our projects root directory. The rules defined in that file are completely up to you - there is a solid <a href="https://eslint.org/docs/rules/">documentation</a> on this. My favourite configuration is:</p><pre>{<br>  &quot;parser&quot;: &quot;babel-eslint&quot;,<br>  &quot;extends&quot;: &quot;airbnb&quot;,<br>  &quot;plugins&quot;: [<br>    &quot;react&quot;,<br>    &quot;flowtype&quot;,<br>    &quot;jsx-a11y&quot;,<br>    &quot;import&quot;<br>  ],<br>  &quot;rules&quot;: {<br>    &quot;react/jsx-filename-extension&quot;: [<br>      1, { &quot;extensions&quot;: [&quot;.js&quot;, &quot;.jsx&quot;] }<br>    ],<br>    &quot;react/prefer-stateless-function&quot;: [<br>      2, { &quot;ignorePureComponents&quot;: true }<br>    ],<br>    &quot;react/forbid-prop-types&quot;: [0, { &quot;forbid&quot;: [] }],<br>    &quot;import/extensions&quot;: [1, &quot;never&quot;, { &quot;svg&quot;: &quot;always&quot; }],<br>    &quot;import/no-extraneous-dependencies&quot;: [<br>      &quot;error&quot;,<br>      {<br>        &quot;devDependencies&quot;: true,<br>        &quot;optionalDependencies&quot;: false,<br>        &quot;peerDependencies&quot;: false<br>      }<br>    ],<br>    &quot;semi&quot;: [&quot;error&quot;, &quot;never&quot;]<br>  },<br>  &quot;env&quot;: {<br>    &quot;jest&quot;: true<br>  }<br>}</pre><p>Lastly, create a script in package.json file. This is to be able to quickly run lint through the entire app. Under scripts we simply declare:</p><pre>&quot;scripts&quot;: {<br>  // ...<br>  &quot;lint&quot;: &quot;eslint src&quot;<br>}</pre><p>src here is a directory, where we keep all the code. From this point on we will be able to check our app simply by calling yarn lint .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DIUS5DL3LxUUnxQpDvOk0Q.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/9D9YESB28Ts?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jeremy Bishop</a> on <a href="https://unsplash.com/search/photos/relax?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>3. Prettier</h3><p><a href="https://github.com/prettier/prettier">Prettier</a> is one of the best things to happened in code management. If you have never heard of it, I assure you you’d love it. You don’t need to think about code styling, and you are 100% guaranteed that the syntax will be consistent across all devs working with the same repo. Just relax and focus on what you’re about to build.</p><p>Configuration of prettier is quite straightforward, but to get the most out of it, it’s best to try it with <a href="https://github.com/okonet/lint-staged">lint-staged</a> and <a href="https://github.com/typicode/husky">husky</a> packages. Again, we install them together under devDependencies :</p><pre>yarn add --dev prettier husky lint-staged</pre><p>All the magic happens in package.json and there is no need to change any other file. First, let’s define the rules we want prettier to follow. We create another script:</p><pre>&quot;scripts&quot;: {<br>  // ...<br>  &quot;pretty&quot;: &quot;prettier --semi false --print-width 100 --single-quote<br>    --trailing-comma all --write \&quot;src/**/*.js\&quot;&quot;<br>}</pre><p>The last argument is regex match indicating which files we’d like to pretty. In this case, they are all Javascript files from our src directory. As we have pretty defined, we can take another step and invite lint-staged to the party. We define, next to scripts :</p><pre>&quot;scripts&quot;: {<br>  // ...<br>},<br>&quot;lint-staged&quot;: {<br>  &quot;*.js&quot;: [<br>    &quot;yarn pretty&quot;,<br>    &quot;git add&quot;<br>  ]<br>}</pre><p>Husky is a tool that allows us to define git hooks, like precommit . To use it, another script goes into our package.json :</p><pre>&quot;scripts&quot;: {<br>  &quot;precommit&quot;: &quot;lint-staged &amp;&amp; yarn test&quot;<br>}</pre><blockquote><strong>When using </strong>husky<strong> with </strong>yarn<strong>, you might meet this issue: </strong><a href="https://github.com/typicode/husky/issues/84">https://github.com/typicode/husky/issues/84</a><br><strong>Simply resolve it with </strong>yarn add —-dev husky --force</blockquote><p>Now our code is protected from any styling abuse and we can commit our changes being sure, that all of our mistakes will be automatically fixed and forgiven.</p><p>We have put a lot of work into our project without writing single line of code yet - let’s change that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eTffjjUgwjOmFZXF7zyyNw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/GSyVkoBAWQM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kym Ellis</a> on <a href="https://unsplash.com/search/photos/flow?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>4. Catching the Flow</h3><p>It’s finally time to create some component. I decided to go with a button, since it will be useful to test other components in the future. You can find sources for my AwesomeButton <a href="https://github.com/lnavry/ReactNativeComponentsTester/tree/master/src/components/awesome-button">right here</a>. I won’t spend much time talking on the button itself, but it is given to you in the repo as an example of how you can test your components.</p><p>First, let’s focus on enabling <a href="https://flow.org/en/docs/">Flow</a> for our project. One tip:</p><blockquote>It is extremely simple!</blockquote><p>Like, really. React Native provides already prepared .flowconfig in its root directory. All that’s needed is:</p><ol><li>Open .flowconfig file.</li><li>Scroll down to the very bottom of this file.</li><li>Check the version number.</li></ol><p>Now, that’s the exact flow-bin package version you need to install. In my case, the number was 0.61.0 , so let’s run the command:</p><pre>yarn add --dev flow-bin@0.61.0 babel-preset-flow</pre><p>I tricked you a little. We also need babel-preset-flow, but that’s not a big issue. Just install this package and add a preset in .babelrc file, like so:</p><pre>{<br>  &quot;presets&quot;: [&quot;react-native&quot;, &quot;flow&quot;]<br>}</pre><p>Let’s create two helper scripts to easily run flow-related commands:</p><pre>&quot;scripts&quot;: {<br>  // ...<br>  &quot;flow&quot;: &quot;flow&quot;,<br>  &quot;flow-stop&quot;: &quot;flow stop&quot;<br>}</pre><p>Finally, we’re ready to go. On the <a href="https://flow.org/en/docs/react/components/">flow website</a> you can find information how to use it inside the components, you can also look at my <a href="https://github.com/lnavry/ReactNativeComponentsTester/blob/master/src/components/awesome-button/awesome-button.js">AwesomeButton</a> component. Remember to put the // @flow signature on the top of the file you’re planning to use it in, and you’re good to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSXdBEb340y_cU3vI6up0g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/m_PB-FYlR_Q?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Levi Saunders</a> on <a href="https://unsplash.com/search/photos/clown?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>5. Jest, and the joke’s on you</h3><p>Forget about all the struggles behind you. Now comes the real deal. The <a href="https://facebook.github.io/jest/docs/en/getting-started.html">Jest</a> setup.</p><p>Jest is something that can turn one of your afternoons into a nightmare, but at the same time save you a lot of trouble in the future. To configure Jest and the awesome <a href="https://github.com/airbnb/enzyme">Enzyme</a> library from the Airbnb guys, and get them both to work on your brand new React Native project, just do the following:</p><h4>Install dependencies</h4><pre>yarn add --dev enzyme enzyme-adapter-react-16 enzyme-to-json react-dom</pre><h4>Set Jest configuration in package.json</h4><pre>&quot;scripts&quot;: {<br>  // ...<br>},<br>&quot;jest&quot;: {<br>  &quot;preset&quot;: &quot;react-native&quot;,<br>  &quot;testMatch&quot;: [<br>    &quot;**/?(*.)test.js?(x)&quot;<br>  ],<br>  &quot;snapshotSerializers&quot;: [<br>    &quot;enzyme-to-json/serializer&quot;<br>  ],<br>  &quot;setupFiles&quot;: [<br>    &quot;&lt;rootDir&gt;/jest/setup.js&quot;<br>  ]<br>}</pre><p>A few interesting things happened above. First, we describe the naming convention of test files in our application. ”**/?(*.)test.js?(x)&quot; expression means, that every file with name such as my-component.test.js , my-better-component.test.jsx, /src/components/commons/my-text/test.js etc. will be treated as a test file.</p><p>We can also see the snapshotSerializers field, where we make a use of enzyme-to-json package we have previously installed. Thanks to this serializer, our <a href="https://facebook.github.io/jest/docs/en/snapshot-testing.html">snapshots</a> will take an easily readable form.</p><p>And finally, we specify jests setup file location. We need to create the jest folder inside of our root directory and put setup.js file in there. Inside this file, the only thing we need to add is:</p><pre>import { configure } from &#39;enzyme&#39;<br>import Adapter from &#39;enzyme-adapter-react-16&#39;</pre><pre>configure({ adapter: new Adapter() })</pre><p>This is necessary because of many breaking changes introduced inside React@16 release.</p><p>Finally, we add two final scripts in our package.json file:</p><pre>&quot;scripts&quot;: {<br>  // ...<br>  &quot;test:unit&quot;: &quot;jest&quot;,<br>  &quot;test&quot;: &quot;yarn lint &amp;&amp; yarn flow &amp;&amp; jest&quot;<br>}</pre><p>That’s it! You can check this script by running yarn test from projects root terminal, but remember, the tests will only pass if there is at least one .test.js file created and the tests are defined inside.</p><p>For the example of how to define tests and maintain test files, you can take a look at my <a href="https://github.com/lnavry/ReactNativeComponentsTester/blob/master/src/components/awesome-button/awesome-button.test.js">AwesomeButton tests</a>.</p><p>I hope at this stage you have well-configured React Native app boilerplate, ready for all your ideas, dreams and experiments. You can always compare your code with <a href="https://github.com/lnavry/ReactNativeComponentsTester">this full-proof working example</a>. If you have any questions, please feel free to drop them in the comment section and I’ll answer as soon as possible.</p><p>Enjoy your code!</p><figure><a href="https://www.aurity.co/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e_O-l3j8STKCjkE91X5jdA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cefdbce3b3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/aurity/creating-react-native-app-boilerplate-with-flow-jest-enzyme-prettier-and-eslint-cefdbce3b3d">Creating React Native app boilerplate with Flow, Jest, Enzyme, Prettier and ESLint</a> was originally published in <a href="https://medium.com/aurity">Aurity.co</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>