<?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>Forem: Giovanna Aveiro</title>
    <description>The latest articles on Forem by Giovanna Aveiro (@glrta).</description>
    <link>https://forem.com/glrta</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%2F418180%2Faa0a6d03-bf6b-428f-989a-4087deab673d.jpeg</url>
      <title>Forem: Giovanna Aveiro</title>
      <link>https://forem.com/glrta</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/glrta"/>
    <language>en</language>
    <item>
      <title>Setting up your test environment with Tape and Codecov in Node.js</title>
      <dc:creator>Giovanna Aveiro</dc:creator>
      <pubDate>Mon, 13 Jul 2020 10:29:12 +0000</pubDate>
      <link>https://forem.com/glrta/setting-up-your-test-environment-with-tape-and-codecov-in-node-js-2paj</link>
      <guid>https://forem.com/glrta/setting-up-your-test-environment-with-tape-and-codecov-in-node-js-2paj</guid>
      <description>&lt;p&gt;I wasn't much into testing until I put myself forward as QA lead in our student project during my coding bootcamp at Founders and Coders. Code coverage was one of the main takeaways I got from that experience. &lt;/p&gt;

&lt;p&gt;Some things I learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code coverage will show you what parts of your code are not being tested when your tests run and it can be surprising when you were sure that test X would hit that line of code you wanted it to but it didn't.&lt;/li&gt;
&lt;li&gt;It will encourage and challenge you to learn more about testing and explore things you don't know.&lt;/li&gt;
&lt;li&gt;If you are not using TDD methodology (most part of the time we weren't, it is a long learning process!) it will push you to write code that can be tested which means better code.&lt;/li&gt;
&lt;li&gt;Working towards a high coverage is a great morale boost.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is important to bear in mind that a test coverage...&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;...won't tell if you are testing for edge cases or critiquing well your own code.&lt;/li&gt;
&lt;li&gt;...it also won't tell you if your tests are meaningful.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This tutorial is then for you who is using Tape as your test runner and wishes to get started with code coverage. In a nutshell, &lt;a href="http://codecov.io"&gt;Codecov.io&lt;/a&gt; is a great tool that integrates code coverage reports. It is supported by &lt;a href="https://docs.codecov.io/docs/supported-languages"&gt;lots of languages&lt;/a&gt;, Node.js included. The set up however also varies according to what test runner you are using. For that student project, Bechdel and Beyond, we decided to use Tape in the &lt;a href="https://github.com/fac19/Bechdel-Beyond-backend"&gt;backend&lt;/a&gt;. Below I am sharing the steps we took to set up our backend repo with Codecov.io.&lt;/p&gt;

&lt;h1&gt;
  
  
  Codecov setup with Tape in Node.js
&lt;/h1&gt;

&lt;p&gt;When using &lt;strong&gt;Tape&lt;/strong&gt; as your test runner you will need some extra tools to implement test coverage as &lt;a href="http://codecov.io"&gt;Codecov&lt;/a&gt; doesn't do all the job in this case, it only integrates reports. Codecov '&lt;a href="https://docs.codecov.io/docs/quick-start"&gt;quick start&lt;/a&gt;' guide recommends Istanbul to generate coverage reports locally that then are sent to Codecov when your branch is pushed to the remote repo. &lt;/p&gt;

&lt;h2&gt;
  
  
  Generating reports
&lt;/h2&gt;

&lt;p&gt;To track the lines of your code being used when your tests run, Codecov recommends installing Istanbul in your development dependencies. I tried following the instructions for Istanbul, but the package is now deprecated and the alternative is Istanbul's command line interface called &lt;code&gt;nyc&lt;/code&gt; . To install it, run:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i nyc -D&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In our project we already had a &lt;code&gt;test&lt;/code&gt; script to run our tests using Tape (and tap-spec to make it pretty):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"PGDATABASE=bbtest tape tests/*.test.js | tap-spec"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is possible to add another script to run it with nyc:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"coverage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nyc npm run test"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively , you just add nyc to your &lt;code&gt;test&lt;/code&gt; script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"PGDATABASE=bbtest nyc tape tests/*.test.js | tap-spec"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running &lt;code&gt;npm run test&lt;/code&gt;  (or &lt;code&gt;npm run coverage&lt;/code&gt;) will then show a report like the one below alongside your tests and will generate a &lt;code&gt;.nyc_output&lt;/code&gt; folders to cache information, all entirely locally.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5js0xWV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/px1g652zyike6ekwaj63.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5js0xWV2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/px1g652zyike6ekwaj63.png" alt="Istanbul report"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(This Stackoverflow &lt;a href="https://stackoverflow.com/questions/26618243/how-do-i-read-an-istanbul-coverage-report"&gt;post&lt;/a&gt; explains how to interpret the report.) &lt;/p&gt;

&lt;p&gt;By default, nyc will look only to the files that are being tested (which can give the illusion of high coverage). Ideally, you want to change this so it covers your entire project and gives you a real picture of what is not being tested. See &lt;a href="https://github.com/istanbuljs/nyc#configuring-nyc"&gt;here&lt;/a&gt; how to configure your nyc report.&lt;/p&gt;

&lt;p&gt;Still according to Codecov instructions, add the script below to your package.json file. It specifies a reporter and saves all in &lt;code&gt;coverage.lcov&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"report-test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nyc report --reporter=text-lcov &amp;gt; coverage.lcov &amp;amp;&amp;amp; codecov"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Uploading reports
&lt;/h2&gt;

&lt;p&gt;Finally, the  &lt;code&gt;&amp;amp;&amp;amp; codecov&lt;/code&gt; part is responsible for uploading the report to &lt;a href="http://codecov.io"&gt;Codecov.io&lt;/a&gt;. For this to work, just install &lt;code&gt;npm i codecov&lt;/code&gt; in development dependencies. Note that when you start at &lt;a href="http://codecov.io"&gt;codecov.io&lt;/a&gt; it suggests you to use a bash command (&lt;code&gt;- bash &amp;lt;(curl -s [https://codecov.io/bash](https://codecov.io/bash))&lt;/code&gt;). If you decide for codecov npm package (is it safer?), you won't need that.&lt;/p&gt;

&lt;p&gt;To test if you can send a report to Codecov, register to &lt;a href="http://codecov.io"&gt;codecov.io&lt;/a&gt; with the account where your repo lives and add the token provided at the end of the script above &lt;code&gt;-t &amp;lt;token&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Run both scripts (assuming you have tests in your project), &lt;code&gt;npm run test&lt;/code&gt; then &lt;code&gt;npm run report-test&lt;/code&gt;. You should see the below in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6GlQAjhl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e7dlxpboo7vuljr0sdpl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6GlQAjhl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/e7dlxpboo7vuljr0sdpl.png" alt="Codecov report"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Important! The report will be uploaded to codecov.io only after pushing your branch to the remote. &lt;/p&gt;

&lt;p&gt;Don't forget to include .lcov and .nyc_output in the &lt;code&gt;.gitignore&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;coverage
*.lcov

# nyc test coverage
.nyc_output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Not using CI
&lt;/h3&gt;

&lt;p&gt;If you are not using any CI yet, remove the token and &lt;code&gt;-t&lt;/code&gt; from your package.json and save the token in a &lt;code&gt;.env&lt;/code&gt; file. Push your branch to the remote and the report will be uploaded to your Codecov dashboard. It might take it some seconds to upload.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using CI (Travis)
&lt;/h3&gt;

&lt;p&gt;If using Travis in your project, remove the token and &lt;code&gt;-t&lt;/code&gt; from your package.json and save the token provided in your project dashboard on Travis. Add both scripts to your &lt;code&gt;.travis.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;script:
  - npm run test
  - npm run report-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is it 😃&lt;/p&gt;

&lt;h1&gt;
  
  
  Extras
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://codecov.io/gh/fac19/Bechdel-Beyond-backend"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T2O-cnES--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codecov.io/gh/fac19/Bechdel-Beyond-backend/branch/master/graph/badge.svg" alt="codecov"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that you have done all of this, go to your project dashboard in &lt;a href="http://code.io"&gt;codecov.io&lt;/a&gt; &amp;gt; settings &amp;gt; badge and add a coverage badge to share your amazing code coverage in your readme! &lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;p&gt;Good article by Vitali Zaidman about JavaScript testing frameworks (maintained): &lt;a href="https://medium.com/welldone-software/an-overview-of-javascript-testing-7ce7298b9870"&gt;An Overview of JavaScript Testing in 2020&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This article by Erick Zhao can also be useful - &lt;br&gt;
&lt;a href="https://medium.com/@erickzhao/adding-test-coverage-to-your-nodejs-app-with-codecov-istanbul-and-travisci-aa092c1e360c"&gt;Adding Test Coverage to your NodeJS app with Istanbul, TravisCI, and Codecov&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more details on what is required for different test runners in NodeJS &lt;a href="https://github.com/codecov/example-node"&gt;here&lt;/a&gt;. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>testing</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Deploy PostgreSQL in Node.js to Heroku for beginners</title>
      <dc:creator>Giovanna Aveiro</dc:creator>
      <pubDate>Mon, 29 Jun 2020 21:12:56 +0000</pubDate>
      <link>https://forem.com/glrta/deploy-postgresql-in-node-js-to-heroku-for-beginners-1ck0</link>
      <guid>https://forem.com/glrta/deploy-postgresql-in-node-js-to-heroku-for-beginners-1ck0</guid>
      <description>&lt;p&gt;During my time at &lt;a href="https://www.foundersandcoders.com/"&gt;Founders and Coders&lt;/a&gt;, we had to use Heroku to deploy our Node + PostgreSQL projects quite a few times. Because it can be daunting at first, I put together this step-by-step based on their graphic user interface. It is quick and straight to the point. Questions and contributions are welcome!&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploy your project
&lt;/h2&gt;

&lt;p&gt;Signup/Login to &lt;a href="http://www.heroku.com"&gt;www.heroku.com&lt;/a&gt;. Go to &lt;code&gt;New&lt;/code&gt; &amp;gt; &lt;code&gt;Create new app&lt;/code&gt; to start. Add name, region and hit &lt;code&gt;Create app&lt;/code&gt;. Choose GitHub as a deployment method under the 'Deploy' tab, search for your repo to connect: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xGLyvYMC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3atr0di1hpcb4eawo6eb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xGLyvYMC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3atr0di1hpcb4eawo6eb.png" alt="screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;on the same tab, click &lt;code&gt;enable automatic deploys&lt;/code&gt; with the master branch for your future deploys.  For the first install, hit &lt;code&gt;Deploy Branch&lt;/code&gt; in 'Manual deploy' section to deploy your app:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--awQAdnly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pt0b8g3f9br0z0g750mc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--awQAdnly--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pt0b8g3f9br0z0g750mc.png" alt="screenshot"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Important to notice that after deployment, Heroku will run the 'start' script in your package.json to start your application. Make sure it is correct.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"script": {
    "start": "server.js"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deploy your PostgreSQL database to Heroku
&lt;/h2&gt;

&lt;p&gt;Once your app is up you should see the message below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L1XoxWMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/djn76hgexida071d4jv6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L1XoxWMZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/djn76hgexida071d4jv6.png" alt="screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to 'Resources' tab and search for &lt;code&gt;Heroku Postgres&lt;/code&gt; add-on, then select the &lt;code&gt;Hobby Dev - Free&lt;/code&gt; version and hit &lt;code&gt;Provision&lt;/code&gt; to confirm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_pXxafPN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g8x14ebwklr37fkxkksh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_pXxafPN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g8x14ebwklr37fkxkksh.png" alt="screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Back to 'Resources' tab, you can see your current database clicking on &lt;code&gt;Heroku Postgres&lt;/code&gt;. You should see in a new tab something similar to the below image, indicating your database is empty:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QLdlOu45--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0vwpb8d5rzupmvaeyizl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QLdlOu45--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0vwpb8d5rzupmvaeyizl.png" alt="screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Connect to the database
&lt;/h3&gt;

&lt;p&gt;Heroku will generate a DATABASE_URL that you can use to connect to your production database. You can find this under 'Settings' back to the project tab in &lt;code&gt;Reveal Config Vars&lt;/code&gt; with key 'DATABASE_URL'. &lt;/p&gt;

&lt;p&gt;Important: If your project/database depend on API keys or tokens, add them in your &lt;code&gt;config vars&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Connect to it via psql/pgcli copying and pasting the url in your terminal and then running you init.sql file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;psql&lt;/span&gt;

&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="k"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;DATABASE_URL&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;database&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;sql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Some extra tips
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can view more information about the database by accessing it from 'Resources' and navigating to 'Settings' &amp;gt; &lt;code&gt;View Credentials&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;You can add collaborators via &lt;code&gt;Access&lt;/code&gt;tab;&lt;/li&gt;
&lt;li&gt;View logs in &lt;code&gt;More&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;You can delete projects from Heroku in 'Setting' at the bottom of the page.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>postgres</category>
      <category>database</category>
      <category>heroku</category>
    </item>
  </channel>
</rss>
