Skip to content

Instantly share code, notes, and snippets.

@tpai
Last active February 20, 2019 07:20
Show Gist options
  • Save tpai/d07be74944e80d1b25808b7550c7e185 to your computer and use it in GitHub Desktop.
Save tpai/d07be74944e80d1b25808b7550c7e185 to your computer and use it in GitHub Desktop.
Build Project with Travis-CI and Coveralls

Directory Structure

.
|-- dist/
|-- src/
|-- test/
|  `-- setup.jsx    # jsdom for renderIntoDocument()
|-- .babelrc
|-- .coveralls.yml
|-- .istanbul.yml
|-- package.json

Settings

.babelrc

{
  "presets": ["react", "es2015", "stage-0"],
  "env": {
    "test": {
      "plugins": [
        "babel-plugin-rewire"
      ]
    }
  }
}

.coveralls.yml

repo_token: [your-token]

.istanbul.yml

instrumentation:
  root: src
  extensions:
    - .jsx
    - .js

.travis.yml

sudo: false
language: node_js
node_js:
- "4"
before_install:
- "npm install -g npm@'>=3.5.1'"
after_script:
- "npm run test:cov"
- "npm install coveralls && cat ./coverage/lcov.info | coveralls"

Old version of npm can't handle caret for dependency versions, be sure to upgrade it so that it can work properly. Then run test with coverage calculation, send it to coveralls after all done.

Ref:

package.json

{
  "scripts": {
    "test": "NODE_ENV=test NODE_PATH=./src mocha --compilers js:babel-core/register 'test/**/*.test.jsx' --recursive --require 'test/setup.jsx'",
    "test:cov": "NODE_ENV=test NODE_PATH=./src babel-node -- ./node_modules/.bin/isparta cover -x 'dist/*.js' --include '**/*.js' --include '**/*.jsx' _mocha -- 'test/**/*.test.jsx' --recursive --require 'test/setup.jsx'"
  }
}

Mocha Options

--compilers # compile with
--recursive # include sub directories
--require   # include libraries

Istanbul Options

--exclude   # coverage calculation exclude files
--include   # coverage calculation include files

Ref:

@mrchief
Copy link

mrchief commented Apr 29, 2018

This will run tests twice - once during test, again during coverage.

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