<?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 Cheyu Wu on Medium]]></title>
        <description><![CDATA[Stories by Cheyu Wu on Medium]]></description>
        <link>https://medium.com/@cheyu1220?source=rss-5415642fdd3c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NXZH2GbhkNv0enB9BM7DnQ.jpeg</url>
            <title>Stories by Cheyu Wu on Medium</title>
            <link>https://medium.com/@cheyu1220?source=rss-5415642fdd3c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 16:20:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cheyu1220/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[c]]></title>
            <link>https://medium.com/@cheyu1220/c-4fa56c23e8a4?source=rss-5415642fdd3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fa56c23e8a4</guid>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[commonjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Cheyu Wu]]></dc:creator>
            <pubDate>Sat, 13 May 2023 12:00:44 GMT</pubDate>
            <atom:updated>2024-09-25T16:46:03.684Z</atom:updated>
            <content:encoded><![CDATA[<h3>Navigating CommonJS and ES Module Challenges in Express.js</h3><h3><strong>Introduction</strong></h3><p>When we import other JavaScript packages into a Node.js project, we may need some help. For instance, if we import an ES Module package but our project is using CommonJS, we may not be successful because CommonJS does not allow the importation of the ES Module packages. However, we can solve this problem by changing our project type to a <a href="https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#im-having-problems-with-esm-and-webpack">pure ES Module package</a>, which allows ES Module to access both ES Module and CommonJS packages.</p><blockquote>However, the real world is not that simple. Let’s take a look at a more complex problem.</blockquote><h3><strong>What’s the Real Problem?</strong></h3><p>Imagine that you are importing a legacy library that your company maintains. The library is written in Typescript and is exported as an ES Module package, but it was not built as a pure ESM package. This means that it is neither an ES Module nor a CommonJS package. If this were the only issue, you could fix the legacy library by changing it to an ESM package.</p><p>However, if this library imported other packages that are neither ES Module nor CommonJS libraries, and then exported them as an ES Module package, you would encounter an awkward error message when you compiled your project. The error message would ask you to add the following to your package.json</p><pre>{<br>  &quot;type&quot;: &quot;module&quot;<br>}</pre><p>After you change your package.json, you may encounter another error message when you compile your project that asks you to remove it.</p><blockquote>This will be an endless fix for the ES Module package.</blockquote><blockquote>Before we solved the problem, let’s figure out what is going on.</blockquote><h3><strong>Explaining the problem</strong></h3><p>The problem is that our project considers the imported package an ES Module, but some of the code is written in CommonJS. The compiler cannot identify the code and the error occurs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NY55VdKdU1cvD5QjHYSXg.png" /></figure><h3>Environment</h3><blockquote>Node.js: v19.8.1<br>npm: 9.6.4<br>Express.js: 4.18.2<br>Wepack: 5.75.0</blockquote><h3><strong>How can we handle this problem?</strong></h3><p>You can solve this problem through <a href="https://webpack.js.org/">Webpack</a>. There is an example with the Express.js server.</p><blockquote>The following shows the Express.js project structure.</blockquote><pre>├── docker-compose.yaml<br>├── Dockerfile<br>├── package.json<br>├── README.md<br>├── src<br>│   ├── app.ts<br>│   ├── controllers<br>│   ├── modules<br>│   └── routes<br>├── test<br>│   ├── myTestScript.test.ts<br>├── tsconfig.json<br>├── vite.config.ts<br>├── webpack.config.cjs<br>└── yarn.lock</pre><blockquote>The webpack.config.cjs should look like</blockquote><pre>const path = require(&#39;path&#39;);<br>const CopyPlugin = require(&#39;copy-webpack-plugin&#39;)<br><br>const config = {<br>  target: &#39;node&#39;,<br>  entry: rootDir(&#39;src/app.ts&#39;),<br>  node: {<br>    __dirname: false,<br>    __filename: true,<br>    global: true<br>  },<br>  output: {<br>    path: rootDir(&#39;dist&#39;),<br>    filename: &#39;[name].bundle.cjs&#39;<br>  },<br>  module: {<br>    rules: [{<br>      test: /\.[tj]s$/,<br>      use: &#39;ts-loader&#39;,<br>      exclude: /node_modules/,<br>    }]<br>  },<br>  resolve: {<br>    extensions: [&#39;.js&#39;, &#39;.ts&#39;],<br>    conditionNames: [&#39;import&#39;, &#39;require&#39;, &#39;node&#39;],<br>  },<br>  snapshot: {<br>    // Note: skip yarn link protocol path to avoid warning, Ref: https://github.com/webpack/webpack/pull/14509#issuecomment-1237348087<br>    managedPaths: [/(node_modules\/(?!@\/|SVG)).*/],<br>  },<br>  stats: {<br>    errorDetails: true,<br>    colors: true,<br>  },<br>  ignoreWarnings: [<br>    // some warning that you wanted to ignore<br>    {<br>      module: file,<br>      message: /some regular expression/<br>    }<br>  ],<br>  plugins: [<br>    new CopyPlugin(<br>      {<br>        patterns: [<br>          // Copy static asset files so that they can be served from output directory as swagger-ui-dist does not work<br>          // with webpack.<br>          rootDir(&#39;Your Static files&#39;),<br>        ]<br>      }<br>    ),<br>  ],<br>}<br><br>function rootDir(dir) {<br>  return path.join(__dirname, &#39;..&#39;, dir);<br>}<br><br>module.exports = config;</pre><h3><strong>Conclusion</strong></h3><p>The article briefly introduces the benefit of ES modules in importing CommonJS and gives an example in a real-world scenario.</p><p>The article explains the problems in a real-world scenario and gives a solution to the problem with Webpack 5.</p><p>If there are any problems, feel free to ask or leave a comment.</p><blockquote>Hope you guys don’t spend whole day looking for this problem like I did.</blockquote><h3>Reference</h3><ul><li><a href="https://webpack.js.org/">Webpack5</a></li><li><a href="https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#im-having-problems-with-esm-and-webpack">Pure ES module Package</a></li><li><a href="https://expressjs.com/">Express js</a></li><li><a href="https://nodejs.org/api/packages.html#approach-1-use-an-es-module-wrapper">Dual CommonJS and ES Module</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fa56c23e8a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy mobile automation testing with WebdriverIO x Appium on AWS Device Farm]]></title>
            <link>https://medium.com/@cheyu1220/deploy-mobile-automation-testing-with-webdriverio-x-appium-on-aws-device-farm-84136ff42aa9?source=rss-5415642fdd3c------2</link>
            <guid isPermaLink="false">https://medium.com/p/84136ff42aa9</guid>
            <category><![CDATA[aws-device-farm]]></category>
            <category><![CDATA[appium]]></category>
            <category><![CDATA[webdriverio]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[automation-testing]]></category>
            <dc:creator><![CDATA[Cheyu Wu]]></dc:creator>
            <pubDate>Sat, 20 Aug 2022 10:53:39 GMT</pubDate>
            <atom:updated>2023-03-09T15:32:19.155Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*rxaAHi9GMN67Z6uBXok6cw.png" /></figure><h3>Abstract</h3><p>Maintaining the quality of the mobile app is very important when it comes to developing a mobile application. No matter how useful the app is if the app contains lots of bugs and worst performance. The user’s willingness will drop significantly. Therefore, to ensure the quality of the app is meaningful.</p><h3>Limitation</h3><p>This article will briefly introduce environment settings and <strong>running android locally </strong>and <strong>how to deploy on AWS Device Farm.</strong></p><p>About the iOS app, <strong>you can do the same operation locally which is similar to android</strong>. However,<strong> I will only show you the YAML file which can deploy on AWS Device Farm</strong>, because I cannot generate the .<strong>ipa</strong> file on my own.</p><h3>Introduced to our tools</h3><p><a href="https://appium.io/">Appium</a> is a well-known mobile automation testing framework.</p><p><a href="https://webdriver.io/">WebdriverIO</a> is an automation testing framework that combines web and mobile <strong><em>(based on Appium)</em></strong> automation testing with good documentation.</p><p><a href="https://aws.amazon.com/device-farm/">AWS Device Farm</a> is a provider for real device automation testing, which means you can deploy your scripts on AWS and run them on a real mobile phone or computer. <strong>There are 1000 minutes for free credit testing</strong>.</p><h3>Environments</h3><blockquote>Node.js: v17.3.1</blockquote><blockquote>npm: v8.18.0</blockquote><blockquote>yarn: v1.22.19 <strong>(you can use npm instead)</strong></blockquote><blockquote>Appium: 1.22.2 <strong>(Test running in Local only)</strong></blockquote><blockquote>Emulator: Pixel 3 API 30 <strong>(Android local testing)</strong></blockquote><blockquote>Java: 17.0.1 <strong>(Android testing)</strong></blockquote><pre>If you wanted to use yarn and your OS is windows, you can install yarn through <a href="https://scoop.sh/">Scoop</a>.</pre><h3><strong>Let’s get started</strong></h3><h4><strong>Prepare the project environment</strong></h4><p>First of all, we need to download two materials which are the <a href="https://github.com/webdriverio/appium-boilerplate/">WebdriverIO boilerplate</a> and an example app file from WebdriverIO.</p><pre>&gt; git clone <a href="https://github.com/webdriverio/appium-boilerplate.git">https://github.com/webdriverio/appium-boilerplate.git</a></pre><pre>&gt; cd ./appium-boilerplate</pre><pre>&gt; npm install or yarn</pre><pre># create a folder which call apps<br>&gt; mkdir apps/ </pre><p>You can also download the demo <a href="https://github.com/webdriverio/native-demo-app/releases/download/v0.4.0/Android-NativeDemoApp-0.4.0.apk">APK</a> from <a href="https://github.com/webdriverio/native-demo-app/releases"><strong>here</strong></a>, and save your APK files to the <strong>apps/ </strong>folder which we just created above.</p><pre>├── apps/<br>└───── Android-NativeDemoApp-0.4.0.apk<br>├── config/<br>├── docs/<br>├── node_modules/<br>├── scripts/<br>└── tests/</pre><p>Install the <a href="https://www.npmjs.com/package/appium">Appium server</a> and other corresponding packages</p><pre># Appium server<br>&gt; npm i -g appium<br></pre><pre># You can install <a href="https://www.npmjs.com/package/appium-doctor"><strong>Appium doctor</strong></a> to validate your environment<br>&gt; npm install -g appium-doctor</pre><pre>&gt; appium-doctor</pre><p>If your environment is ready, let’s run locally.</p><h4>Run it locally</h4><p><em>Make sure you have already created a pixel 3 emulator and launched it.</em></p><pre>&gt; npm run android.app</pre><pre>or </pre><pre>&gt; yarn run android.app</pre><blockquote>Well, wish your environment is working !!</blockquote><h3>Deploy on AWS Device Farm</h3><p>It comes to the final steps, remember to <strong>enroll in aAWS account</strong> and <strong>need to spend a little time understanding how webdriverIO works</strong>, It won’t be mentioned in this article.</p><h4><strong>Before All</strong></h4><ol><li>Create <strong>aws.config.ts </strong>in <strong>config/ </strong>to run on AWS Device Farm</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tWESAhvwmm706sImCZmShQ.png" /></figure><pre>import { config } from &#39;./wdio.shared.conf&#39;;<br><br>// ============<br>// Specs<br>// ============<br>config.specs = [<br>    // Your spec<br>    &#39;./tests/specs/**/app*.spec.ts&#39;,<br>];<br><br>// ============<br>// Capabilities<br>// ============<br>// For all capabilities please check<br>// http://appium.io/docs/en/writing-running-appium/caps/#general-capabilities<br>config.capabilities = [<br>    {<br>        // The defaults you need to have in your config<br>        appWaitActivity: &#39;*&#39;,<br>        appWaitDuration: 100000,<br>        maxInstances: 1,<br>    },<br>];<br><br>exports.config = config;</pre><p>2. Add <strong>port</strong> and <strong>path</strong> parameters in <strong>config/wdio.shared.conf.ts</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*3zWCs7xhPATUhHP2Gnua4Q.png" /></figure><pre>port: 4723,<br>path: &#39;/wd/hub&#39;</pre><p>3. Add npm script in <strong>package.json</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8EqqyjlnR8DxmRiWD3g-uA.png" /></figure><pre>&quot;scripts&quot;: {<br>    &quot;test:app&quot;: &quot;wdio $DEVICEFARM_TEST_PACKAGE_PATH/config/aws.config.ts&quot;<br>}</pre><p>4. Compress your file like the figure below and it will generate a <strong>.zip</strong> file.</p><blockquote><strong>Make sure it won’t generate a parent folder when you unzip it.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fjz8aQKKUgQvpwSmY09H6A.png" /></figure><h4>Open the AWS Device Farm console</h4><ol><li><strong>Create new project</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuQuo-BeCP4Q2OV8KafIvA.png" /></figure><p><strong>2. Create a new run</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C40cT3knyyi7BRvLolJarQ.png" /></figure><p>3. <strong>Upload our .apk file and click the next button</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLKWkrmIGSambz2qEGSvWg.png" /></figure><p>4. <strong>Upload your code</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KvpaLiR14jqj3L5BsOnT7g.png" /></figure><p>5. <strong>After you uploaded your code, you need to create a new TestSpec</strong></p><p>You can find the environment variables <a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environment-env.html"><strong>here</strong></a>.</p><p><strong>Android:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ac5adcde36527c774bb4d554b700a4e/href">https://medium.com/media/6ac5adcde36527c774bb4d554b700a4e/href</a></iframe><p><strong>iOS:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0da9625aa3f58180f4afe2ee813a9a37/href">https://medium.com/media/0da9625aa3f58180f4afe2ee813a9a37/href</a></iframe><p>6.<strong> Finally select the devices and started the test cases.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*Gz98c2pCnnD0hgq7JwHjOw.png" /></figure><p>Thanks for your reading, hope you enjoy it.</p><p>If you have any questions or advice, feel free to ask or comment.</p><p><a href="https://github.com/CheyuWu/deploy-webdriverio-appium-on-aws">Github repository</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84136ff42aa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>