<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bart Wijnants</title>
    <description>The latest articles on DEV Community by Bart Wijnants (@bartw).</description>
    <link>https://dev.to/bartw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F28867%2F896452ca-48b4-449a-b17a-db4388fb1e4a.png</url>
      <title>DEV Community: Bart Wijnants</title>
      <link>https://dev.to/bartw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bartw"/>
    <language>en</language>
    <item>
      <title>Testing an Apollo GraphQL server using apollo-server-testing, Jest and msw</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Sat, 14 Nov 2020 21:23:09 +0000</pubDate>
      <link>https://dev.to/bartw/testing-an-apollo-graphql-server-using-apollo-server-testing-jest-and-msw-g6k</link>
      <guid>https://dev.to/bartw/testing-an-apollo-graphql-server-using-apollo-server-testing-jest-and-msw-g6k</guid>
      <description>&lt;p&gt;&lt;a href="https://medium.com/@bartwijnants/testing-an-apollo-graphql-server-using-apollo-server-testing-jest-and-msw-feed7d9e05cf?source=rss-3dd8c36bc285------2"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cV9t-o7k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2600/0%2ApefK9U3ObK7cTGYd" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How do you easily test an Apollo GraphQL server that gets data from external api’s?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@bartwijnants/testing-an-apollo-graphql-server-using-apollo-server-testing-jest-and-msw-feed7d9e05cf?source=rss-3dd8c36bc285------2"&gt;Continue reading on Medium »&lt;/a&gt;&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>api</category>
      <category>jest</category>
      <category>testing</category>
    </item>
    <item>
      <title>Agnita: Authentication for Create React App using AWS Cognito</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Mon, 13 Apr 2020 19:37:40 +0000</pubDate>
      <link>https://dev.to/bartw/agnita-authentication-for-create-react-app-using-aws-cognito-181e</link>
      <guid>https://dev.to/bartw/agnita-authentication-for-create-react-app-using-aws-cognito-181e</guid>
      <description>&lt;p&gt;&lt;a href="https://medium.com/@bartwijnants/agnita-authentication-for-create-react-app-using-aws-cognito-80cde1fb781b?source=rss-3dd8c36bc285------2"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zG1vx-uf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2AY8Ixajo0m8Z4Ynfd.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Agnita project is a proof of concept implementation using Amazon Cognito and create-react-app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@bartwijnants/agnita-authentication-for-create-react-app-using-aws-cognito-80cde1fb781b?source=rss-3dd8c36bc285------2"&gt;Continue reading on Medium »&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>I'm building a blog about building a blog</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Mon, 23 Dec 2019 10:54:15 +0000</pubDate>
      <link>https://dev.to/bartw/i-m-building-a-blog-about-building-a-blog-5agg</link>
      <guid>https://dev.to/bartw/i-m-building-a-blog-about-building-a-blog-5agg</guid>
      <description>&lt;p&gt;Some time ago I noticed there was money to be made on &lt;a href="https://medium.com/"&gt;Medium&lt;/a&gt;. I joined the &lt;a href="https://medium.com/creators"&gt;Medium Partner Program&lt;/a&gt; and moved some of my posts behind the &lt;a href="https://help.medium.com/hc/en-us/articles/360018834314-Stories-that-are-part-of-the-metered-paywall"&gt;metered paywall&lt;/a&gt;. Time to become a millionaire.&lt;/p&gt;

&lt;p&gt;I quickly wrote a new blogpost and shared it here and on &lt;a href="https://www.reddit.com/"&gt;Reddit&lt;/a&gt;. This received some backlash as someone commented "Too bad you care about money more than sharing it. ¯(ツ)/¯". That hurt, but it was also kinda true.&lt;/p&gt;

&lt;p&gt;This sparked a thought in my head. I can just create my own blog. Maybe add some ads. And still become a millionaire. I can just blog about building a blog. Easy does it.&lt;/p&gt;

&lt;p&gt;I already have 3 posts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://dev.bartwijnants.be/gatsby-from-scratch/"&gt;Gatsby From Scratch&lt;/a&gt;: Create a very simple Gatsby site from scratch without using a starter.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.bartwijnants.be/fill-the-head-the-rest-will-follow/"&gt;Fill The Head The Rest Will Follow&lt;/a&gt;: Add a header and manifest to a Gatsby site using some basic GraphQL.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.bartwijnants.be/tailwind/"&gt;Tailwind&lt;/a&gt;: Use the Tailwind CSS framework in a Gatsby site.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And a ton of notes waiting to be converted to posts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.bartwijnants.be/"&gt;Check it out&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>react</category>
      <category>graphql</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>Getting started with TypeScript for Node</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Sat, 23 Nov 2019 15:23:10 +0000</pubDate>
      <link>https://dev.to/bartw/getting-started-with-typescript-for-node-5cbe</link>
      <guid>https://dev.to/bartw/getting-started-with-typescript-for-node-5cbe</guid>
      <description>&lt;p&gt;A step by step guide&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@bartwijnants/getting-started-with-typescript-for-node-50679fa596e?source=rss-3dd8c36bc285------2"&gt;Continue reading on Medium »&lt;/a&gt;&lt;/p&gt;

</description>
      <category>eslint</category>
      <category>node</category>
      <category>javascript</category>
      <category>babel</category>
    </item>
    <item>
      <title>retyst: A React Typescript Starter</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Sun, 23 Sep 2018 11:19:56 +0000</pubDate>
      <link>https://dev.to/bartw/retyst-a-react-typescript-starter-a77</link>
      <guid>https://dev.to/bartw/retyst-a-react-typescript-starter-a77</guid>
      <description>

&lt;h2&gt;&lt;a href="https://github.com/bartw/retyst"&gt;check retyst out on GitHub&lt;/a&gt;&lt;/h2&gt;

&lt;h2&gt;scripts&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install
&lt;/span&gt;npm start
npm run build:dev
npm run build:prod
npm run detach
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;about&lt;/h2&gt;

&lt;p&gt;This is a simple starter repo to quickly get a React Typescript project going.&lt;/p&gt;

&lt;p&gt;The dev dependencies include Typescript and Webpack with ts-loader, html-webpack-plugin, webpack-cli and webpack-dev-server.&lt;/p&gt;

&lt;p&gt;The dependencies are react, react-dom and styles-components.&lt;/p&gt;

&lt;p&gt;I will try to keep this repo up to date whenever I use it (and that might be never).&lt;/p&gt;

&lt;h2&gt;usage&lt;/h2&gt;

&lt;p&gt;You can test this repo by executing &lt;code&gt;npm install&lt;/code&gt; followed by &lt;code&gt;npm start&lt;/code&gt; and then browse to &lt;a href="http://localhost:8080/"&gt;http://localhost:8080/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can use the &lt;code&gt;npm run build:dev&lt;/code&gt; and &lt;code&gt;npm run build:prod&lt;/code&gt; to check out the generated bundles.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;npm run detach&lt;/code&gt; script removes all connections to retyst and the .git folder so you can start your own project.&lt;/p&gt;

&lt;h2&gt;license&lt;/h2&gt;

&lt;p&gt;This repo is licensed under the &lt;a href="LICENSE"&gt;MIT License&lt;/a&gt;.&lt;/p&gt;


</description>
      <category>react</category>
      <category>typescript</category>
      <category>webpack</category>
      <category>styledcomponents</category>
    </item>
    <item>
      <title>Continuous deployment to Firebase hosting using Travis CI</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Wed, 15 Aug 2018 10:11:18 +0000</pubDate>
      <link>https://dev.to/bartw/continuous-deployment-to-firebase-hosting-using-travis-ci-3lpm</link>
      <guid>https://dev.to/bartw/continuous-deployment-to-firebase-hosting-using-travis-ci-3lpm</guid>
      <description>

&lt;h4&gt;Intro&lt;/h4&gt;

&lt;p&gt;Last night I had another multi million dollar web app idea. So of course first thing I do in the morning is start to work on my idea. Got to earn those dollars.&lt;/p&gt;

&lt;p&gt;The first thing I need is some place on the internet where my customers can start handing me over their money. I want to move fast, so each time I change something I want to see the results immediately.&lt;/p&gt;

&lt;h4&gt;Enablers&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://firebase.google.com/"&gt;Firebase&lt;/a&gt; is a platform by Google that provides hosting with minimal effort and for free. &lt;a href="https://travis-ci.org/"&gt;Travis&lt;/a&gt; is a hosted continuous integration solution that will allow me to deploy my changes to Firebase. &lt;a href="https://github.com/"&gt;GitHub&lt;/a&gt; is the place where I’ll be storing my precious code.&lt;/p&gt;

&lt;p&gt;To build this stuff I installed &lt;a href="https://nodejs.org/en/"&gt;Node.js&lt;/a&gt; and &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; on my laptop. I didn’t really need Docker but I did not feel like installing &lt;a href="https://www.ruby-lang.org/en/"&gt;Ruby&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Let’s go to work&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Go to &lt;a href="https://console.firebase.google.com"&gt;Firebase&lt;/a&gt; and create a new project.&lt;/li&gt;
&lt;li&gt;Create a new repository on &lt;a href="https://github.com"&gt;GitHub&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Clone the repository locally.&lt;/li&gt;
&lt;li&gt;Create a minimal index.html.&lt;/li&gt;
&lt;/ul&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir public
touch public/index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Connect GitHub repository to Firebase project using the Firebase tools.
Don’t overwrite index.html when initializing.&lt;/li&gt;
&lt;/ul&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g firebase-tools
firebase login
firebase init 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Generate a Firebase CI token (and keep it handy).&lt;/li&gt;
&lt;/ul&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase login:ci
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Go to &lt;a href="https://travis-ci.org/"&gt;Travis&lt;/a&gt; and activate the GitHub repository.&lt;/li&gt;
&lt;li&gt;Encrypt the Firebase CI token using Travis CLI.&lt;/li&gt;
&lt;/ul&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# only run the docker command if you don't have and don't want to install Ruby
docker run -it --rm ruby:latest bash
gem install travis
travis encrypt "1/firebase_CI_token" -r githubusername/reponame
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create a .travis.yml file to deploy to Firebase after every push to GitHub.&lt;/li&gt;
&lt;/ul&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;language: node_js
node_js:
  - "node"
script:
  -
deploy:
  provider: firebase
  token:
    secure: "encrypted_firebase_CI_token"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Commit and push the changes to GitHub.&lt;/li&gt;
&lt;li&gt;Watch Travis build and deploy.&lt;/li&gt;
&lt;li&gt;Check Firebase Hosting to see the deployment history.&lt;/li&gt;
&lt;li&gt;Go to the Firebase Hosting domain for the project to see the website.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p&gt;I just spent half a day on writing a guide on continuously deploying a website to Firebase using Travis CI and I didn’t start working on my multi million dollar idea.&lt;/p&gt;

&lt;p&gt;Find the code on &lt;a href="https://github.com/bartw/travisonfire"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See the website &lt;a href="https://travisonfire-a209c.firebaseapp.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;


</description>
      <category>github</category>
      <category>travisci</category>
      <category>firebase</category>
      <category>ci</category>
    </item>
    <item>
      <title>Incrementally migrate your webpack project to TypeScript</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Fri, 04 Aug 2017 06:48:33 +0000</pubDate>
      <link>https://dev.to/bartw/incrementally-migrate-your-webpack-project-to-typescript</link>
      <guid>https://dev.to/bartw/incrementally-migrate-your-webpack-project-to-typescript</guid>
      <description>&lt;h3&gt;
  
  
  TL;DR
&lt;/h3&gt;

&lt;p&gt;If you want to migrate to &lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt; but don’t want to migrate all your code at the same time you can configure &lt;a href="https://webpack.github.io/"&gt;webpack&lt;/a&gt; to bundle both TypeScript and JavaScript code.&lt;/p&gt;

&lt;p&gt;You can find a demo project &lt;a href="https://github.com/bartw/incrementally_migrate_to_typescript"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to?
&lt;/h3&gt;

&lt;p&gt;To add TypeScript to a webpack project you can follow these steps:&lt;/p&gt;

&lt;p&gt;Install the needed dev-dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @types/jest awesome-typescript-loader typescript @types/lodash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a tsconfig.json file to specify that you want to transpile to ES6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;compilerOptions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;target&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es6&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add awesome-typescript-loader to your webpack config file and load your TypeScript first through the TypeScript transpiler and then through Babel:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;jsx&lt;/span&gt;&lt;span class="se"&gt;?&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;babel-loader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; 
      &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;tsx&lt;/span&gt;&lt;span class="se"&gt;?&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
      &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;babel-loader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;awesome-typescript-loader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To stop Babel from transforming ES6 module syntax to commonjs you need to update the .babelrc file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es2015&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;modules&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plugins&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;transform-class-properties&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now comes the tricky part: keeping the Jest tests running.&lt;br&gt;&lt;br&gt;
Some extra configuration is necessary to tell Jest to transpile TypeScript and to have the normal JavaScript run through Babel-Jest.&lt;/p&gt;

&lt;p&gt;In your package.json add the following Jest config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;moduleFileExtensions&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;jsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;transform&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^.+&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.(ts|tsx)$&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;rootDir&amp;gt;/preprocessor.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;^.+&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.(js|jsx)$&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;babel-jest&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;testRegex&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;(/ __tests__ /.*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.(test|spec))&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;.(ts|tsx|js|jsx)$&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a preprocessor.js file to transpile TypeScript tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tsc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;typescript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.ts&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;endsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.tsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;tsc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;transpile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In .babelrc you need to add a separate configuration for the test environment to play nice with Jest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es2015&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;modules&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}],&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plugins&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;transform-class-properties&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;env&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;test&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;presets&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es2015&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;plugins&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;transform-class-properties&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should be able to start migrating files one by one to TypeScript without breaking tests or builds.&lt;/p&gt;

</description>
      <category>webpack</category>
      <category>typescript</category>
      <category>javascript</category>
      <category>jest</category>
    </item>
    <item>
      <title>Continuous deployment of a webpack app to multiple environments using Travic CI</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Thu, 03 Aug 2017 09:29:52 +0000</pubDate>
      <link>https://dev.to/bartw/continuous-deployment-of-a-webpack-app-to-multiple-environments-using-travic-ci</link>
      <guid>https://dev.to/bartw/continuous-deployment-of-a-webpack-app-to-multiple-environments-using-travic-ci</guid>
      <description>

&lt;h3&gt;
  
  
  TL;DR
&lt;/h3&gt;

&lt;p&gt;I set up continuous deployment of a &lt;a href="https://webpack.github.io/"&gt;webpack&lt;/a&gt; app with tests in &lt;a href="https://facebook.github.io/jest/"&gt;Jest&lt;/a&gt; hosted on &lt;a href="https://firebase.google.com/"&gt;Firebase&lt;/a&gt; using &lt;a href="https://github.com/"&gt;GitHub&lt;/a&gt; and &lt;a href="https://travis-ci.org/"&gt;Travis CI&lt;/a&gt;. Deploys to the DEV environment are done on every commit to master. Deploys to the PROD environment are done on every tag to master.&lt;/p&gt;

&lt;p&gt;Check out the code &lt;a href="https://github.com/bartw/multi_env_webpack_travis_app"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to?
&lt;/h3&gt;

&lt;p&gt;In code I use a default value:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;__CONFIG__&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That value can be overridden in a webpack config file:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DefinePlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; 
    &lt;span class="na"&gt;__CONFIG__&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"override"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In my .firebaserc file I defined multiple Firebase projects:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"projects"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"prod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"prod-multi-webpack-travis"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"dev-multi-webpack-travis"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This allows me to setup ci for each project by executing the following commands:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;firebase use dev
firebase login:ci
travis encrypt "1/xxx"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the .travis.yml file I defined multiple deploys:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deploy:
  - provider: firebase
    project: dev
    token:
      secure: "encrypted stuff"
    skip_cleanup: true
    on:
      branch: "master"
  - provider: firebase
    project: prod
    token:
      secure: "encrypted stuff"
    skip_cleanup: true
    on:
      tags: true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now I can also use the environment variables that Travis defines in my webpack config file:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;webpack&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DefinePlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; 
    &lt;span class="na"&gt;__CONFIG__&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TRAVIS_TAG&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"override on tag"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"override"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If I do a push to GitHub the dev deploy is triggered and if I update the version then the dev and prod deploy are triggered:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm version patch
git push --follow-tags
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To get Jest tests working on files where the environment files are used I added some Jest configuration to my package.json file:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;"jest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"globals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;" __CONFIG__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;It took me way too long to get this working so I decided to write this blog post. This setup makes it very easy to have different configurations for each environment.&lt;/p&gt;

&lt;p&gt;A downside is that the code needs to be bundled again every time you change environment.&lt;/p&gt;





</description>
      <category>ci</category>
      <category>travisci</category>
      <category>javascript</category>
      <category>github</category>
    </item>
    <item>
      <title>Using Prettier and husky to make your commits safe.</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Wed, 14 Jun 2017 20:00:54 +0000</pubDate>
      <link>https://dev.to/bartw/using-prettier-and-husky-to-make-your-commits-safe</link>
      <guid>https://dev.to/bartw/using-prettier-and-husky-to-make-your-commits-safe</guid>
      <description>

&lt;p&gt;Whether you work in a team or by yourself, having consistently formatted code is important for readability and maintainability.&lt;/p&gt;

&lt;h4&gt;
  
  
  Tl;dr
&lt;/h4&gt;

&lt;p&gt;Use Prettier to automatically format your JavaScript and use husky and lint-staged to add a precommit script that runs Prettier and your tests when you commit.&lt;/p&gt;

&lt;p&gt;Check out the full code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/bartw/pretty_husky"&gt;bartw/pretty_husky&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  ESLint vs JavaScript Standard Style vs Prettier
&lt;/h4&gt;

&lt;p&gt;For JavaScript there are solutions like &lt;a href="http://eslint.org/"&gt;ESLint&lt;/a&gt;that can check if your code is consistent. But &lt;a href="http://eslint.org/"&gt;ESLint&lt;/a&gt;requires a lot of configuration and while it can fix some things by itself, it often requires manual intervention when you screw up.&lt;/p&gt;

&lt;p&gt;Then there is &lt;a href="https://standardjs.com/"&gt;JavaScript Standard Style&lt;/a&gt;. This module is the complete opposite of ESLint. It requires no configuration and can also fix some of your code by itself. But having no configuration, it’s very opinionated.&lt;/p&gt;

&lt;p&gt;And now there is also &lt;a href="https://github.com/prettier/prettier"&gt;Prettier&lt;/a&gt;. The difference between Prettier and other lint tools is that Prettier doesn’t check your code. It just takes your code as input and spits out formatted code as output. Like JavaScript Standard Style, Prettier is opinionated but you have some options to customize the format. Because Prettier doesn’t check your code but parses it, everything will be fixed automatically. Sounds like the best of both worlds.&lt;/p&gt;

&lt;h4&gt;
  
  
  Hello Prettier
&lt;/h4&gt;

&lt;p&gt;The best way to see the greatness of Prettier is to try it out.&lt;/p&gt;

&lt;p&gt;Fire up your terminal and start typing:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;mkdir&lt;/span&gt; &lt;span class="nx"&gt;pretty_husky&lt;/span&gt;
&lt;span class="nx"&gt;cd&lt;/span&gt; &lt;span class="nx"&gt;pretty_husky&lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;dev&lt;/span&gt; &lt;span class="nx"&gt;prettier&lt;/span&gt;
&lt;span class="nx"&gt;mkdir&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;
&lt;span class="nx"&gt;touch&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;js&lt;/span&gt;
&lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can write some poorly formatted code in foo.test.js:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'this needs to be prettier.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And add a script package.json to run Prettier:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"pretty"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"prettier--write --tab-width 4 &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;src/**/*.js&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can run Prettier from your terminal:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt; &lt;span class="nx"&gt;pretty&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And you can see that the contents of foo.test.js have changed to:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"this needs to be prettier."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  What about that husky?
&lt;/h4&gt;

&lt;p&gt;Prettier makes your code look pretty but what if you forget to run it before you check in?&lt;/p&gt;

&lt;p&gt;You could run Prettier as a step during continuous integration but then you have to check your code in again if there are changes. It would be much easier if you made sure that no “ugly files can be pushed or committed.&lt;/p&gt;

&lt;p&gt;This is where &lt;a href="https://github.com/typicode/husky"&gt;husky&lt;/a&gt; comes in. &lt;a href="https://github.com/typicode/husky"&gt;Husky&lt;/a&gt; makes creating git hooks easy. Git hooks are scripts that git executes before or after and event. If husky runs Prettier for us then “ugly files can never be committed. But it’s not that easy. Husky can run Prettier but the changed files won’t be added to our commit.&lt;/p&gt;

&lt;p&gt;This problem can be solved by &lt;a href="https://github.com/okonet/lint-staged"&gt;lint-staged&lt;/a&gt;. Lint-staged can run a lint tool, like Prettier, and immediately add them to the staged files.&lt;/p&gt;

&lt;h4&gt;
  
  
  Hook me up!
&lt;/h4&gt;

&lt;p&gt;If you haven’t created a git repository yet now is the time, your hooks won’t work without a repository:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt;
&lt;span class="nx"&gt;touch&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;gitignore&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add “node_modules to the .gitignore file to avoid checking in too much:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;node_modules&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Go back to your terminal and install husky for the hooks, lint-staged for adding the formatted files to the staged files and Jest to run some tests:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;dev&lt;/span&gt; &lt;span class="nx"&gt;husky&lt;/span&gt; &lt;span class="nx"&gt;lint&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;staged&lt;/span&gt; &lt;span class="nx"&gt;jest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Create some scripts to hook everything up in your package.json file:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="s2"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"jest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"pretty"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"prettier --write --tab-width 4 &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;src/**/*.js&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"precommit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"npm run pretty &amp;amp;&amp;amp; npm test"&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="s2"&gt;"lint-staged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"*.js"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s2"&gt;"npm run pretty"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"git add"&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Make some ugly and failing tests in foo.test.js:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'ugly'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'failing'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now try to commit:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="nx"&gt;git&lt;/span&gt; &lt;span class="nx"&gt;commit&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt;&lt;span class="s2"&gt;"will this work?"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The script ran and the test failed, foo.test.js got updated:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ugly"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"failing"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And husky stopped the commit:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; husky - pre-commit hook failed (add --no-verify to bypass)
&amp;gt; husky - to debug, use 'npm run precommit'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you fix the test and try again the commit should work.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Prettier, husky and lint-staged can improve your workflow by formatting your JavaScript files and running some scripts before every commit.&lt;/p&gt;

&lt;p&gt;Check out the full code on &lt;a href="https://github.com/bartw/pretty_husky"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;


</description>
      <category>git</category>
      <category>continuousintegrati</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Running tests for .NET and Node.js on Travis CI</title>
      <dc:creator>Bart Wijnants</dc:creator>
      <pubDate>Sun, 11 Jun 2017 07:05:10 +0000</pubDate>
      <link>https://dev.to/bartw/running-tests-for-net-and-nodejs-on-travis-ci</link>
      <guid>https://dev.to/bartw/running-tests-for-net-and-nodejs-on-travis-ci</guid>
      <description>

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Together with a colleague I started working on &lt;a href="http://partei.be"&gt;Partei&lt;/a&gt;. Like a lot of projects this consists of a web api that does some stuff and a front-end.&lt;/p&gt;

&lt;p&gt;To make things easy we decided to serve our front-end from the same server that serves our api and to keep them in the same git repository. We opted for ASP.NET Core in the back-end and React in the front.&lt;/p&gt;

&lt;p&gt;We set up the projects and configured Travis CI to run our tests and publish to Heroku.&lt;/p&gt;

&lt;p&gt;Initially we only had .NET tests and Travis ran them without a problem. But then we introduced Jest tests for the front-end. Travis CI has Node.js installed by default on the .NET environment so thing should go smooth.&lt;/p&gt;

&lt;p&gt;But things didn’t go smooth. Apparently the default version of Node.js is 4 and our project is written using Node.js 8.&lt;/p&gt;

&lt;p&gt;Time to figure out a solution for this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;I created a &lt;a href="https://github.com/bartw/dotnetcore_node_travis"&gt;repo&lt;/a&gt; with a .NET Core test project and an npm project both with a simple test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/bartw/dotnetcore_node_travis"&gt;bartw/dotnetcore_node_travis&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On Travis CI, Node Version Manager (&lt;a href="https://github.com/creationix/nvm"&gt;nvm&lt;/a&gt;) is available. In my .travis.yml file I used nvm to install Node.js 8 and use this version to run our tests.&lt;/p&gt;

&lt;p&gt;Now both the .NET tests and the Node.js tests are running together.&lt;/p&gt;


</description>
      <category>travisci</category>
      <category>javascript</category>
      <category>node</category>
      <category>dotnetcore</category>
    </item>
  </channel>
</rss>
