Skip to content

Instantly share code, notes, and snippets.

@Faultless
Last active November 10, 2017 13:53
Show Gist options
  • Save Faultless/cbb014364dc1a5440ab6473a9a3608ab to your computer and use it in GitHub Desktop.
Save Faultless/cbb014364dc1a5440ab6473a9a3608ab to your computer and use it in GitHub Desktop.
An opinionated guide for Postlight trainees on how to use CircleCI and Codecov instead of TravisCI and coveralls.

Postlight uses CircleCI for it's Continuous Integration needs, and Codecov for it's test coverage.

Below we show how to configure our testing pipeline using Postlight's tooling instead of the JS Stack tutorial tools.

Configuring CircleCI for Continuous integration

  1. Make sure to Sign in using your Postlight-connected Github account and select All Repos since your fork of the learn repo is Private.

  2. Follow the instructions under Dashboard -> Projects to setup your fork of the learn repository on CircleCI.

  3. Add a config File to your repo. Below is a detailed explanation for this step.

The only file that will be changed here (compared to the js stack tutorial) is the .yml config file specific to the CI provider we're using.

  • Travis uses .travis.yml for its configuration.
  • CircleCI uses .circleci/config.yml which is very similar.

Assuming you are creating a brand new repository for the last part of the "JS stack from scratch" training, your config.yml file should look like the following:

  version: 2
  jobs:
    build:
      docker:
        - image: circleci/node:latest

      steps:
        - checkout

        # Download and cache dependencies
        - restore_cache:
            keys:
            - v1-dependencies-{{ checksum "package.json" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

        - run: npm install

        - save_cache:
            paths:
              - node_modules
            key: v1-dependencies-{{ checksum "package.json" }}
          
        # run tests
        - run: npm test && npm run prod:build
  1. Once everything is set up, all we need to do is to push a commit to our fork of learn in order to trigger the building/testing of our app.

Hooking up our repo with Codecov

  1. Similarly to CircleCI, Codecov will seemlessly set you up using your Postlight Github Account.

  2. Once this is done, run npm install -D codecov or it's equivalent yarn add --dev codecov to make sure the codecov command is available for us to use in our testing script. Why? because codecov will analyze our Jest's coverage directory to generate it's coverage reports.

  3. Update the test script in your package.json to be:

  "scripts": {
    ...
    "test": "npm run lint && flow && jest --coverage && codecov --token=YOU_CODECOV_TOKEN",
    ...
  }

That's it! Next time you run your tests they will be available on your codecov dashboard.

@JadTermsani
Copy link

To add to George's comment :

"test": "yarn lint && flow && jest --coverage && codecov --token=YOUR_CODECOV_TOKEN",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment