Skip to content

Commit

Permalink
Add coverage testing
Browse files Browse the repository at this point in the history
  • Loading branch information
G. Grau committed Feb 26, 2016
1 parent 868f825 commit c66a50b
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pids

# Dependency directory
node_modules

# Others
/coverage
/.extractedApi.md
*.sublime-project
*.sublime-workspace
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/tools
/test
/coverage
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
language: node_js
node_js:
- "stable"
after_success:
- 'cat ./coverage/lcov.info | ./node_modules/.bin/coveralls'
1 change: 0 additions & 1 deletion dist/timm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/timm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@
"devDependencies": {
"chai": "^3.5.0",
"chalk": "^1.1.1",
"coffee-coverage": "^1.0.1",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.6",
"cross-env": "^1.0.7",
"debug": "^2.2.0",
"envify": "^3.4.0",
"immutable": "^3.7.6",
"istanbul": "^0.4.2",
"lodash": "^4.5.0",
"mocha": "^2.4.5",
"seamless-immutable": "^5.0.1",
"uglifyjs": "^2.4.10"
},
"scripts": {
"test": "mocha",
"t": "mocha",
"test": "npm run testCoverage",
"testCoverageDev": "cross-env TEST_COV=1 NODE_ENV=development mocha",
"testCoverageProd": "cross-env TEST_COV=1 NODE_ENV=production mocha",
"testCoverageMerge": "coffee tools/coffeeCoverageMerge.coffee",
"testCoverage": "npm run testCoverageDev && npm run testCoverageProd && npm run testCoverageMerge",
"testMinified": "cross-env TEST_MINIFIED_LIB=1 mocha",
"compile": "rm -rf dist && coffee -o dist -c src",
"docs": "coffee tools/extractDocs.coffee",
"uglify": "cross-env NODE_ENV=production envify dist/timm.js | uglifyjs - -o dist/timm.min.js --mangle --compress --comments \"/\\|/\"",
"build": "npm test && npm run compile && npm run uglify && npm run testMinified && npm run docs",
"build": "npm run testCoverage && npm run compile && npm run uglify && npm run testMinified && npm run docs",
"benchmarks": "coffee tools/benchmarks.coffee"
},
"repository": {
Expand Down
1 change: 0 additions & 1 deletion src/timm.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ MERGE_ERROR = 'MERGE_ERROR'
_merge = (fAddDefaults) ->
args = arguments
len = args.length
not(len > 1) and _throw if process.env.NODE_ENV isnt 'production' then "At least one object should be provided to merge()" else MERGE_ERROR
out = args[1]
not(out?) and _throw if process.env.NODE_ENV isnt 'production' then "At least one object should be provided to merge()" else MERGE_ERROR
fChanged = false
Expand Down
4 changes: 2 additions & 2 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--compilers coffee:coffee-script
--require coffee-script/register
--compilers coffee:coffee-script/register
--require ./tools/coffeeCoverageLoader.js
--recursive
-R spec
--colors
Expand Down
10 changes: 10 additions & 0 deletions test/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ describe 'Object operations', ->
obj2 = timm.merge obj, {b: 2, d: obj.d}
expect(obj2).to.equal obj

it 'with more than 6 args', ->
obj2 = timm.merge {a: 1}, {b: 2}, {c: 3}, {d: 4}, {e: 5}, {f: 6}, {g: 7}
expect(obj2).to.deep.equal {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7}

it 'should throw with no args', -> expect(timm.merge).to.throw(Error)

describe 'merge multiple', ->
it 'with changes', ->
obj2 = timm.merge obj, {b: 4}, {c: 3}, {b: 7}
Expand Down Expand Up @@ -218,6 +224,10 @@ describe 'Object operations', ->
obj2 = timm.addDefaults obj, {b: 2, d: obj.d}
expect(obj2).to.equal obj

it 'with more than 6 args', ->
obj2 = timm.addDefaults {a: 1}, {b: 2}, {c: 3}, {d: 4}, {e: 5}, {f: 6}, {g: 7}
expect(obj2).to.deep.equal {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7}

describe 'addDefaults multiple', ->
it 'with changes', ->
obj2 = timm.addDefaults obj, {b: 4}, {c: 3}, {b: 7}, {c: 6}
Expand Down
23 changes: 23 additions & 0 deletions tools/coffeeCoverageLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
if (!process.env.TEST_COV) {
return;
}
console.log("Configuring coffee-coverage...");

var path = require('path');
var coffeeCoverage = require('coffee-coverage');
var projectRoot = path.resolve(__dirname, "..");
var coverageVar = coffeeCoverage.findIstanbulVariable();
// Only write a coverage report if we're not running inside of Istanbul.
var covFileName = process.env.NODE_ENV === 'production'
? "coverage-coffee-prod.json"
: "coverage-coffee-dev.json"
var writeOnExit = (coverageVar == null) ? (projectRoot + '/coverage/' + covFileName) : null;

coffeeCoverage.register({
instrumentor: 'istanbul',
basePath: projectRoot,
exclude: ['/test', '/node_modules', '/.git', '/tools'],
coverageVar: coverageVar,
writeOnExit: writeOnExit,
initAll: true
});
16 changes: 16 additions & 0 deletions tools/coffeeCoverageMerge.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
istanbul = require 'istanbul'
collector = new istanbul.Collector()
reporter = new istanbul.Reporter()
SYNC = false

_addToCollector = (filePath) ->
collector.add JSON.parse fs.readFileSync(filePath, 'utf8')

collector.add require '../coverage/coverage-coffee-dev.json'
collector.add require '../coverage/coverage-coffee-prod.json'

reporter.add 'text'
reporter.add 'lcov'

reporter.write collector, SYNC, ->
console.log "All reports generated"

0 comments on commit c66a50b

Please sign in to comment.