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:
This will run tests twice - once during test, again during coverage.