<?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[JetClosing Engineering - Medium]]></title>
        <description><![CDATA[Engineering and technology articles by JetClosing engineers - Medium]]></description>
        <link>https://medium.com/jetclosing-engineering?source=rss----cf40ca17ba00---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>JetClosing Engineering - Medium</title>
            <link>https://medium.com/jetclosing-engineering?source=rss----cf40ca17ba00---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:31:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/jetclosing-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting up a Production GraphQL Server — Part 1: The Server]]></title>
            <link>https://medium.com/jetclosing-engineering/setting-up-a-production-graphql-server-part-1-the-server-e790c54f9adf?source=rss----cf40ca17ba00---4</link>
            <guid isPermaLink="false">https://medium.com/p/e790c54f9adf</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Thu, 05 Mar 2020 21:56:55 GMT</pubDate>
            <atom:updated>2020-03-05T21:56:55.026Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up a Production GraphQL Server — Part 1: The Server</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z7o_SjOImbJI73tc" /><figcaption>Photo by <a href="https://unsplash.com/@aligns?utm_source=medium&amp;utm_medium=referral">Jordan Harrison</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>At <a href="https://www.jetclosing.com/">JetClosing</a>, we recently released Version 2 of our app. For this release, we developed a whole new backend service that uses <a href="https://graphql.org/">GraphQL</a> for its APIs. This mini-series will cover the steps needed to set up your own production-ready <a href="https://graphql.org/">GraphQL</a> server in <a href="https://aws.amazon.com/">AWS</a>, using the <a href="https://serverless.com/framework/docs/providers/aws/">Serverless Framework</a>, <a href="https://nodejs.org/">Node.js</a>, and <a href="https://www.apollographql.com/docs/apollo-server/">ApolloServer</a>. It utilizes <a href="https://aws.amazon.com/lambda/">Lambda</a> for running the server code, <a href="https://aws.amazon.com/api-gateway/">API Gateway</a> to serve our GraphQL API, and <a href="https://aws.amazon.com/dynamodb/">DynamoDB</a> as our backing data store.</p><h3>Create the Service</h3><p>To get started, you’ll want to make sure you have an <a href="https://serverless.com/framework/docs/providers/aws/guide/credentials/">AWS account set up and configured for Serverless</a>.</p><p>Next, we’ll want to generate our service using one of the templates. Run the following commands in your terminal, replacing my-graphql-service with the name of your service:</p><pre>mkdir -p ~/my-graphql-service<br>cd ~/my-graphql-service<br>npx serverless create --template aws-nodejs-ecma-script -n my-graphql-service<br>yarn install</pre><p>Using a template ensures we are using the latest standards; however, it requires some cleanup:</p><ul><li>Add a locked version of serverless: yarn add -D serverless</li><li>Delete example handlers: rm first.js second.js</li><li>In the serverless.yml file, delete everything under functions</li></ul><p>Next, we’ll want to add some better default options to our service. In the serverless.yml we’ll want to add the following under the provider field:</p><pre>provider:<br>  # Generated code...<br>  apiGateway:<br>    minimumCompressionSize: 1024 # Enable gzip compression for responses &gt; 1 KB<br>  environment:<br>    SERVICE: ${self:service}<br>    STAGE: ${opt:stage}<br>    AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1 # Use http keep-alive for AWS connections</pre><p>Let&#39;s add the GraphQL and <a href="https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-lambda">ApolloServer</a> dependencies:</p><pre>yarn add graphql apollo-server-lambda graphql-tag graphql-tools</pre><h3>Create the GraphQL API</h3><p>Create the GraphQL and schema index.js files:</p><pre>mkdir -p src/graphQl/schema &amp;&amp; touch src/graphQl/index.js &amp;&amp; touch src/graphQl/schema/index.js</pre><p>Since we’re just setting up the server, we’ll create a temporary GraphQL schema for testing purposes. Add the following to your <a href="https://gist.github.com/chris-feist/769f8ca67edab408a49b87b3fc51c8d4">schema index file</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9003ee4d339be6aacfa4ba773f1dab5a/href">https://medium.com/media/9003ee4d339be6aacfa4ba773f1dab5a/href</a></iframe><p>Now we can set up our GraphQL handler code. Update your <a href="https://gist.github.com/chris-feist/b1c9405c1384443f9e329c37ffe5a0d6">GraphQL index file</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1790914bce5f9d592623500c485c5857/href">https://medium.com/media/1790914bce5f9d592623500c485c5857/href</a></iframe><p>You’ll notice we have enabled <a href="https://graphql.org/learn/introspection/">introspection</a> when not using a prod stage. If developing a public API, you should always enable it so that your API consumers can view the documentation.</p><p>Add the GraphQL function to your serverless.yml file under the functions field:</p><pre>functions:<br>  graphQl:<br>    handler: src/graphQL/index.graphQlHandler<br>    events:<br>      - http:<br>          path: /graphql<br>          method: post<br>          cors: true</pre><p>Now we have a functioning GraphQL service that can be deployed! You can test out a <em>dev</em> deployment by running:</p><pre>yarn serverless deploy -s dev</pre><h3>Setup GraphQL Playground</h3><p>Manually invoking a GraphQL API is cumbersome, so we’re going to set up a <a href="https://github.com/prisma-labs/graphql-playground">GraphQL Playground</a> environment to make manual testing of our API much easier.</p><p>Install the GraphQL Playground dependencies:</p><pre>yarn add graphql-playground-middleware-lambda aws-lambda</pre><p>Add the playground handler to your <a href="https://github.com/chris-feist/example-graphql-service/commit/6733af40590314fa57cedf22d4e22009acaabead">GraphQL index file</a>:</p><pre>import lambdaPlayground from &#39;graphql-playground-middleware-lambda&#39;;</pre><pre>export const playgroundHandler = lambdaPlayground({<br>  endpoint: `/${process.env.STAGE}/graphql`,<br>});</pre><p>Now add the playground function to your serverless.yml file:</p><pre>functions:<br>  # Existing graphQl function<br>  <br>  playground:<br>    handler: src/graphQL/index.playgroundHandler<br>    events:<br>      - http:<br>          path: /playground<br>          method: get<br>          cors: true</pre><p><em>You may consider securing your playground API unless your API is public</em></p><p>Now let&#39;s deploy our service so we can use the playground:</p><pre>yarn serverless deploy -s dev</pre><p>You should see the deployment result like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0jEjfBRh0oEA7J6D7j3SxQ.png" /></figure><p>Grab the playground endpoint and paste it into your browser. It should load up the playground and allow you to view our temporary schema and query the ping field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eyYhwz725eRoYJEI2gcOXw.png" /></figure><h4>Extra Credit: Unit Tests</h4><p>We will be using <a href="https://jestjs.io/">Jest</a> for our testing framework. Add the dependencies and initialize the project:</p><pre>yarn add -D jest babel-jest @babel/core @babel/preset-env<br>yarn jest --init</pre><p>Create a babel.config.js file in the root of your project:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02fdeb0eaa61f5aaaff877b750272da1/href">https://medium.com/media/02fdeb0eaa61f5aaaff877b750272da1/href</a></iframe><p>Now you can create some <a href="https://github.com/chris-feist/example-graphql-service/commit/946bd7a53e29c7729a3ccb082c26b36703e5b13a">unit tests</a>.</p><p>Follow the <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering Blog</a> and stay tuned for the next part which will include creating the API data with corresponding GraphQL schema and resolvers. Check out the <a href="https://github.com/chris-feist/example-graphql-service/tree/part1-the-service">example repo</a> for an implementation of everything up to this point.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e790c54f9adf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jetclosing-engineering/setting-up-a-production-graphql-server-part-1-the-server-e790c54f9adf">Setting up a Production GraphQL Server — Part 1: The Server</a> was originally published in <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create your own React hook]]></title>
            <link>https://medium.com/jetclosing-engineering/create-your-own-react-hook-5cae013304d2?source=rss----cf40ca17ba00---4</link>
            <guid isPermaLink="false">https://medium.com/p/5cae013304d2</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Tue, 02 Jul 2019 17:26:23 GMT</pubDate>
            <atom:updated>2019-07-02T17:26:23.685Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ONV-2xMNggMQCnUPJtZDFw.png" /></figure><p><a href="https://reactjs.org/docs/hooks-intro.html">React hooks</a> are a powerful way to supercharge functional components. However, beyond the useState and useEffect hooks, the <a href="https://reactjs.org/docs/hooks-custom.html">examples</a> for creating your own hooks are not very extensive. Let’s look at a practical example by implementing a file drag and drop on the whole window, which we’ll call the “Window Drop Zone”.</p><p>To get started, let&#39;s create our hook file. The <a href="https://reactjs.org/docs/hooks-custom.html#extracting-a-custom-hook">naming convention</a> for hooks is “use” plus the hook name, so let&#39;s create a file called useWindowDropZone.js with a basic shell function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f3b9a5b9379cebe843b862257969a0c/href">https://medium.com/media/3f3b9a5b9379cebe843b862257969a0c/href</a></iframe><p>When we use the window drop zone hook, we’ll want an onDrop callback that is invoked when the user drops files. We’ll need to use the <a href="https://reactjs.org/docs/hooks-reference.html#useeffect">useEffect</a> hook in order to add and remove the onDrop callback event listener.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef234ba3966ee127db28d648f04af272/href">https://medium.com/media/ef234ba3966ee127db28d648f04af272/href</a></iframe><p>The <a href="https://reactjs.org/docs/hooks-reference.html#useeffect">useEffect</a> hook is documented well, but here is a quick explanation: The first argument is a function that is executed on every render. It can optionally return a cleanup function that is executed before every re-render and when the component is unmounted. In our case, we’re adding the drop listener to the window and removing it in the cleanup function. The second argument of useEffect is an optional array of values that the effect depends on. This allows us to conditionally run the effect, instead of executing it on every render. In our case, we are saying only add the drop event listener when the onDrop argument changes. This means we don’t have to unnecessarily remove and re-add the listener on every render.</p><p>Let&#39;s see <a href="https://codesandbox.io/embed/usewindowdropzone-ondrop-88zk8">our new hook</a> in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNm97D1-6aGqOmdakCVjaQ.gif" /></figure><h4>🤔🤔🤔</h4><p>It doesn’t appear to be working… What’s happening is that the browser is consuming the event and loading our dropped file. In order to fix this, we need to call the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault">preventDefault</a> method on the event. So we’ll have to supply our own drop event listener and a dragover listener to prevent the default event handling. We could easily create our own event listener functions to handle this. However, since we’re expecting our useWindowDropZone hook to be used in a functional component, that means each render will cause a new function to be created. Thankfully, React already has the <a href="https://reactjs.org/docs/hooks-reference.html#usecallback">useCallback</a> hook that only creates the function once, unless the dependencies change. Let’s see how this looks inside our hook:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb5100552aec8dcb16ff4d416b00bbd0/href">https://medium.com/media/bb5100552aec8dcb16ff4d416b00bbd0/href</a></iframe><p>So what did we do? We created onDropCallback that prevents the default handling of the event and calls the onDrop argument that is supplied to our hook. Like the useEffect hook, the second argument to the hook is an array of dependencies. In our case, we only want a new onDropCallback to be created when onDrop changes. We also created the onDragoverCallback that prevents the default event handling and we claim it has no dependencies by supplying an empty dependency array. This means that it will only be created once no matter how many times our useWindowDropZone hook is invoked while rendering. We also updated the drop event listener to use our new onDropCallback function, added a new dragover listener, and updated the effects dependencies.</p><p>Now let&#39;s see if our <a href="https://codesandbox.io/embed/usewindowdropzone-drop-dragover-yujnd">modified hook</a> works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRKFgRh0xs3UErZOjtLkmA.gif" /></figure><h4>Success!</h4><p>What if we could take this a step further and provide a dragging state from our hook? We can do that by returning an isDragging field from our hook. We’ll have to do some wiring up internally and leverage the <a href="https://reactjs.org/docs/hooks-reference.html#usestate">useState</a> and <a href="https://reactjs.org/docs/hooks-reference.html#useref">useRef</a> hooks:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5db0785833c576dd14ab183566d3c872/href">https://medium.com/media/5db0785833c576dd14ab183566d3c872/href</a></iframe><p>useRef what!?! An overlooked benefit to this hook is that it allows us to <a href="https://reactjs.org/docs/hooks-faq.html#is-there-something-like-instance-variables">keep track of mutable values</a> while not triggering rerenders. In our case, we need to count how many times we receive the dragenter and dragleave events so we can know when the drag has initially entered and finally left. Since we do want to trigger rendering when the dragging state changes, we use the useState hook. We also added a couple more event listeners and tied it all together. Let’s see our <a href="https://codesandbox.io/embed/usewindowdropzone-isdragging-wnwsu">latest changes</a> in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4PvIrWfN4ZWDTM41GYL4Hg.gif" /></figure><h4>It works!</h4><p>Now that we have a solid functioning hook, we could expand its features to include things such asonDragEnter and onDragLeave callbacks.</p><p>The true powers of hooks are yet to be fully realized, but with the right know-how, you can start to harness their power. Hopefully, this post will help you in creating your own hooks or expanding on existing ones. If you have any comments, feel free to leave them below and make sure to follow the <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering blog</a> to see some of the great stuff we’re working on.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5cae013304d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jetclosing-engineering/create-your-own-react-hook-5cae013304d2">Create your own React hook</a> was originally published in <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Native Device Testing w/ Appium, Node, and AWS Device Farm]]></title>
            <link>https://medium.com/jetclosing-engineering/react-native-device-testing-w-appium-node-and-aws-device-farm-295081129790?source=rss----cf40ca17ba00---4</link>
            <guid isPermaLink="false">https://medium.com/p/295081129790</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[webdriverio]]></category>
            <category><![CDATA[aws-device-farm]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[appium]]></category>
            <dc:creator><![CDATA[Nick Ames]]></dc:creator>
            <pubDate>Fri, 29 Mar 2019 16:25:24 GMT</pubDate>
            <atom:updated>2019-03-29T16:25:24.103Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*_6gvcjZ4M-aBO94tJTviIg.png" /><figcaption>Photo by <a href="https://unsplash.com/@luisviol">Luis Villasmil</a> on <a href="https://unsplash.com/photos/1HzaqbBpxBs">Unsplash</a></figcaption></figure><p>At <a href="https://www.jetclosing.com/">JetClosing</a>, we put a considerable emphasis on testing, especially for our mobile applications. We use <a href="https://facebook.github.io/react-native/">React Native</a> to quickly build out features for both iOS and Android. React Native provides a wonderful framework for building cross-platform applications; however, it not only increases the testing scope but also increases the difficulty for writing true end-to-end integration and automated UI testing on real devices.</p><p>We wanted to avoid using different languages and massive frameworks such as C# and Xamarin and stay within the Node ecosystem. Fortunately, there are existing frameworks available for testing mobile applications with Node: <a href="http://appium.io/">Appium</a> and <a href="https://webdriver.io/">WebdriverIO</a>. Appium allows us to use the WebDriver protocol to send/receive information to/from the device. WebdriverIO provides an API for Node that will allow us to connect to the Appium server and run our tests. Armed with these two, we are able to not only test locally on emulators and simulators but also in the cloud on real devices thanks to AWS Device Farm and their support for Appium with Node.</p><p>Our goal for this article is to help you understand how to test your React Native application in Device Farm using Appium and WebdriverIO. We will cover the following topics:</p><ul><li>Setting up your environment for testing.</li><li>Allowing components in our app to be selected in our tests.</li><li>Creating the Android APK and iOS IPA/App needed for both local testing and Device Farm.</li><li>Testing with WebdriverIO and Appium locally.</li><li>And finally, running our tests in Device Farm.</li></ul><p>We are making a few assumptions in the article:</p><ul><li>You are developing on a Mac (iOS and Android).</li><li>You have a React Native project (non-Expo or ejected).</li></ul><p>Last, here are the versions we will be using:</p><ul><li>Appium 1.9.1</li><li>React Native 59.1</li><li>React 16.8.3</li><li>XCode 10.1</li></ul><p>If you would like to set up a new project, please follow the instructions here: <a href="https://facebook.github.io/react-native/docs/getting-started">https://facebook.github.io/react-native/docs/getting-started</a>. You will want to select <em>React Native CLI Quickstart</em>. Once your development environment is set up and you are able to run your application, you are ready to begin configuring the application for testing.</p><p>I have also set up an example repository that contains a React Native application and tests. Check it out here: <a href="https://github.com/names144/RNDeviceFarm">https://github.com/names144/RNDeviceFarm</a></p><h3>Installing Appium</h3><p>Before we begin testing in Device Farm, we will want to run our tests locally on simulators/emulators so we do not waste time and money on things such as syntax errors.</p><p>For this article, we will be using Appium 1.9.1 and the CLI utility. Appium can be installed as a desktop application and/or as a CLI utility. I highly recommend the desktop application, as it gives you the ability to view your components and their properties in a simple interface. You can download the application from their <a href="https://github.com/appium/appium-desktop/releases">Github</a>.</p><p>To install the Appium CLI, simply run the following:</p><pre>npm install -g appium@1.9.1</pre><p>It is also highly recommended you install appium-doctor to ensure your system has all dependencies required by Appium.</p><p>For more information on installing and configuring Appium, please see: <a href="http://appium.io/docs/en/about-appium/getting-started/">http://appium.io/docs/en/about-appium/getting-started/</a></p><h3>Setup Component Selection for Tests</h3><p>To test our application, we will need the ability to select components to perform validation checks and actions. Unfortunately, there isn’t a standard way to set a component as selectable by the Webdriver testing framework within React Native for both Android and iOS. On iOS, we can use the attribute <em>testID</em>, while on Android we will need to use <em>accessibilityLabel</em>. For more information on this issue, see this Github thread: <a href="https://github.com/facebook/react-native/issues/7135">https://github.com/facebook/react-native/issues/7135</a>.</p><p>To remedy this, we will need to create a utility that will apply the correct attribute for the current platform.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0361e7de84b4f6cb82754787e16290d9/href">https://medium.com/media/0361e7de84b4f6cb82754787e16290d9/href</a></iframe><p>This gives us a simple utility for setting the selectable ID needed when doing our testing.</p><h3>Create Android APK</h3><p>Creating and testing the Android APK is fairly straightforward. We will want to create an APK file that can be used by Appium and AWS Device Farm. To do this, we can run the following from the root of the project:</p><pre>cd android &amp;&amp; ./gradlew assembleRelease</pre><p>The APK should be located at android/app/build/outputs/apk/release/app-release-unsigned.apk. Don’t worry about signing this APK: Appium will sign it and install it on the emulator before testing (Device Farm will do the same before running tests).</p><h3>Create iOS IPA/App Build</h3><p>Creating an IPA/App file for iOS is a bit more involved. We will need to create an IPA for Device Farm and a .app file for our local simulator testing.</p><p>To create the iOS app for local testing, open your Xcode project file from the ios directory.</p><p>Once your project is opened in Xcode, select the device you would like to run your tests against locally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*4mJYpVfRbMCVegScBAAIvA.png" /><figcaption>For my testing, I used an iPhone X. Appium will run the tests locally on this device.</figcaption></figure><p>Now that we have our device selected, we can tell Xcode to build our application for release, so we can target our production build with our tests. Go to Product -&gt; Scheme -&gt; Manage Schemes and change your scheme<em> </em>Run Build Configuration to Release.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gVljfXPlHOfI065MT-Cvkw.png" /><figcaption>Changing the build configuration to Release to target our production build.</figcaption></figure><p>Next, we will want to build the app for the simulator device we selected. Select Product -&gt; Clean and Product -&gt; Build<em>.</em> This will create a .app file in your Xcode build output directory. The default should be ~/Library/Developer/Xcode/DerivedData/. Once your app builds and you have verified the .app file exists, you are ready to test on the simulator locally.</p><p>For Device Farm, we will need to create a signed IPA file. Device Farm will re-sign our IPA file before installing on their devices, but we still need to archive our app and sign it. We can choose either Development or Ad Hoc signing when archiving our app.</p><p>Before we are able to archive we will need to change our device from a simulator device to Generic iOS Device<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*sSH6pfthhpz8zmFCb42IdA.png" /><figcaption>To archive our app we need to select the Generic iOS Device.</figcaption></figure><p>Now, go to Product -&gt; Clean and Product -&gt; Archive<em>. </em>Once the app is archived, select Distribute App -&gt; Development or Ad Hoc -&gt; Uncheck Bitcode Option -&gt; Automatic Signing<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PUQIYkwZURe0tzyNaA5iyA.png" /><figcaption>Use either Development or Ad Hoc for Device Farm.</figcaption></figure><p>You should now have an IPA file that can be used for Device Farm testing.</p><h3>Create and Run Tests Locally</h3><p>For our tests, we will be using WebdriverIO and Appium. WebdriverIO not only allows us to communicate to Appium with the WebDriver protocol but also gives us a test runner to easily run our tests.</p><p>Before we begin writing tests, we will create a new directory that will hold our node_modules needed for our tests and test runner. Device Farm requires a zip file containing our tests and their dependencies.</p><p>From the root of your project, create a new directory for testing and add a package.json so that we can install our needed packages.</p><pre>mkdir integration &amp;&amp; cd integration &amp;&amp; npm init -y</pre><p>We will need to install a few packages so that we are able to run our tests in Device Farm.</p><pre>npm install --save webdriverio @wdio/cli</pre><p>Now, we need to set up our Webdriver configurations. The Webdriver CLI allows us to quickly create a configuration file through a few questions.</p><pre>npx wdio config</pre><p>This will install the dependencies needed based on your selections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*QnvCizygUo8Ryxkk7kk67A.png" /><figcaption>An example of the CLI configuration generator.</figcaption></figure><p>Feel free to change any of the values in the wdio.conf.js file that is generated. To view my configuration files, please see: <a href="https://github.com/names144/RNDeviceFarm/tree/master/integration">https://github.com/names144/RNDeviceFarm/tree/master/integration</a></p><p>After we have configured our Webdriver test runner, we can test that everything is installed and working by running the test driver.</p><p>First, start the Appium server and your emulator/simulator, then run the following:</p><pre>npx wdio ./wdio.conf.js</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*1Qlf0qy3TJfmrWM7_P7SvA.png" /><figcaption>We get an error because we have no tests!</figcaption></figure><p>If you are able to run the test runner and see an error about missing tests, you are now ready to write some tests.</p><p>Add a test file in the test directory for the Webdriver test runner.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/545fae2a11d60465a9e1c75958f60966/href">https://medium.com/media/545fae2a11d60465a9e1c75958f60966/href</a></iframe><p>Now, we are ready to run tests against our application. Add the cross-platform test ID attribute to a component in your application and build the APK or .app file. In the wdio.conf.js file, update the capabilities to include information about the app location, emulator/simulator, etc.</p><p>Below is an example of a configuration for Android.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e4f10644c232fd97cbdbf26143a3ab7/href">https://medium.com/media/1e4f10644c232fd97cbdbf26143a3ab7/href</a></iframe><p>If you have everything set up correctly, running the test runner again should yield the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*DfZByXydbjf1tp1M7GVbWw.png" /><figcaption>Example of a successful test run for the local test.</figcaption></figure><p>You can also watch your emulator as the tests are running!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*zutQlbbZ27rQUIBTIYy22g.gif" /><figcaption>Watch your tests run on an emulator!</figcaption></figure><h3>Run Tests in Device Farm</h3><p>After successfully running our tests locally on the simulator/emulator, we are ready to upload to Device Farm!</p><p>Before uploading, we will need to prepare our tests and bundle everything into a zip file. To do this, we will use <a href="https://github.com/majgis/npm-bundle">npm-bundle</a>.</p><pre>npm install --save-dev npm-bundle</pre><p>Now we need to add bundle dependencies to our package.json:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55cfdd6941b3415618d8ce57a30ca9f0/href">https://medium.com/media/55cfdd6941b3415618d8ce57a30ca9f0/href</a></iframe><p>Running the package NPM script will bundle our package and then put it into a zip file that will be ready to upload to Device Farm.</p><p>Before you run the pack, you will need to remove the capabilities from the wdio.conf.js file. Remove all attributes except for maxInstances as Device Farm sets the capabilities needed.</p><p>After we have updated the wdio.conf.js file and ran npm run package we should have a zip file that is ready to be uploaded to Device Farm. Open Device Farm, create a new project or choose an existing project and click Create a new run<em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inmVb9UnjmcsQRwmOK0VeQ.png" /><figcaption>Upload your APK or IPA file that we built previously.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GaHhUfnrUEaHwjPmyDecNw.png" /><figcaption>Upload your zip file and edit the Appium YAML configuration to run the tests. In this example, we have an NPM script that runs ‘npx wdio wdio.ios.conf.js’ for iOS.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3JFRhSkO9MIInB1PzOXLQ.png" /><figcaption>Select the device(s) you want to run your tests against.</figcaption></figure><p>You can also adjust network speed, directories, install other apps, and more. I left the device state as the default state and started the run. If everything goes smoothly you should see the output from the tests in the AWS console and eventually a successful test run!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*bItxjuw_zsNcoA_au3saPg.gif" /><figcaption>AWS Device Farm stream of our test on a real iPhone device.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Dmht0Xtu7xXqkSvTiiQYg.png" /><figcaption>All greens indicating our tests passed in Device Farm.</figcaption></figure><p>Armed with the information in this article, you should now have the ability to test your React Native applications not only on emulators/simulators but on real physical devices in AWS Device Farm.</p><p>You can check out my example repository here: <a href="https://github.com/names144/RNDeviceFarm">https://github.com/names144/RNDeviceFarm</a></p><p>This article was inspired by <a href="https://medium.com/@dabit3/testing-mobile-applications-across-hundreds-of-real-devices-with-appium-node-js-aws-device-farm-b749aefd651a">https://medium.com/@dabit3/testing-mobile-applications-across-hundreds-of-real-devices-with-appium-node-js-aws-device-farm-b749aefd651a</a></p><p>Thanks for reading and if you have any questions/comments please leave them below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=295081129790" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jetclosing-engineering/react-native-device-testing-w-appium-node-and-aws-device-farm-295081129790">React Native Device Testing w/ Appium, Node, and AWS Device Farm</a> was originally published in <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing private JavaScript functions using Babel]]></title>
            <link>https://medium.com/jetclosing-engineering/testing-private-javascript-functions-using-babel-20cab9bc48f4?source=rss----cf40ca17ba00---4</link>
            <guid isPermaLink="false">https://medium.com/p/20cab9bc48f4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[babel]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Chris Feist]]></dc:creator>
            <pubDate>Tue, 18 Sep 2018 17:25:35 GMT</pubDate>
            <atom:updated>2018-12-18T18:42:03.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Flxld10x12l6HfmMj7zEYw.jpeg" /></figure><p>At <a href="http://www.jetclosing.com/">JetClosing</a> we utilize decomposition and modular programming. As projects get larger, it’s important to clearly define the interface between objects by exporting the methods that make up that interface. Sometimes this can cause issues when trying to unit test that code, especially the private functions. The existing strategies for accomplishing this have their own issues:</p><ul><li><strong>Exposing private members</strong> - This creates potential security issues and can effect development; such as when auto imports suggest the intended private members over other public members.</li><li><strong>Testing through public functions</strong> - This approach is a pain! In order to have targeted tests for the private functions, it requires a bunch of setup and teardown code just to ensure the private function is executed.</li><li><strong>Use existing 3rd party options</strong> - The current options are limited, and require multiple plugins or custom test imports; such as <a href="https://www.npmjs.com/package/denude">denude</a> and <a href="https://www.npmjs.com/package/babel-plugin-test-export">babel-plugin-test-export</a>.</li></ul><p>None of these strategies are ideal or practical in large projects, so we decided to create our own solution as a single Babel plugin: <a href="https://github.com/JetClosing/babel-plugin-testable">babel-plugin-testable</a>. Like most modern javascript developers, we are using Babel to compile modern javascript into backwards compatible code. Therefore, we made a plugin that could export our ES6+ code for testing purposes.</p><h3>Integrating the plugin</h3><h4>Install</h4><p>Install the plugin using your favorite package manager: npm install -D babel-plugin-testable or yarn add -D babel-plugin-testable.</p><h4>Enable</h4><p>Add the plugin to your Babel configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c11c9c4d297cacea3907eaf91554caa/href">https://medium.com/media/4c11c9c4d297cacea3907eaf91554caa/href</a></iframe><h3>Using the Plugin</h3><p>Now, decorate and import!</p><h4>Decorate</h4><p>Add testable comments to the code you want to test:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3238049deed3f2e390b737956be68442/href">https://medium.com/media/3238049deed3f2e390b737956be68442/href</a></iframe><h4>Import</h4><p>Import your private members along with the public members in your tests, and add any test code you need:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ca55b190e50db54abb3e509df954069/href">https://medium.com/media/0ca55b190e50db54abb3e509df954069/href</a></iframe><h3>That’s it!</h3><p>Now you can import any private function, variable, or class for testing purposes. Simple and clean!</p><h4>The Nitty Gritty</h4><p>So how does it work? This is pretty simple too!</p><p>When compiling the code, the plugin keys off of the NODE_ENV or BABEL_ENV environment variables to determine if the code is being compiled for tests. If neither of these are &#39;test&#39;, then it compiles as it normally would. Otherwise, it looks for top level private members (variables, functions, and classes) that are annotated with the // @testable comment, and adds an export in front of them. This allows the private members to be imported in your test files like any other exported member.</p><h3>Give it a shot!</h3><p>Now that we’ve made testing private members easier for you, give it a shot! Let us know what you think in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20cab9bc48f4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jetclosing-engineering/testing-private-javascript-functions-using-babel-20cab9bc48f4">Testing private JavaScript functions using Babel</a> was originally published in <a href="https://medium.com/jetclosing-engineering">JetClosing Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>