Skip to content

Instantly share code, notes, and snippets.

@kukiron
Forked from tpai/travis-coveralls.md
Created October 15, 2017 14:12
Show Gist options
  • Save kukiron/6690b33d8f34c997db7c3897a2098540 to your computer and use it in GitHub Desktop.
Save kukiron/6690b33d8f34c997db7c3897a2098540 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:

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