Skip to content

Commit

Permalink
add code coverage (#9)
Browse files Browse the repository at this point in the history
use codecov for code coverage with the tests
  • Loading branch information
brendanashworth authored Sep 24, 2016
1 parent aa5e13e commit a798e84
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
npm-debug.log
.idea
coverage/
coverage.lcov
src-cov
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
language: node_js

node_js:
- 'node'
- '6.0'
- '4.0'
- 'iojs'
- '0.12'
- '0.11'
- '0.10'

after_success:
- 'npm run coverage'

notifications:
email: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Generate Password
=====
[![Build Status](https://travis-ci.org/brendanashworth/generate-password.svg?branch=master)](https://travis-ci.org/brendanashworth/generate-password)
[![Build Status](https://travis-ci.org/brendanashworth/generate-password.svg?branch=master)](https://travis-ci.org/brendanashworth/generate-password) [![codecov](https://codecov.io/gh/brendanashworth/generate-password/branch/master/graph/badge.svg)](https://codecov.io/gh/brendanashworth/generate-password)

[![Generate-Password NPM](https://nodei.co/npm/generate-password.png)](http://npmjs.org/package/generate-password)

Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Easy library for generating unique passwords.",
"main": "main.js",
"scripts": {
"test": "mocha"
"test": "mocha",
"coverage": "sh ./test/coverage.sh"
},
"repository": {
"type": "git",
Expand All @@ -25,7 +26,10 @@
"dependencies": {},
"devDependencies": {
"chai": "^1.10.0",
"codecov": "^1.0.1",
"jscover": "^1.0.0",
"mocha": "^2.0.1",
"mocha-lcov-reporter": "^1.2.0",
"underscore": "^1.7.0"
}
}
17 changes: 17 additions & 0 deletions test/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -x

ROOT=$PWD

# Make a copy of src into src-cov, with the coverage code.
$ROOT/node_modules/.bin/jscover $ROOT/src $ROOT/src-cov

# Run the tests.
JSCOV=1 $ROOT/node_modules/.bin/mocha -R mocha-lcov-reporter > $ROOT/coverage.lcov

# Update the server with the results.
$ROOT/node_modules/.bin/codecov

# Clean up.
rm -f $ROOT/coverage.lcov
rm -rf $ROOT/src-cov
3 changes: 2 additions & 1 deletion test/generator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var assert = require('chai').assert,
_ = require('underscore');

var generator = require('../main');
// We use a different require path for code coverage.
var generator = process.env.JSCOV ? require('../src-cov/generate') : require('../main');

describe('generate-password', function() {
describe('generate()', function() {
Expand Down

0 comments on commit a798e84

Please sign in to comment.