<?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 Yiquan Zhou on Medium]]></title>
        <description><![CDATA[Stories by Yiquan Zhou on Medium]]></description>
        <link>https://medium.com/@yiquanzhou?source=rss-2ebdbc642169------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PLBmqCjbCe9P_X1w.jpeg</url>
            <title>Stories by Yiquan Zhou on Medium</title>
            <link>https://medium.com/@yiquanzhou?source=rss-2ebdbc642169------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:15:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yiquanzhou/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[Run selenium UI tests in Docker container]]></title>
            <link>https://medium.com/@yiquanzhou/run-selenium-ui-tests-in-docker-container-78be98e1b52d?source=rss-2ebdbc642169------2</link>
            <guid isPermaLink="false">https://medium.com/p/78be98e1b52d</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[selenium-webdriver]]></category>
            <dc:creator><![CDATA[Yiquan Zhou]]></dc:creator>
            <pubDate>Mon, 21 Nov 2016 10:52:04 GMT</pubDate>
            <atom:updated>2016-11-21T10:52:04.935Z</atom:updated>
            <content:encoded><![CDATA[<p>A few months ago Atlassian announced the <a href="https://confluence.atlassian.com/bamboocloud/bamboo-cloud-eol-827125716.html">end of life of the Bamboo Cloud</a> continuous delivery offering that we have been using for our project <a href="http://findtheflow.io/">Flow</a>. A new solution called <a href="https://bitbucket.org/product/features/pipelines">Bitbucket pipelines</a> has been introduced as the replacement of Bamboo. It is built within Bitbucket which makes it really close to the source code and it uses Docker containers to run builds. You can use all images hosted on Docker Hub as your build environment or build your own.</p><p>One of the problem that we ran into with this change is that we need to <strong>run our selenium UI tests inside of a Docker container</strong>. I think this case would become more and more common so I’d like to share in this post how to do that.</p><p>The major problem of a Docker container for UI testing is that it does not have a screen output. There are in general two solutions: <strong>use a headless browser</strong> such as HTMLUnit that does not require a graphical user interface or <strong>simulate a screen output</strong>.</p><p>I choose the second one because in this case I do not need to change my testing code to use a WebDriver for a headless browser. Moreover, <strong>headless browser may not have full functionalities of a real browser</strong>. For example, the web application that we test uses WebSocket which is not supported by HTMLUnit.</p><p>What I need is a display server called Xvfb or X virtual frame buffer<strong>. </strong>It performs all graphical operations in memory without showing any screen output.</p><p>So first I create a Docker image with a Dockerfile and install firefox and Xvfb on it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be3fd1a29c0aede058c8950d6c758969/href">https://medium.com/media/be3fd1a29c0aede058c8950d6c758969/href</a></iframe><p>Once the image is built, I can run this image and verify that firefox is installed at <em>/usr/bin/firefox</em>.</p><pre>$ docker run -it firefox-image</pre><pre>$ firefox -v<br>Mozilla Firefox 45.0</pre><p>But if I try to run firefox I will get an error:</p><pre>$ firefox<br>Error: cannot open display: :99</pre><p>This is because there is no screen output. You will get the same error if you try to run the UI tests directly in this Docker container. To solve this issue, we need to start the Xvfb display server before running the UI tests. You can find the command and options by referring to the <a href="https://linux.die.net/man/1/xvfb">Xvfb manual</a> :</p><pre>$ Xvfb :99 -ac &amp;</pre><p>This command runs a virtual display server as a background process. It will listen for connections as server number 99, which is required by firefox. The <em>-ac</em> flag disabled the access control to the display. Now you can run your UI tests with maven or whatever command you use.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78be98e1b52d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to structure real world Redux/React application]]></title>
            <link>https://medium.com/@yiquanzhou/how-to-structure-real-world-redux-react-application-d61e66a7dd36?source=rss-2ebdbc642169------2</link>
            <guid isPermaLink="false">https://medium.com/p/d61e66a7dd36</guid>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[visualization]]></category>
            <dc:creator><![CDATA[Yiquan Zhou]]></dc:creator>
            <pubDate>Mon, 10 Oct 2016 11:24:25 GMT</pubDate>
            <atom:updated>2016-10-10T11:24:25.628Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I was rewriting in Redux/React the web application of <a href="http://findtheflow.io/">Flow</a>, a tool to help developers better understand the structure and the behavior of their applications. It provides an interactive web interface to <a href="http://findtheflow.io/">visualize the execution flow of Java programs</a>. And I was confronting the problem of how to structure my project.</p><h4>Organize by file nature or by feature / data domain?</h4><p>In most samples and tutorials of Redux/React projects including the official ones, the common file structure is organized <strong>by file natures</strong>: <strong>actions, reducers, selectors, (presentational) components </strong>and<strong> containers</strong>.</p><pre>- app/<br>  - actions/<br>      CallActions.js<br>      ArtifactActions.js<br>      FilterActions.js<br>      ...<br>  - reducers/<br>      CallReducer.js<br>      ArtifactReducer.js<br>      FilterReducer.js<br>      ...<br>  - containers/<br>      CallGraph.jsx<br>      FlameChart.jsx<br>      FilterPanel.jsx<br>  - components/<br>      ...<br>  index.js<br>  rootReducer.js</pre><p>So I started with this structure and I soon found the limit of this approach: <strong>it does not scale</strong>. It’s quite easy to see this coming because <strong>the file nature will always remain the same but features and data domains grow</strong> <strong>in real world applications</strong>. In consequence, we will get more and more files in each of these folders. Moreover, when I started a new feature I was wasting much time scrolling and navigating in my project to find all the files related to the same feature.</p><p>Then I tried to group the files <strong>by features</strong>. But I found some new problems. In the application that I’m working on, we collect data from the execution of a Java application, such as the call stacks, the running threads, the artifacts (packages, classes, methods) and so on. And we build different visualizations/views upon these data in order to help developers better understand their program. For example, we build a <a href="http://findtheflow.io/docs/doc_intellij.html#_call_graph">call graph</a> that represents the artifacts and the relationships between them. We also provide a <a href="http://findtheflow.io/docs/doc_intellij.html#_flame_chart">flame chart</a> that shows all the method calls during the execution. You can search, filter and select artifacts and calls among all the visualizations.</p><p>You can go to the <a href="http://app.findtheflow.io/recording.html?url=aHR0cDovL2Zsb3ctZGVtby5lbGFzdGljYmVhbnN0YWxrLmNvbS9yZWNvcmRpbmdzL2p1bml0"><strong>live demo here</strong></a> to see how these visualizations look like, or checkout <a href="http://findtheflow.io/docs/usecases.html#_understand_junit_runners">this post</a> to see how I use the visualizations to understand Junit runners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xEvOLRU2WBmR3oSbjcARBA.png" /><figcaption>Visualize the execution flow of a Junit test</figcaption></figure><p>I realize that on one hand, <strong>a feature/view often involves multiple data domains</strong>. For example, the rendering of the flame chart will need the threads, the calls and eventually the filters.</p><p>On the other hand, <strong>a data domain can be shared by multiple features and it does not necessarily become a feature or a view itself</strong>. Both call graph and flame chart need the filter data. To me, reducers, actions and selectors control the data and business logic whereas containers and components construct the views.</p><p>Finally I ended up with the following structure by extracting containers and components from the feature folders:</p><pre>-app/<br>  - data/<br>    - artifacts/<br>        ArtifactReducer.js<br>        ArtifactActions.js<br>        ArtifactSelectors.js <br>    - calls/<br>        CallsReducer.js<br>        CallsActions.js<br>        CallsSelectors.js<br>    - filters/<br>        ...<br>    - threads/<br>        ...<br>    - ...<br>  - containers/<br>      FlameChartContainer.jsx // depends on calls, threads, filters<br>      FilterContainer.jsx     // depends on filters<br>      CallGraphContainer.jsx  // depends on artifacts and filters<br>  - components/<br>      ...<br>  index.js<br>  rootReducer.js</pre><p>I think the main advantages of this structure are:</p><ul><li>Different data domains and business logic residing in actions, reducers and selectors are <strong>independent</strong> and <strong>encapsulated</strong>.</li><li>Features and views can be built upon the data and the <strong>dependencies can be clearly identified</strong>.</li><li>The separation of React components reminds you to keep them <strong>highly reusable</strong> across features and views.</li></ul><h4>Module import and export</h4><p>With ES6 module system, each file is a module and we need to export functions and variables from each file and import them in others to use. So when a container depends on a data domain, we may need to import its reducer, actions and selectors. ex.</p><pre>import CallReducer from &#39;../data/calls/CallReducer.js&#39;;<br>import * as CallActions from &#39;../data/calls/CallActions.js&#39;;<br>import * as CallSelectors from &#39;../data/calls/CallSelectors.js&#39;;</pre><p>This requires a lot of imports with relative paths and the internal structure of the data domain <em>/data/calls</em> is exposed. A better way is to encapsulate the data domain by creating an <em>index.js</em> that exports the internal files of this module.</p><pre>// data/calls/index.js</pre><pre>import CallReducer from &#39;./CallReducer&#39;;<br>import * as CallSelectors from &#39;./CallSelectors&#39;;<br>import * as CallActions from &#39;./CallActions&#39;;</pre><pre>export {<br>  CallReducer,<br>  CallSelectors,<br>  CallActions<br>}</pre><p>This <em>index.js</em> becomes a public API of this data domain and hides its internal file structure from the outside. As a result, dependency on this module in a container will be reduced to only one import:</p><pre>import { CallReducer, CallSelectors, CallActions } from &#39;../data/calls&#39;</pre><p>This looks much better right? You can change the internal structure of the data domain modules without worrying about breaking any dependencies.</p><h4>Where to put the tests?</h4><p>At first I put my tests in a separate folder <em>src/test</em> besides the source folder <em>src/app</em>. As I code a lot in Java as well this looks good to me because that’s how things are done in Maven projects (sources in <em>src/main/java</em> and tests in <em>src/test/java</em>).</p><p>I quickly realise that it is not convenient at all. The tests are far away from the sources. So each time a source file is modified such as <em>src/app/data/calls/CallReducer.js</em>, I need to navigate to the corresponding test <em>src/test/calls/CallReducer.spec.js</em>. When there’s some refactoring, the imports are often broken and unfortunately we do not benefit from the refactoring capabilities of a Java IDE.</p><p>Therefore, I decided to move the tests into the <em>src/app</em> folder so that they are close to the source. In this case, it’s much easier for me not to mess up the import.</p><pre>- app/<br>  - data/<br>    - spec/<br>        CallReducer.spec.js<br>        CallSelectors.spec.js<br>      CallReducer.js<br>      CallActions.js<br>      CallSelectors.js</pre><p>If you are using Karma, Karma will scan and find all the test files easily by their extensions. So the move of the tests are pretty transparent.</p><pre>// karma.conf.js</pre><pre>files:[<br> &#39;src/app/**/*.spec.js&#39;<br>]</pre><h4>Conclusion</h4><p>I really want to share in this post how I organized the file structure of my project and the reasons why I did so. I think that if you start a very simple project on Redux/React, then the organization by file nature will work just fine for you. It may help you to learn the major concepts of Redux. But when things are getting complex, you will find out the limit and adopt other approaches.</p><p>After all, what really matters is how to think of your project in terms of data domains, business logic, views, as well as the dependencies and reusability of all these components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d61e66a7dd36" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>