<?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 Nicolas Cuillery on Medium]]></title>
        <description><![CDATA[Stories by Nicolas Cuillery on Medium]]></description>
        <link>https://medium.com/@ncuillery?source=rss-69ddd49628e3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ASLcBxM6IB_CLxxKS-vw6g.jpeg</url>
            <title>Stories by Nicolas Cuillery on Medium</title>
            <link>https://medium.com/@ncuillery?source=rss-69ddd49628e3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 09:03:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ncuillery/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[Golden testing using CachedNetworkImage]]></title>
            <link>https://medium.com/flutter-community/golden-testing-using-cachednetworkimage-1b488c653af3?source=rss-69ddd49628e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b488c653af3</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[visual-regression-testing]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Nicolas Cuillery]]></dc:creator>
            <pubDate>Tue, 01 Sep 2020 02:27:01 GMT</pubDate>
            <atom:updated>2020-09-01T02:27:01.950Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://pub.dev/packages/cached_network_image">cached_network_image</a> is a popular package to handle network images in a Flutter application, it provides:</p><ul><li>Cache on iOS, Android, and recently macOS,</li><li>Placeholder widget and nice fade-out transition to the image,</li><li>Progress download indicator for large images,</li><li>Offline support (cached images can be displayed without an active connection).</li></ul><p>Using it on my Flutter projects has greatly improved the user experience. On the first launch, the app displays the placeholders sized as close as possible to the final images to smoothen the transition when the images are loaded. Then, the subsequent launches are blazing-fast, thanks to the cache (no network requests).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CeahuLknD6u4lcbVu2slYQ.gif" /><figcaption>The first launch of the app (without cache)</figcaption></figure><p>However, such improvement doesn’t come for free, and this package introduces a slight technical overhead: the cached_network_image package relies on the popular <a href="https://pub.dev/packages/flutter_cache_manager">flutter_cache_manager</a> package (by the same author), which, in turn, relies on the yet-another-popular package (and <a href="https://flutter.dev/docs/development/packages-and-plugins/favorites">Flutter Favorite</a>) <a href="https://pub.dev/packages/sqflite">sqflite</a>.</p><p>This is usually not a problem since this machinery is abstracted by the straight-forward API of the CachedNetworkImage widget… except when it comes to testing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cce0e34b63decaf9c24dc003b824b359/href">https://medium.com/media/cce0e34b63decaf9c24dc003b824b359/href</a></iframe><p>The MissingPluginException is the classic exception thrown when accessing to a native library (in our case, sqflite) in a unit test or widget test that doesn’t build any native counterparts.</p><p>Let’s see how to configure our test environment to correctly mock the cache mechanism used by the CachedNetworkImage widget and, as a bonus, configure some stubbing to return a test asset in place of the expected image, so we can generate a golden image of a widget that uses CachedNetworkImage.</p><p><em>Golden testing (a.k.a. visual regression testing) consists of rendering a widget into an image (the golden) and compared this image to the existing one for each subsequent test execution. Check this other article from Flutter Community for more info about golden testing:</em></p><p><a href="https://medium.com/flutter-community/flutter-golden-tests-compare-widgets-with-snapshots-27f83f266cea">Flutter: Golden tests — compare Widgets with Snapshots</a></p><h3>Sandbox application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OiHY5Mhh6i9Zlh7blRhErw.jpeg" /></figure><p>This application is a mono-page application listing some services such as <a href="https://placekitten.com/">https://placekitten.com</a> that deliver images in any resolution declared in the URL itself:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9QvveCQwIAYbjhuqG2HykQ.jpeg" /><figcaption><a href="https://placekitten.com/1280/360">https://placekitten.com/1280/360</a> (credit: <a href="https://placekitten.com/attribution.html">https://placekitten.com/attribution.html</a>)</figcaption></figure><p>The source code is available <a href="http://https//github.com/ncuillery/image_mocker">here</a>.</p><p>The main widget is InsetCard: it is responsible for displaying the characteristics of the service as well as an example image. Moreover, its implementation is tricky and requires a double build cycle:</p><ul><li>the first one to get the intrinsic height of the Inset widget,</li><li>the second one to center this widget at the bottom edge of the Backdrop image.</li></ul><p>Finally, this widget has to be flexible and renders correctly with data of different lengths (short or long name/description, various amount of tags, …). Therefore it’s the perfect candidate for a widget test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*R6qbfyz5Ld6d9dbdKNM0Xg.png" /><figcaption>Anatomy of the InsetCard widget</figcaption></figure><p>The code of this widget is no interest here but can be found on the <a href="https://github.com/ncuillery/image_mocker">app repository</a>. The only thing we need to be aware of is the usage of CachedNetworkImage within the Backdrop widget.</p><p>As we already know, the most basic golden test as below is failing because of the sqflite plugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f36fd237711a5cd793475f0635a80a12/href">https://medium.com/media/f36fd237711a5cd793475f0635a80a12/href</a></iframe><h3>Improve testability</h3><p>Some native packages provide a stubbing API for usage in unit tests or widget tests (like <a href="https://github.com/flutter/plugins/blob/3b931d0a9c10e6a833cff1dffcd8e6a947a43936/packages/shared_preferences/shared_preferences/README.md#testing">shared_preferences</a>) but this is not the case for sqflite. The cached_network_image package doesn’t provide anything either, however, it does allow injecting a custom BaseCacheManager via the <a href="https://pub.dev/documentation/cached_network_image/latest/cached_network_image/CachedNetworkImage/cacheManager.html">cacheManager</a> property! This class is responsible for the caching mechanism and the default implementation is the one who relies on sqflite, see <a href="https://pub.dev/documentation/flutter_cache_manager/latest/flutter_cache_manager/DefaultCacheManager-class.html">DefaultCacheManager</a>.</p><p>The first step then is to use a custom BaseCacheManager when running tests while the app still normally uses the DefaultCacheManager. This can be accomplished with <a href="https://pub.dev/packages/get_it">get_it</a>. This simple package is basically a singleton registry. It may don’t seem useful at first sight (after all, we can create <a href="https://stackoverflow.com/q/12649573/769006">plain Dart singletons</a>) but it quickly becomes indispensable if you’d like to bring the test coverage to a decent level in your project.</p><p>We use get_it to register an instance of DefaultCacheManager in the project main.dart:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/026a9cc606cbd4888d7a639e51fb8c7c/href">https://medium.com/media/026a9cc606cbd4888d7a639e51fb8c7c/href</a></iframe><p>Then we can inject this singleton in the CachedNetworkImage widget:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dee23ebf3bc59a9af67c09de0398153c/href">https://medium.com/media/dee23ebf3bc59a9af67c09de0398153c/href</a></iframe><p>By doing this (see the complete <a href="https://github.com/ncuillery/image_mocker/commit/a24efd4897b9595b01226fea4a54780353b44d2d">diff</a>), the app works exactly the same, we haven’t changed how the CachedNetworkImage works, however, we now have the possibility to declare our own implementation of BaseCacheManager for the widget test, in its main function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/958e97f1601fc590618ccb2bd46f2838/href">https://medium.com/media/958e97f1601fc590618ccb2bd46f2838/href</a></iframe><h3>Writing the TestCacheManager</h3><p>We follow the plan by creating a class that extends BaseCacheManager. This class needs a concrete implementation for the method getFilePath as well as a mandatory positional argument in the constructor. By using the IDE quick fixes, we can write the following without too much hassle:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0865619a1e5b6c92353226bc84eb96b6/href">https://medium.com/media/0865619a1e5b6c92353226bc84eb96b6/href</a></iframe><p>This, however, leads to another error when executing the test. If not provided, the BaseCacheManager creates a CacheStore object used to wrap a CacheInfoRepository:</p><p><a href="https://github.com/Baseflow/flutter_cache_manager/blob/761ca4565f25741ae7b3c402ad2a7f5fbc80afdf/flutter_cache_manager/lib/src/storage/cache_info_repository.dart">Baseflow/flutter_cache_manager</a></p><p>This abstract class is the interface between the BaseCacheManager and the storage. The default implementation is using sqflite and is responsible for the MissingPluginException. It means that we can finally get rid of this dependency by providing a dummy implementation of CacheInfoRepository.</p><p>Good news, this implementation already exists! Its name is NonStoringObjectProvider. It’s the one used to ensure flutter_cache_manager compatibility for Flutter Web. This library on the Web is basically a no-op (image caching on the Web is mostly handled by the browser) but most importantly: it doesn’t crash.</p><p><a href="https://github.com/Baseflow/flutter_cache_manager/blob/761ca4565f25741ae7b3c402ad2a7f5fbc80afdf/flutter_cache_manager/lib/src/storage/non_storing_object_provider.dart">Baseflow/flutter_cache_manager</a></p><p>We can enhance the TestCacheManager to provide an instance of CacheStore which is, in turn, initialized with an instance of NonStoringObjectProvider :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e77ddab1390a3a9f5057b8d9387bbb80/href">https://medium.com/media/e77ddab1390a3a9f5057b8d9387bbb80/href</a></iframe><p><strong>Important note:</strong> During this step, we have imported files that are not exposed by the flutter_cache_manager package. By doing that, we introduced a coupling with the internals of the package, and therefore expose ourselves to breaking changes in future versions (changes that could not be considered as “breaking” in the version changelog or documentation since they don’t concern public API).</p><p>The last barrier that separates us from the green test result is an error due to an undisposed Timer:</p><blockquote>A Timer is still pending even after the widget tree was disposed.</blockquote><p>This is caused by the CacheStore that performs an asynchronous cache clean at some point in the test execution. By default, the WidgetTester asserts that all asynchronous resources must be properly closed at the end of the test. Because we don’t have control over this Timer, we can’t close it manually. We have to wrap the pumpWidget method with a runAsync method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/815238b701f24a3af786cb837794cee9/href">https://medium.com/media/815238b701f24a3af786cb837794cee9/href</a></iframe><p>We finally have a successful test and a generated golden image!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*G9LUr81O7MZZzLm6IpJ-Eg.png" /><figcaption>There is room for improvement though…</figcaption></figure><h3>Improve the golden image</h3><p>There are indeed some aspects that require an inevitable amount of boilerplate when running golden tests. Let’s tackle them one by one:</p><h4>Canvas size</h4><p>The default canvas used to render the widget is 800x600. It is, by sheer coincidence, the same aspect ratio as the Backdrop widget. Therefore, the CachedNetworkImage placeholder takes the whole canvas.</p><p>We can configure a more real realistic value by running the following code on a device: print(MediaQuery.<em>of</em>(context).size);. In the case of the iPhone 11 simulator, it gives a resolution of 414x896.</p><p>Then we can write a utility method to configure the WidgetTester to use this resolution:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9abee55cf1367b001115d81b4f841be/href">https://medium.com/media/a9abee55cf1367b001115d81b4f841be/href</a></iframe><h4>Font files</h4><p>The most noticeable difference is the text lines. By default in widget tests, all the fonts are replaced by a test font named <a href="https://www.w3.org/Style/CSS/Test/Fonts/Ahem/README">Ahem</a> which renders all characters as a plain square. In the case of visual regression testing, it doesn’t suit our interest.</p><p>When using the MaterialApp widget, the default font is <em>Roboto</em>. We have to load it manually, as well as the Material icon font (the icon in the top right corner of the Inset):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0eff62c67505f9bad256ccaeecfb6acd/href">https://medium.com/media/0eff62c67505f9bad256ccaeecfb6acd/href</a></iframe><h4>Inset layout</h4><p>Remember how the Inset widget is supposed to be centered around the bottom edge of the Backdrop? The golden image reveals it’s just aligned at the bottom.</p><p>This is because of an implementation detail of the InsetCard widget: it requires 2 layout passes to be correctly positioned: the first one to get the height of the Inset, and the second to add a margin equal to half the height on the Backdrop, to obtain the expected layout. Check the <a href="https://github.com/ncuillery/image_mocker/blob/master/lib/src/widgets/inset_card.dart">repository</a> for the full implementation.</p><p>When calling pumpWidget, only the first pass is performed. For the second one, we have to call pump to trigger a second frame. To be less dependant of implementation details like this one (and more frequently used: animations), we can use pumpAndSettle, which actually means “trigger new frames until the app is idle”.</p><p>Let’s run the test command for another try:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*JoVCUFMqKHBYDgvu7ZRnag.png" /><figcaption>That’s progress!</figcaption></figure><p>This is the corresponding updated test, using the 2 methods previously implemented:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45079614f12886a4a6c82e204df35a82/href">https://medium.com/media/45079614f12886a4a6c82e204df35a82/href</a></iframe><p>The golden image starts to look like the real widget. In addition to the missing backdrop image, we can notice another difference: the grey border below the Inset.</p><p>This is because of the Inset shadow: shadows are not guaranteed to be pixel-perfect every time they are rendered. So they are disabled by default in golden tests and replaced by solid borders, otherwise, it could lead to false positives when running the golden tests.</p><p>Note: it’s technically possible to force the activation of the shadows (for documentation purpose for instance) by doing:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7885d3f91e6c0bc708acea453f05167/href">https://medium.com/media/d7885d3f91e6c0bc708acea453f05167/href</a></iframe><h3>Mock image asset</h3><p>This leads us to the final problem we have to take care of: the backdrop image. In widget tests, we don’t want to be dependent on any remote server, that’s why the low-level Dart HttpClient is configured by default to return an error 400 on every request (the reason why our image is not loaded). It’s possible to mock this client and stub a custom response for a given request however it is highly verbose and cumbersome to set up.</p><p>By chance, we are already using a package, cached_network_image, whose sole purpose is to spare a network request when the image is found in the cache. In addition to that, it already implements the logic to fetch an image from the filesystem (sqflite is used to store the cached URLs and associated metadata, but the image file itself is stored in the device’s temporary folder).</p><p>It would be neat then if we could trick the BaseCacheManager by faking a cache hit and configuring it to return an image file from the test/assets directory!</p><p>Let’s start by saving an image in the test/assets folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oVuXbzwBV36mYbv3wYF9KQ.jpeg" /><figcaption>Mock image (original photo by <a href="https://unsplash.com/@victoire_jonch?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Victoire Joncheray</a> on <a href="https://unsplash.com/s/photos/la-clusaz?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>)</figcaption></figure><p>By looking at the internal of the CachedNetworkImage component, we can see a call to the method <a href="https://pub.dev/documentation/flutter_cache_manager/latest/flutter_cache_manager/BaseCacheManager/getFileStream.html">getFileStream</a> of the BaseCacheManager class.</p><p>If the returned Stream emits a valid FileResponse object, then the widget builds the Image and starts the fade-out transition from the placeholder.</p><p>In BaseCacheManager, this method contains the cache logic (look into the cache, then download the file if not found). We can bypass that logic by overriding the method in our TestCacheManager:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80fa93a0e4a9bf44bde26bcc4affdcba/href">https://medium.com/media/80fa93a0e4a9bf44bde26bcc4affdcba/href</a></iframe><p>That’s it! The Stream emits an event and the CachedImageWidget interprets as a ready-to-use image and build the Image widget.</p><p>If you re-run the test now, unfortunately, the image is still missing. That’s because the Image widget loads the image in an asynchronous task and the WidgetTester can’t know when the loading is complete.</p><p>But thanks to Chun-Heng Tai from the Flutter team, <a href="https://github.com/flutter/flutter/issues/38997#issuecomment-524992589">a workaround exists</a>, based on <a href="https://api.flutter.dev/flutter/widgets/precacheImage.html">precacheImage</a> method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e2775a51a02f0dff4ef22b17f55d60d/href">https://medium.com/media/8e2775a51a02f0dff4ef22b17f55d60d/href</a></iframe><p>And <em>voilà</em>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*MqzPT6UYHvb_AnsXZszTGQ.png" /><figcaption>Final golden image</figcaption></figure><h3>Wrap up</h3><p>We now have a test to guarantee the UI will never change unintentionally. In addition to that, once the moderated amount of boilerplate has been written, we can multiply the test cases endlessly for different screen sizes, text factors, landscape mode (it doesn’t look good…), different lengths of data, etc.</p><p>If you’d like to know more about golden testing in production, eBay has used it extensively for their app <em>eBay Motors</em> and wrote interesting feedback in this blog post:</p><p><a href="https://tech.ebayinc.com/engineering/ebay-motors-screenshot-testing-with-flutter/">eBay Motors: Screenshot Testing with Flutter</a></p><p>Feel free to share any suggestions or feedback in the comments and… happy testing!</p><p>Thank you to Rene Floor <a href="https://twitter.com/FloorRene">@FloorRene</a>, main contributor of cached_network_image, for his review of this article.</p><p><a href="https://www.twitter.com/fluttercomm">https://www.twitter.com/fluttercomm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b488c653af3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/flutter-community/golden-testing-using-cachednetworkimage-1b488c653af3">Golden testing using CachedNetworkImage</a> was originally published in <a href="https://medium.com/flutter-community">Flutter Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ESLint test report in buddybuild]]></title>
            <link>https://medium.com/@ncuillery/eslint-test-report-in-buddybuild-49cf03290616?source=rss-69ddd49628e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/49cf03290616</guid>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[buddybuild]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Nicolas Cuillery]]></dc:creator>
            <pubDate>Tue, 05 Sep 2017 12:30:31 GMT</pubDate>
            <atom:updated>2017-09-05T12:30:31.939Z</atom:updated>
            <content:encoded><![CDATA[<p>My team uses <a href="https://eslint.org/">ESLint</a> and <a href="https://facebook.github.io/jest/">Jest</a> on a daily basis for several projects. That’s why we were pretty exciting when buddybuild announced the support of <a href="https://www.buddybuild.com/blog/custom-test-reporting">custom test reporting</a>.</p><p>This feature consists in displaying a tab with the test results for each build. It works seamlessly with Jest which figures in the <a href="https://docs.buddybuild.com/tests/frameworks.html">list of supported frameworks</a>, by simply adding the following lines in the <a href="https://docs.buddybuild.com/builds/custom_build_steps.html">post-build</a> hook:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c867416b26400c08266f52b453682506/href">https://medium.com/media/c867416b26400c08266f52b453682506/href</a></iframe><p>Then, at the end of the build, a Jest tab appears and displays the result of the tests execution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*51TCQwERbVNhbAxYF-NapA.png" /><figcaption>Successful tests in buddybuild</figcaption></figure><p>We tried to do the same with ESLint but the result was pretty bad: A “ESLint” showed up but was empty:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vZjHMYhMfW-FQ4XVoyzSOA.png" /><figcaption>The “99” is the total number of tests from all frameworks, here: only the Jest ones.</figcaption></figure><p>It appears that buddybuild is not able to parse the ESLint JSON output (it isn’t mentioned in the <a href="https://docs.buddybuild.com/tests/frameworks.html">list of supported frameworks</a> after all).</p><h3>JSON output transformation</h3><p>What if we transform the ESLint JSON output to make it similar to the Jest one? We know for sure that buddybuild is able to parse it.</p><p>Jest produces the following JSON (reduced to a single failed test suite for the sake of readability):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7105d5f904ce07304b5e8dbb751afdf5/href">https://medium.com/media/7105d5f904ce07304b5e8dbb751afdf5/href</a></iframe><p>The output contains metadata about the execution, number of tests succeeded, failed &amp; total, information about snapshots, status, etc. and a testResults node which contains an object for each test suite.</p><p>These underlying objects also contain metadata and an assertionResults node which contains an object for each test case.</p><p>Let’s examine the structure of the JSON produced by ESLint now. Here is a shortened example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c694a3cf743684abf255aef2e5bca63f/href">https://medium.com/media/c694a3cf743684abf255aef2e5bca63f/href</a></iframe><p>ESLint goes straight to the essential: no metadata, just an array with an object representing each file.</p><p>So let’s try to transform the JSON in order to make buddybuild able to parse it. A proper ESLint report would be an array with a line for each file verified, so we’ve build a Jest-style JSON object representing a single test suite including a test case for each file of the ESLint report.</p><p>In a simple NodeJS script that read and parse the ESLint output file, we create a raw root object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7ef142bbca5920be711ba5f61c4195a/href">https://medium.com/media/c7ef142bbca5920be711ba5f61c4195a/href</a></iframe><p>Then, we fill the assertionResults array with objects that look like the Jest test cases:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59df4666321beb37111d45b941b6e1f0/href">https://medium.com/media/59df4666321beb37111d45b941b6e1f0/href</a></iframe><p>Finally, we add the metadata, based from the presence of errors or not:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba874e60d2390a158e3f1499227c2363/href">https://medium.com/media/ba874e60d2390a158e3f1499227c2363/href</a></iframe><p>Note that the message, name and summary empty strings are needed even if they aren’t display anywhere. For some reason, buddybuild won’t be able to parse the JSON file if they are not present.</p><p>And <em>voilà</em>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gjxsIbUImdOOa5YQATho6A.png" /><figcaption>Relevant ESLint report in buddybuild</figcaption></figure><h3>Wrap up</h3><p>Here is the <a href="https://gist.github.com/ncuillery/ab5b252e247dbcc9bbf72413382fe0c9">Gist</a> with the whole buddybuild_postbuild.sh and eslint-output-adapter.js files. These 2 files contain all the magic.</p><p>I admit that the whole “JSON output transformation” thing looks like a dirty workaround. There are better ways to transform a JSON structure to another, like using existing tools (like <a href="https://github.com/bozzltron/node-json-transform">node-json-transform</a> or <a href="https://github.com/ColinEberhardt/json-transforms">json-transforms</a>), but there are pretty good chance that the situation is temporary: it’s a transition until buddybuild officially supports ESLint, so I didn’t want to overthink the solution (hey <a href="https://medium.com/u/7ca2ee6a674f">buddybuild</a>, an official statement in comments about that would be pretty cool 😉).</p><p>When they do, I hope they would support it better than I did, like handle ESLint warnings as well, handle multiple errors per file, show the code snippet in tooltip, etc.</p><p>In the meantime, we finally manage to unify our CI, dropping an old Jenkins instance whose the only job was to run the lint &amp; test commands.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49cf03290616" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I learned at React Europe 2017]]></title>
            <link>https://medium.com/free-code-camp/what-ive-learned-from-react-europe-2017-c433468890d6?source=rss-69ddd49628e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/c433468890d6</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Nicolas Cuillery]]></dc:creator>
            <pubDate>Tue, 23 May 2017 13:56:01 GMT</pubDate>
            <atom:updated>2017-05-27T07:07:02.692Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LI8kcoWrhCJUoAXdqz6vaQ.jpeg" /></figure><p>Few days ago, the 3rd edition of the biggest React conference in Europe took place in Paris. No heatwave or transportation strike this year — only great talks and interesting people.</p><p>Here is my feedback from my most appreciated talks of this edition.</p><p>Speaking of interesting people, I’d like to warmly thank <a href="https://medium.com/u/b0b8620b801a">Griffith</a> Tchen Pan, just met among the audience, for his review of this article, as well as my team mates at <a href="http://tech.m6web.fr/">M6 Web</a>.</p><h3>Keynote</h3><p>Those who came especially to hear news and updates about React could be satisfied: <a href="https://medium.com/u/6025bd347b9a">Andrew Clark</a> opened the conference with the roadmap for React. All these updates can be resumed in a single name: React Fiber.</p><p>Andrew illustrated React Fiber with a performance analysis of the video streaming in the newsfeed. They had to deal with poor performance caused by other tasks blocking the main JS thread. It was a scheduling problem, solved by splitting the execution of the tasks: the main thread is able to process chunks as they arrive so videos are no longer interrupted. The idea behind React Fiber is to schedule these tasks at the component level via the async rendering.</p><p>Coming in React 16, the revamp will also include fragments (group of sibling component, no more div wrapper, just return an array in the render function). Also a better error handling will be shipped with error boundaries (i.e. try/catch for component) and distinction of critical errors from the others. In case of critical error, the component will unmount to avoid degraded UI, corrupted datas…</p><p>React 16 is already in production, ready to install with the <em>next</em> tag:</p><p>yarn add react@next</p><p>Beyond React 16, the enhanced render scheduling allows rendering to be prioritized, depending on the viewport position: this allows offscreen or hidden elements to render last without delaying rendering of “immediately-visible” components. It could also improve the user experience when using code-splitting within the current screen. Code-splitting could cause a smoothless cascading rendering of the screen. To avoid this side-effect, React 16 introduces a “commit phase” which consists to delay all the DOM updates at the end of the rendering phase to avoid inconsistent DOM.</p><p>Introducing React Fiber was a great way to open the conference. Its new features are highly anticipated by the community. To learn more about React Fiber: <a href="https://github.com/acdlite/react-fiber-architecture">https://github.com/acdlite/react-fiber-architecture</a></p><h3>What I learned benchmarking React</h3><p><a href="https://medium.com/u/2cd0dccd3af3">Dominic Gannaway</a> from Facebook presented the recent optimizations on the React package. Inspired by the design of lightweight clones of React like Inferno (created by him) &amp; Preact, he works to make the React package lighter and faster to load.</p><p>Thanks to a new build system backed by <a href="https://github.com/rollup/rollup">Rollup</a>, the React package gains 10% weight and is 9% faster to load.</p><blockquote>Webpack is for apps, Rollup is for libraries</blockquote><p>They also externalize the PropTypes support as well as deprecated code like React.createClass (see <a href="https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html#new-deprecation-warnings">here</a>).</p><p>Dominic pointed out the importance of using a powerful and consistent benchmark tool when trying to optimize the React package. He showed an interesting “snapshot benchmarking” tool comparing current metrics versus the previous one (package size, initial load time, time to interactive) that runs on <a href="https://developers.google.com/web/tools/lighthouse/">Google Lighthouse</a>.</p><p>This tool was a great help to get confidence when moving the React codebase. It is a prerequisite to make React smaller and faster.</p><p>To know more about Dominic’s work:<br>New build system: <a href="https://github.com/facebook/react/pull/9327">https://github.com/facebook/react/pull/9327</a><br>Benchmark: <a href="https://github.com/facebook/react/pull/9465">https://github.com/facebook/react/pull/9465</a></p><h3>High quality JavaScript tools</h3><p>As an early adopter of Jest, I can tell that using Jest two years ago was like crossing the desert. I also lived the mutation of Jest which is nowadays a great and widely-used tool. That’s why I was very pleased to hear <a href="https://medium.com/u/9ea60eb6fc7c">Christoph Pojer</a> telling that story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*RGql2QYssW6i_RPldPED_A.jpeg" /><figcaption>Sad jester (“Stańczyk” by <a href="https://en.wikipedia.org/wiki/Jan_Matejko">Jan Matejko</a>)</figcaption></figure><p>That story is: how Jest has turned from a tool into a “product”. A product is focused on performance and features which bring adoptability, and in case of a test runner, 2 experiences must be delightful: running tests and writing tests.</p><p>The performance has been improved by implementing parallel test runs, using all the CPUs, and measuring the execution times to schedule them better for the next runs.</p><p>Christoph and the community made a great job to bring interesting features into Jest, like relevant output (useful diff instead of pointless error stacktrace), immersive watchmode (interactive CLI, navigation among the list of test cases to rerun them).</p><p>Christoph mentioned the snapshot testing: in addition to conventional testing (it’s not a replacement !), it’s a great way to visualize the comprehensive output of a component (current vs expected).</p><p>Jest 20 will come with the multi-project runner. By using the option --projects Jest is able to run multiple test suites and consolidate tests result in a single terminal window. Useful for using the watch-mode on a multi-repo codebase.</p><p>Jest has been moved to a multi-package architecture and some of them are used on several projects at Facebook: jest-haste-map, jest-snapshot, jest-validate (an CLI options parser like <a href="https://github.com/tj/commander.js">Commander</a>). It has been useful internally to consolidate their infrastructures and share best practices.</p><p>Worth to mention: Jest is now maintained by 2 core developers + the community. We are strongly encouraged to contribute, Jest project is approchable and easy to contribute.</p><p>Blog post about Jest 20: <a href="https://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html">https://facebook.github.io/jest/blog/2017/05/06/jest-20-delightful-testing-multi-project-runner.html</a></p><h3>Worse is better: the upside of JavaScript fatigue</h3><p>The point of this talk is that the JavaScript fatigue is a good thing, healthy for the ecosystem. <a href="https://medium.com/u/236f88713399">Kevin Lacker</a> started by remind us what the <a href="http://thefullstack.xyz/javascript-fatigue/">JavaScript fatigue</a> is.</p><p>Hundreds of new librairies are announced each month on <a href="https://news.ycombinator.com/">Hackernews</a>. It’s impossible to take a look to everything. The good news is that you don’t have to: just pick <strong>the right thing</strong>.</p><p>From a principle conceived by Richard P. Gabriel in the eighties, the right thing has 4 golden characteristics:</p><ul><li>Simplicity</li><li>Correctness</li><li>Consistency</li><li>Completeness</li></ul><p>But history shows that the right thing is sometimes… not the right thing. Actually, only the simplicity matters.</p><blockquote>Simple things are easier to integrate.</blockquote><p>The concept of <strong>worse is better</strong> is born. We could bear a lack of correctness, consistency or completeness if the thing is simple to handle!</p><p>At this point came the parallel with the raise of React: Simplicity above all other characteristics.</p><p>Simplicity leads to popularity which leads to contributors. Today we can enjoy all that React was missing at its launch : state management, routing, getting started tools (create-react-app).</p><p>Speaking of create-react-app, it really gathers all the best things brought by the community since 3 years and it is far better that it could have been at React launch.</p><p>The JavaScript fatigue, then, is simply the consequence of the huge number of open-source contributors.</p><h3>Nicolas Cuillery on Twitter</h3><p>It seems my name was prominently readable at #F8... before it got unzoomed &amp;amp; drown into 4500 contributors&#39; names :) https://t.co/oKQntitZs5</p><p>In conclusion, launch something simple, make it popular (documented, battle-tested), then fill the holes.</p><p>I found Kevin has made an interesting analogy between the modern JavaScript ecosystem and the <em>worse is better vs the right thing</em> theory.</p><p>Excellent article about the Richard P. Gabriel theory: <a href="https://en.wikipedia.org/wiki/Worse_is_better">https://en.wikipedia.org/wiki/Worse_is_better</a></p><h3>Wabi Sabi</h3><p>This Japanese word designates the art of “beauty into imperfection”. <a href="https://medium.com/u/701b0000d771">Cheng Lou</a> made a philosophic and very inspirational talk (<a href="https://www.youtube.com/watch?v=mVVNJKv9esE">for the second year in a row</a>) about trade-offs.</p><p>Trade-offs are a big part of our job as software engineer because we don’t have unlimited time and money. So we use pieces of software which imperfectly covers our needs. Let’s say 80% of our needs: it corresponds to the <strong>sweet spot</strong> on the Pareto curve, a.k.a. the 80/20 rule. It means that a reasonable amount of time (about 20%) is sufficient to cover 80% of our needs.</p><p>Our IT world is full of 80% systems. For example, image compression: if you get 80% of the original image for 20% of its size, that’s a good trade-off.</p><p>About React, the trade-off may be the communication with sibling components which is far harder than parent/child components… The cause is the tree model, convenient for 80% of the case. The 100% approach would be a graph model.</p><p>Flux is a 80% system too. Some tasks are difficult, like managing side-effects or external sources of changes. Redux is generally great but the unlucky programmers in the 20% area need dirty workarounds. It reminds me the <a href="https://medium.com/@erikras/redux-dead-drop-1b9573705bec">dead drop pattern</a> for example.</p><blockquote>Some things are not meant to be optimized.</blockquote><p>It’s important to point out that, sometime, the trade-off is intentional because we are in the sweet spot, we don’t want to move. Let’s come back to the React example above, if React moved to a graph model handling 100% of the use cases, the whole library would be more complex which is not a good thing.</p><p>Being in a 80% system give us wiggle room, it boosts our creativity and adaptability. I work for few months with <a href="https://redux-observable.js.org/">redux-observable</a> which I can now describe as “a trade-off for the 20% of the cases Redux doesn’t cover”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*DBGdHlkB6DVjBy62d3TANQ.gif" /><figcaption>And redux-observable is also a 80% system!</figcaption></figure><p>There are disadvantages in the 80% approach. First of all: the 20% obviously. it may not be chosen to build foundations. Moreover, the 80% design generally makes composing a nightmare (mutations, side-effects, …).</p><p>Some stuff belong to the 100% world. For example, types checking with Flow: a great strength of Flow is the ability to incrementally typing your code base. It’s okay to add Flow file by file but you can’t add Flow partially within a file because you wouldn’t be able to say “Ok, this part of my app is strongly type-checked, I trust it”. You would loose the benefit of the type-checking (the confidence).</p><p>It’s interesting to mention that 80% and 100% systems can be complementary: you can use a 80% tool because you have a compiler behind the scene (100%, the compiler never bails on you).</p><p>Reading documentation is a 80% action, reading source code is 100%.</p><p>In conclusion, Cheng mentioned a publication of Leslie Lamport as a source of inspiration for his talk. He says that the credibility of the 80% approach varies with the domain of science, from 0% in Math to 100% in sociology/psychology.</p><p>Again, Cheng has the awesome skill to look at the bigger picture with hindsight. I found his talk very instructive and… kind of refreshing in such a technical conference.</p><h3>Andrew Clark on Twitter</h3><p>@_chenglou Great talk. Reminded me of this Louis CK gem https://t.co/E2mPXQcAwF</p><p>Leslie Lamport’s publication: <a href="http://lamport.azurewebsites.net/pubs/future-of-computing.pdf">http://lamport.azurewebsites.net/pubs/future-of-computing.pdf</a></p><h3>How streaming can supercharge React</h3><p><a href="https://medium.com/u/1dcba27e6a5c">Sasha Aickin</a> introduced his talk with some metrics about the initial render time (+1s page load time on a commercial website leads to -20% conversion rate), making the point that SSR (Server Side Rendering) is vital.</p><p>But SSR comes with an other problem: It causes a delay between the first render (the browser paints the server-side-rendered markup immediately) and the “time-to-interactive” (the browser has loaded the bundle and the SPA is on). This duration is called in a funny way by <a href="https://medium.com/u/97ce3a05d275">Paul Lewis</a> the “uncanny valley”.</p><p>Moreover, the SSR doesn’t scale well: the more your page is complex, the more it takes to render on the server-side. And it’s difficult to tell to your PO: “No, no, no, I can’t do that, it will make the whole page slower !”</p><p>Multiples things happen when a page is rendered on the server-side:</p><ul><li>The browser sends a request to the server,</li><li>The server fetches the data from the API,</li><li>The server renders the markup,</li><li>The server returns the page with the markup.</li><li>The browser paints the markup and sends requests for the CSS and JS files. We have entered into the uncanny valley.</li><li>The server answers the requested files.</li><li>The browser loads and executes the bundle.</li><li>We’ve finally reached the end of the uncanny valley.</li></ul><p>The problem is that all these tasks happen sequentially. What if we can parallelize things ?</p><p>Instead of a huge monolithic SSR, the server could process the render of the page fragment by fragment. Let’s consider a page made of a title, a main content and comments for example, Sasha showed that the server could returns a “chunk”, i.e. all pieces necessary to render a portion of the page (HTML + CSS + JS + JSON) for each part of the page.</p><p>With this approach (SCR or Server Chunk Rendering), both initial render time and uncanny valley duration are reduced (especially on mobile) because the SSR is more of a “stream” now, it could be parallelized:</p><ul><li>The browser sends a request to the server,</li><li>The server processes and returns the first chunk (the title)</li><li>While the browser paints and loads it, the server starts to process the 2nd chunk (the main content) and can even ask the API the data of the 3rd chunk (the comments) at the same time too.</li><li>The server returns the 2nd chunk</li><li>And so on…</li></ul><p>An other benefit is: if one of the multiple calls to the API falls into a black hole, it doesn’t take the whole page down, but only the area concerned by the chunk.</p><p>I had a lot of interrogation in mind after the talk: how to define the chunks within each page of the app ? does it imply the return of the good old HTML templates ? (I guess I have to take a look at Sasha’s lib <a href="https://github.com/aickin/react-dom-stream">react-dom-stream</a>), but, yes, it seems we had a glimpse of what the future of the SSR will be:</p><blockquote>Rename ReactServer -&gt; ReactDOMServerStream This file is going to be the replacement for ReactDOMServer.</blockquote><p>Recent pull requests show that something is coming in the official React repo: <a href="https://github.com/facebook/react/pull/9710">https://github.com/facebook/react/pull/9710</a></p><p>Blog post about the uncanny valley: <a href="https://aerotwist.com/blog/when-everything-is-important-nothing-is/">https://aerotwist.com/blog/when-everything-is-important-nothing-is/</a></p><h3>Lightning talks (day 1)</h3><h4>return null; by Joshua Comeau</h4><p><a href="https://medium.com/u/a11edf57e20a">Joshua Comeau</a> spoke about “renderless” components. Those components don’t render anything but enjoy the React lifecycle though.</p><p>He presented a dead simple Log component which prints its child in the console, every time it changes, thanks to the React lifecycle.</p><p>Then, a more serious example: a component wrapping the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API">Web Speech API</a> that read out loud the content of a text input. The component is able to interrupt the current speech before reading the new content: since the new content is a prop, that could be easily implemented in a componentWillReceiveProps.</p><p>Joshua has gathered great explanations (as well as slides and examples) in his Github repository: <a href="https://github.com/joshwcomeau/return-null">https://github.com/joshwcomeau/return-null</a></p><h4>Detox: Graybox End-to-End Tests and Automation Library for React Native</h4><p>Even people who have never heard about Detox knew that something was coming when the audience applauded before the talk began, just when the title appeared on the screens!</p><p>In the mobile development world, manual QA is time consuming, up to 10 full days for the Wix app. So <a href="https://medium.com/u/83a4f96844d0">Tal Kol</a> and people at Wix put effort in automated tests and used the number 1 framework: <a href="http://appium.io/">Appium</a>. It didn’t give satisfaction because tests have to run on real devices, they are very slow, complicated to write and flaky (they end up with <em>sleep()</em> everywhere). So they decided to create a new tool: Detox!</p><p>While Appium is a blackbox, Detox is more of a “greybox”: everything on the device (or simulator) is monitored (network, JS thread, etc.), kept controlled and synchronized to avoid flakiness.</p><p>The talk ended up with a video showing a very fast test suite execution.</p><p>We encountered the exact same problems with Appium in my client company <a href="http://tech.m6web.fr/">M6 Web</a>. Due to the lightning talk format, it was impossible to explain in detail the internal of Detox so we still have a lot of questions (does it work with brownfield app ?), but we’ll definitely try Detox by ourselves!</p><p>Repo: <a href="https://github.com/wix/detox">https://github.com/wix/detox</a></p><h4>Serious graphics on React Native</h4><p>Great way to close Day 1: a visual lightning talk full of cool stuff like video games, image filters, data viz, ... by <a href="https://medium.com/u/b76f0303e50d">James Ide</a> from Expo.</p><p>James presented the GLView component of Expo which is able to display OpenGL GPU-accelerated graphics on a mobile device.</p><p>GLView component architecture is a bit different from other React Native component. It used the ability of JavaScriptCore (the mobile JavaScript execution environment) to call the C native API without using the main bridge. So the graphics are not affected by the occupation on the bridge.</p><p>Then James showed some graphic interfaces like effects on the video stream from the camera, video-games and an example of a 3D view created with the existing library <a href="https://github.com/gre/gl-react">gl-react</a> that is compatible with React Native.</p><p>GLView documentation: <a href="https://docs.expo.io/versions/v17.0.0/sdk/gl-view.html">https://docs.expo.io/versions/v17.0.0/sdk/gl-view.html</a></p><h3>Composition: a superpower explained</h3><p>I found that Functional Programming is generally incredibly useful, concise and elegant, but we shouldn’t fall in the trap of doing FP… for doing FP, when code becomes less readable and understandable than before. <a href="https://medium.com/u/ff3f225e7f5c">Nik Graf</a> didn’t fall in that trap when he presented his talk about composition, inspired by his work on the color API of <a href="https://github.com/styled-components/polished">polish</a>.</p><p>To illustrate the original problem, Nik presented an example of imperative code using <a href="https://lodash.com/">Lodash</a> (since the live video has been temporary removed from YouTube, I’ve rewritten similar code snippets):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8fbabf45b3227bbf49666eb0a4bf418/href">https://medium.com/media/e8fbabf45b3227bbf49666eb0a4bf418/href</a></iframe><p>That code full of temporary variables could be improved with the chain API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8849a772fbf314dcd13f1f33b6554b54/href">https://medium.com/media/8849a772fbf314dcd13f1f33b6554b54/href</a></iframe><p>That is more concise but still not perfect, there are still the chain and value operator (seriously, who have never forgotten .value() at the end of an explicit Lodash chain?). Moreover, the chain API kills the ability to partially import Lodash (see <a href="https://medium.com/making-internets/why-using-chain-is-a-mistake-9bc1f80d51ba">this excellent article</a>).</p><p>Real composition allows to define a pipe with <a href="http://ramdajs.com/">Ramda</a>, <a href="https://github.com/lodash/lodash/wiki/FP-Guide">lodash/fp</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/994c9893ca42ef4cda96461ec36cbf88/href">https://medium.com/media/994c9893ca42ef4cda96461ec36cbf88/href</a></iframe><p>We can find a similar ugly syntax in React with the HoC (High-Order Component) pattern and, again, composition could improve the readability:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/559d8513e11fcc188c2675db41b2660a/href">https://medium.com/media/559d8513e11fcc188c2675db41b2660a/href</a></iframe><p>The compose function from either Ramda, lodash/fp, recompose or react-apollo can be used here (oh, I’ve already put the mind-blown gif in this article, right ?). So it seems there is a real pattern here.</p><p>That was a source of inspiration when Nik created the color API of polish: a color could be a composition of tint, light and saturation! They made a cool api like Ramda or Lodash/fp, composable but also usable in the imperative style thanks to currying.</p><p>Back to React, Nik showed that we can write our own HoC function to avoid repetition. For example, when we have a bunch of component that need a boolean prop to be true to display content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e66b4ce978d39b6a3e1fa9c38d5acb7d/href">https://medium.com/media/e66b4ce978d39b6a3e1fa9c38d5acb7d/href</a></iframe><p>We can do the same with a HoC function withErrorMessage that decorate a text input with an error message for example.</p><p>Nik closed the talk with a React VR screen showing planets rotation, the rotation is implemented with a syntax similar to React Native Animated. He explains how the animation is contained in a reusable HoC function withRotation.</p><p>This talk provided relevant examples to illustrate FP concepts like currying, Higher-order-Function and how they could be applied to React (Higher-order-Component). I’m definitely looking forward to analyze the withRotation HoC and see if I could transpose that on my React Native projects.</p><p>React doc about composition &amp; HoC: <a href="https://facebook.github.io/react/docs/higher-order-components.html">https://facebook.github.io/react/docs/higher-order-components.html</a></p><h3>React as a Platform</h3><p>It’s a well-known fact that Airbnb makes an extensive use of React and React Native. <a href="https://medium.com/u/41a8b1601c59">Leland Richardson</a> pointed out that it was a big step forward:</p><p>Instead of writing Airbnb 3 times (for Web, iOS and Android) by 3 different teams (JavaScript / Java / Swift), React and React Native allows a 2-time writing (Web and native) by the same team (Javascript). But now, the engineer writes twice the almost identical code. Couldn’t it be better if they write it only once ?</p><blockquote>Write one, run anywhere ?</blockquote><p>Leland thinks we can achieve that. React Native was an eye-opener: React can address multiple platforms. Then, <a href="https://github.com/necolas/react-native-web">React Native for Web</a> had come, followed by Windows, Ubuntu, VR, …</p><p>The biggest obstacle of component sharing between platforms is the import of the platform implementation, for example with React Native:</p><pre>import { View } from &#39;react-native&#39;;</pre><p>Note that a React DOM component doesn’t have such an import for legacy reason but shouldn’t it be for sake of consistency ?</p><pre>import { Div } from &#39;react-dom&#39;; //To discuss only, don&#39;t do that ;)</pre><p>Based from the experience of the Airbnb’s library of React Native components, only 7 React Native APIs are widely used. Lots of the 70+ APIs are composition of these 7 primaries.</p><p>Leland came with a proposal: these 7 APIs wrapped in an NPM package named react-primitives.</p><ul><li>View</li><li>Image</li><li>Text</li><li>Animated</li><li>Touchable</li><li>Platform</li><li>StyleSheet</li></ul><p>Leland is aware that it isn’t perfect: the presence of Animated is questionnable. In the opposite, TextInput is not included despite it can’t be a composition of the 7 primitives.</p><p>But maybe an optional platform extension is the answer (inspired by the React Native ability to define platform-specific implementations by adding a suffix at the end of the file name).</p><p>Take the checkbox example: <em>Checkbox.js</em> could contain a composition of primitives to design a checkbox on every platform where the checkbox doesn’t exist. And, as an optimization, <em>Checkbox.web.js</em> could contain only the input component from react-dom.</p><pre>&lt;input type=&quot;checkbox&quot;&gt;</pre><p>As if that were not enough convincing, Leland closed his talk with <a href="https://github.com/airbnb/react-sketchapp">react-sketchapp</a>, showing how they treated the design tool <a href="https://www.sketchapp.com/">Sketch</a> as an additional platform without modifications in the code base thanks to primitives. Airbnb designers can design storyboards using the real library of React Native components.</p><h3>Adam Miskiewicz on Twitter</h3><p>There&#39;s not a whole ton of people thinking this big about x-platform React. @intelligibabble and @AirbnbEng are really pushing this forward.</p><p>react-primitives: <a href="https://github.com/lelandrichardson/react-primitives">https://github.com/lelandrichardson/react-primitives</a></p><h3>Lightning talks (day 2)</h3><h4>Expo Snack</h4><p>In addition to making a great intro for each speaker during these 2 days, <a href="https://medium.com/u/d5a707474bd2">Brent Vatne</a> presented Snack for the Expo app in a lightning talk.</p><p>Snack is the replacement of the former React Native playground (<a href="https://github.com/rnplay/rnplay-web">rnplay-web</a>). The problem with rnplay-web was a very slow feedback loop. Code changes were sent to the server which had to run the React Native packager and sent back the output to the browser.</p><p>With Snack, the code changes from the web editor are sent to the device and reexecuted directly.</p><p>Snack also includes a QR code generation to get your code running in the Expo app on your own device.</p><p>Examples of the official React Native documentation has moved to Snack. For example: <a href="http://facebook.github.io/react-native/releases/next/docs/text.html">http://facebook.github.io/react-native/releases/next/docs/text.html</a></p><p>To play with the QR code generation, drag’n drop of Expo’s bridged components running on your own device in no time: <a href="https://snack.expo.io/">https://snack.expo.io/</a></p><h4>Smarter code-splitting and preloading for React applications</h4><p>In his lightning talk, <a href="https://medium.com/u/25b2696a8b5d">Brandon Dail</a> spoke about code-splitting with react-loadable and its ability to preload a component using the static method preload().</p><p>There are 2 approaches regarding the preloading. The “passive” preloading is based on user’s <strong>intent</strong>. For example, a list page could preload the detail page because there are pretty good chances that the user want to open the detail page. This approach should be based on the analytics to avoid wasteful preloading.</p><p>On the opposite, the “active” approach consists in a preload based on user’s <strong>action</strong>, like a mouse approaching a button (onMouseEnter event). For that case, Brandon created the library react-perimeter which define boundaries around a component and call a callback when they are breached (similar to a onMouseEnter event): useful to call the preload method.</p><p>react-loadable: <a href="https://github.com/thejameskyle/react-loadable">https://github.com/thejameskyle/react-loadable</a><br>react-perimeter: <a href="https://github.com/aweary/react-perimeter">https://github.com/aweary/react-perimeter</a></p><p>Only 2 days after the conference, videos of the talks started be published on the conference YouTube channel, stay tuned on <a href="https://www.youtube.com/channel/UCorlLn2oZfgOJ-FUcF2eZ1A/videos">https://www.youtube.com/channel/UCorlLn2oZfgOJ-FUcF2eZ1A/videos</a> !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c433468890d6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/what-ive-learned-from-react-europe-2017-c433468890d6">What I learned at React Europe 2017</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easier React Native upgrades with rn-diff]]></title>
            <link>https://medium.com/zenika/easier-react-native-upgrades-with-rn-diff-5020b5c3de2d?source=rss-69ddd49628e3------2</link>
            <guid isPermaLink="false">https://medium.com/p/5020b5c3de2d</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Nicolas Cuillery]]></dc:creator>
            <pubDate>Wed, 07 Sep 2016 14:02:44 GMT</pubDate>
            <atom:updated>2016-09-07T14:02:44.342Z</atom:updated>
            <content:encoded><![CDATA[<p>The React Native environment is a strange world: This shiny framework allows JavaScript developers to easily create mobile apps with a native look-and-feel. Most of the resources (official documentation, examples, tutorials, blog posts, StackOverflow questions, feedback, …) cover the early stages of a project like initialization, setting up the navigation, building screens, having your first “whoa!”, etc. But when the time has come to maintain, industrialize or release a React Native project, resources become sparse and you can sometimes feel like you’re on your own. Upgrading React Native is one of the most difficult tasks you’ll face when working on a long life project. I’ll tell you why, and how I solved it.</p><h3>Bahattin Çiniç on Twitter</h3><p>I am trying to upgrade to the latest version (from 0.21 to 0.27) of my react-native project. This process is very difficult :( #reactnative</p><h3>The upgrading process</h3><p>First of all, React Native is upgraded at a fast pace: one minor release <a href="https://facebook.github.io/react/blog/2015/05/22/react-native-release-process.html">every 2 or 3 weeks</a>. Note that, according to semver (see <a href="http://semver.org/#spec-item-4">bullet n°4</a>), “minor” releases could introduce breaking changes… and <a href="https://github.com/facebook/react-native/releases">they do</a> !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/0*GvKCJb5FZ2DFNrQ4." /><figcaption>Number of days elapsed since the previous release</figcaption></figure><p>To understand the following, let me explain how the upgrading process works under the hood. Except in cases when you integrated React Native into an existing app, you probably used the <a href="https://www.npmjs.com/package/react-native-cli">CLI</a> to generate a blank app. This skeleton includes:</p><ul><li>2 JavaScript entry-points (one for each platform),</li><li>iOS stuff in the <em>ios</em> directory (the “host app” for the iOS platform),</li><li>Android stuff in the <em>android</em> directory (the “host app” for the Android platform),</li><li>Tools (the React Native packager, <a href="https://flowtype.org/">Flow</a>, <a href="https://buckbuild.com/">Buck</a>, …).</li></ul><p>Since <a href="https://github.com/facebook/react-native/pull/2298">#2298</a>, the generation process uses <a href="http://yeoman.io/">Yeoman</a> with 3 generators embedded in the local CLI (the CLI included in the React Native package, called by the global CLI which is a pretty empty shell).</p><p>The upgrading process is described <a href="https://facebook.github.io/react-native/docs/upgrading.html">here</a>. With the exception of few versions requiring manual upgrades, it’s a one-step process consisting of running the command <em>react-native upgrade</em>. Underneath, it simply performs a new generation over your existing sources. It’s the way to upgrade any app generated with a Yeoman generator (<a href="https://github.com/Swiip/generator-gulp-angular/blob/master/docs/recipes/upgrade-my-current-project.md">isn’t it, Swiip ?</a>).</p><h3>Why do I care about the generator I used to initiate my project ?</h3><p>Other Yeoman generators generate real source files used as the foundation of your project, intended for modifications afterward. But the React Native generators are slightly different. They generate 2 full native apps (the iOS and the Android ones) containing a lot of React Native related content inside (the native entry-point, references towards all the native modules and components, platform-specific tooling, etc.). From the point of view of a JavaScript developer, these files are not the sources, you’d inevitably tend to consider them as part of the framework, completely tied to the react-native package in your <em>node_modules</em> directory. You can see the <em>react-native upgrade</em> command as a way to keep your hosted apps in sync with the React Native version mentioned in your <em>package.json</em> file.</p><p>That being said, let’s see what Yeoman does when you rerun a generator. For each output file that already exists, it performs a comparison between the existing content and the new content (see the Yeoman <a href="http://yeoman.io/generator/Conflicter.html">Conflicter</a> class). If it differs, it prompts the user with two options: replace with the new content or keep the existing one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yo4Mgt416vahgC5l." /><figcaption>react-native upgrade command output</figcaption></figure><p>Do you see how this could be problematic? The upgrade command has absolutely no idea which version you are coming from. When a conflict occurs, there is no way to know what kind of change it is:</p><ul><li>Changes that are coming up with the new React Native version, let’s call them “upstream changes”,</li><li>Changes made by developer at one time during the project life, let’s call them “project changes”.</li></ul><p>Of course, a conflicted file could contain both. The only thing Yeoman can do is printing the diff. Deal with it!</p><h3>Javier on Twitter</h3><p>Upgrade react-native is kinda a pain in the ass. &quot;Oh I see you have some changes, keep all or overwrite all?&quot; 😟 @reactjs @reactnative</p><p>A file containing project changes will be marked as “conflicted” for every React Native upgrade, whether the corresponding file in the host app had been updated between the 2 versions or not!</p><p>As a side note, keep in mind that despite the VCS semantics, we are not working with Git! The diff is computed in JavaScript with the <a href="https://www.npmjs.com/package/diff">diff</a> NPM package. Yeoman is unable to perform an automatic merge.</p><h3>Why is it such a pain ?</h3><p>At this point, you should start to imagine how much of a hassle it is to upgrade React Native. Unfortunately, the list goes on.</p><p>I said that the <em>ios</em> and <em>android</em> directories could be seen as part of the framework itself. Well, that is not quite true: sooner or later, you have to open the black box and introduce project changes:</p><ul><li>Native 3rd-party libraries required references in host apps (the <em>react-native link</em> command is here to avoid manual updates but not every library has support).</li><li>Native settings like device orientation, splashscreen, assets, …</li></ul><p>It means that the more your project is growing, the more potential conflicts you will encounter during React Native upgrades.</p><p>Some conflicts are easy to solve (like config files, comments, …) but most of them take place in the iOS and Android host apps which are written in Objective-C and Java, with a pinch of platform-specific knowledges like Gradle build files (Android) written in Groovy or Xcode boilerplate (iOS). And you don’t master these languages, that’s the reason you are using React Native!</p><p>Oh, and speaking of Xcode boilerplate… it deserves a dedicated paragraph! That is the worst part: some files in the <em>ios</em> directory are not even supposed to be read by a human… The <em>project.pbxproj</em> file contains the whole configuration of the Xcode project. It is a huge file (700+ LoC) written in an obscure (and deprecated!) plist format used by <a href="https://en.wikipedia.org/wiki/Property_list#NeXTSTEP">NeXTSTEP</a>. It contains hashes used as identifiers within the file (multiple occurrences) for every file or dependency and the result is that it’s very hard to read (I guess we could feel fortunate, it is not a binary file after all).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OffDt9dtREkXJo_u." /><figcaption>Typical conflicts in <em>project.pbxproj</em> while upgrading React Native</figcaption></figure><p>Miss a line or make a typo in there when resolving conflicts in this file and the host app is broken, your app won’t start and Xcode will fail to open the project. You are good to restart the process (i.e. revert the changes in this file and redo the upgrade command)!</p><p>Note that it’s not only a React Native problem, the <em>project.pbxproj</em> has been a pain for iOS developers for a long time despite some tools like <a href="https://github.com/simonwagner/mergepbx">mergepbx</a> or <a href="https://github.com/truebit/xUnique">xUnique</a>.</p><p>I would finish with some practical issues. When starting a React Native upgrade, you have to warn your teammates to avoid modifying the <em>ios</em> or <em>android</em> directories until your upgrade is done and merged into master. No manual changes and no <em>react-native link</em> (you certainly don’t want additional conflicts due to collaborative work!). You also have to keep track of all the changes made by hand in the host apps since day one of the project (for example: add a big red label “MANUAL UPDATES” on every Pull Request concerned).</p><h3>rn-diff to the rescue</h3><p>Let’s think about improving the process. The main problem is the difficulty in knowing what exactly has changed in the version you want to use.</p><p>Given that it simply uses Yeoman under the hood, you can explore and track the source code to see where the generators lie and read their Git history.</p><p>I did that for you, it’s:</p><ul><li><a href="https://github.com/facebook/react-native/commits/master/local-cli/generator-android">here</a> (the Android host app)</li><li><a href="https://github.com/facebook/react-native/commits/master/local-cli/generator-ios">here</a> (the iOS host app)</li><li>and <a href="https://github.com/facebook/react-native/commits/master/local-cli/generator">here</a> (platform-agnostic stuff like config files)</li></ul><p>It’s a good start, upstream changes are entirely displayed here, but it’s still a hard process to extract all the changes due to a specific React Native version. You have to track down every commit and its corresponding Pull Request to see if it’s been embedded in the version you want to upgrade. Moreover, there are a few surprises, like <em>.flowconfig</em> which <a href="https://github.com/facebook/react-native/commit/2566ed80899a4a071ed0e9c80fca0f28c2125a76#diff-0693784fbf2e944793d2c1f187991860">is taken from the root directory</a>.</p><p>We could do better than that… If the main point is to isolate upstream changes from the project ones, how about executing the upgrade command on a blank project, without project changes at all?</p><p>There is a great tool which aims to display changes in source code and it’s called <em>git diff</em>. And there is also a great service for dealing with public git repositories and it’s called Github.</p><p>Github is able to display a page with all the changes between 2 parent/child branches. So… it could be a good idea to upgrade React Native on a blank project, version after version, by creating a dedicated branch every time, isn’t it ?</p><p>That’s the whole point of rn-diff <a href="http://github.com/ncuillery/rn-diff">http://github.com/ncuillery/rn-diff</a>. It contains a pristine React Native project generated with <em>react-native init</em> with a pretty old React Native version and upgraded separately with <em>react-native upgrade</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wkVZD6LYqMffpiI_." /><figcaption>Branch tree of rn-diff</figcaption></figure><p>All branches of this repo contains one commit which contains the output of the upgrade process. It is now very easy to see the changes from one version to another using the Github compare view:</p><ul><li><a href="https://github.com/ncuillery/rn-diff/compare/rn-0.28.0...rn-0.29.0">https://github.com/ncuillery/rn-diff/compare/rn-0.28.0...rn-0.29.0</a>,</li><li><a href="https://github.com/ncuillery/rn-diff/compare/rn-0.29.0...rn-0.29.2">https://github.com/ncuillery/rn-diff/compare/rn-0.29.0...rn-0.29.2</a>,</li><li><a href="https://github.com/ncuillery/rn-diff/compare/rn-0.31.0...rn-0.32.0">https://github.com/ncuillery/rn-diff/compare/rn-0.31.0...rn-0.32.0</a>.</li></ul><p>Now, you can use the upgrade command backed by the corresponding rn-diff view. There are 3 scenarios when dealing with the files marked as “conflicted” by Yeoman:</p><ul><li>The file doesn’t appear in the rn-diff view: it means this file hasn’t changed in the new version, you can skip it with a clear conscience!</li><li>The file presents a few changes in the rn-diff view: you should probably skip it (i.e. keep your changes) and report the React Native changes manually (a good example of this scenario: <a href="https://github.com/ncuillery/rn-diff/compare/rn-0.28.0...rn-0.29.0#diff-47688e69ba4c83d925cb62d0b3fb3528R618">a very minor change in the <em>project.pbxproj</em> file introduced in 0.29.0</a>).</li><li>Most of the changes can be found in the rn-diff view: they are upstream changes, you should probably overwrite the file and report the project changes.</li></ul><p>I’ve saved the best for last. By just appending “.diff” to the compare view url, Github gives you a ready-to-use Git patch: <a href="https://github.com/ncuillery/rn-diff/compare/rn-0.31.0...rn-0.32.0.diff">https://github.com/ncuillery/rn-diff/compare/rn-0.31.0...rn-0.32.0.diff</a></p><p>Despite some caveats (see the <a href="https://github.com/ncuillery/rn-diff/blob/master/USAGE.md">usage guide</a>), you can use it as a replacement of the <em>react-native upgrade</em> command by running <a href="https://git-scm.com/docs/git-apply"><em>git apply</em></a>. By entering the git world, you get many advantages:</p><ul><li>No more conflicts for files unconcerned by the new version,</li><li>Automatic merge,</li><li><em>git apply</em> options (dry run, whitespace management, exclusion, …),</li><li>In case of real conflict, use your favorite merge tool !</li></ul><h3>Jameal G on Twitter</h3><p>I really wish `react-native upgrade` had a git-like conflict merge interface. #ReactNative</p><p>I would like to warmly thank my teammate <a href="https://medium.com/u/9fdb7cbbd52c">Dits kenny</a> for his guidances and <a href="https://medium.com/u/69f0d1607f68">Ryan Kaskel</a>, an early adopter of rn-diff, for his in-depth review of this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5020b5c3de2d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/zenika/easier-react-native-upgrades-with-rn-diff-5020b5c3de2d">Easier React Native upgrades with rn-diff</a> was originally published in <a href="https://medium.com/zenika">Zenika</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>