Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Change-Id: I5facc788a1e9b84f2044a0ba40eaaa5aa90bb3b2
  • Loading branch information
Colin McLeod committed Nov 27, 2013
1 parent 1bcb9a1 commit cc4b9d6
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 84 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,30 @@ https://github.com/visionmedia/mocha/wiki/Third-party-reporters describes using
Basically, have your project's package.json be like:

``` js
{
"devDependencies": {
"mocha-teamcity-reporter": ">=0.0.1"
}
{
"devDependencies": {
"mocha-teamcity-cov-reporter": ">=0.0.1"
}
}
```

Then call mocha with:

`mocha --reporter mocha-teamcity-reporter test`
`mocha --reporter mocha-teamcity-cov-reporter test`

This also works well with [grunt-mocha-test](https://github.com/pghalliday/grunt-mocha-test)

``` js
mochaTest: {
test: {
// Your test settings
},
coverage: {
options: {
reporter: 'mocha-teamcity-cov-reporter',
quiet: false
},
src: ['src/files.js'] // Your source code files
}
}
```
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/teamcity')
module.exports = require('./lib/teamcity-cov');
50 changes: 50 additions & 0 deletions lib/teamcity-cov.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Module dependencies.
*/

var JSONCov = require('mocha/lib/reporters/json-cov');

/**
* Expose `Teamcity`.
*/

exports = module.exports = TeamcityCov;

/**
* Initialize a new `Teamcity` reporter.
*
* @param {Runner} runner
* @api public
*/

function TeamcityCov(runner) {
JSONCov.call(this, runner, false);

runner.on('end', function(){
var data = this.cov;
var threshold = this.threshold || 0;
if (!data) {
console.log("##teamcity[message text='CODE-COVERAGE CHECK FAILED' errorDetails='Error reading report file.' status='ERROR']");
return;
}

var cov = Math.ceil(data.coverage);

console.log("##teamcity[message text='Code Coverage is " + cov + "%']");
console.log("##teamcity[blockOpened name='Code Coverage Summary']");
console.log("##teamcity[buildStatisticValue key='CodeCoverageB' value='" + cov + "']");
console.log("##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='" + data.hits + "']");
console.log("##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='" + data.sloc + "']");
console.log("##teamcity[buildStatisticValue key='CodeCoverageL' value='" + cov + "']");
console.log("##teamcity[buildStatisticValue key='PassedTestCount' value='" + data.passes.length + "']");
console.log("##teamcity[buildStatisticValue key='FailedTestCount' value='" + data.failures.length + "']");
console.log("##teamcity[blockClosed name='Code Coverage Summary']");

if (cov >= threshold) {
console.log("##teamcity[message text='CODE-COVERAGE CHECK PASSED' status='NORMAL']");
} else {
console.log("##teamcity[message text='CODE-COVERAGE CHECK FAILED' errorDetails='Insufficient code coverage.' status='ERROR']");
}

}.bind(this));
}
71 changes: 0 additions & 71 deletions lib/teamcity.js

This file was deleted.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "mocha-teamcity-reporter",
"version": "0.0.2",
"description": "teamcity reporter for mocha",
"name": "mocha-teamcity-cov-reporter",
"version": "0.0.1",
"description": "teamcity code coverage reporter for mocha",
"main": "index.js",
"directories": "./lib",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/travisjeffery/mocha-teamcity-reporter.git"
"url": "https://github.com/cmcleod/mocha-teamcity-cov-reporter.git"
},
"keywords": [
"mocha",
"teamcity",
"reporter",
"jetbrains"
"coverage"
],
"dependencies": {
"mocha": ">=1.13.0"
},
"author": "travis jeffery",
"author": "Colin McLeod",
"license": "MIT",
"bugs": {
"url": "https://github.com/travisjeffery/mocha-teamcity-reporter/issues"
"url": "https://github.com/cmcleod/mocha-teamcity-cov-reporter/issues"
}
}

0 comments on commit cc4b9d6

Please sign in to comment.