diff options
| author | elliottcable <[email protected]> | 2013-05-24 02:42:15 -0400 |
|---|---|---|
| committer | elliottcable <[email protected]> | 2013-05-24 02:42:15 -0400 |
| commit | 92783b483630b516b83cab3b555cce2fb5b79982 (patch) | |
| tree | 2b7c224fd47b0e778992714c5a0432b3ea16d373 | |
| parent | ed578c2d1944c7122a5b1bbde0622513dcf87cc2 (diff) | |
| download | node-coveralls-92783b483630b516b83cab3b555cce2fb5b79982.tar.xz node-coveralls-92783b483630b516b83cab3b555cce2fb5b79982.zip | |
Supporting command-line usage outside of Travis-CI
| -rw-r--r-- | README.md | 7 | ||||
| -rwxr-xr-x[-rw-r--r--] | bin/coveralls.js | 22 | ||||
| -rw-r--r-- | lib/convertLcovToCoveralls.js | 10 | ||||
| -rw-r--r-- | package.json | 1 | ||||
| -rw-r--r-- | test/convertLcovToCoveralls.js | 4 |
5 files changed, 28 insertions, 16 deletions
@@ -5,17 +5,18 @@ Installation: Add the latest version of `coveralls` to your package.json. -This script ( `bin/coveralls.js` ) can take standard input from any tool that emits the lcov data format (including [mocha](http://visionmedia.github.com/mocha/)'s [LCov reporter](https://npmjs.org/package/mocha-lcov-reporter)) and send it to coveralls.io to report your code coverage there. It needs to run from [travis-ci](http://about.travis-ci.org/docs/user/languages/javascript-with-nodejs/) to work. +This script ( `bin/coveralls.js` ) can take standard input from any tool that emits the lcov data format (including [mocha](http://visionmedia.github.com/mocha/)'s [LCov reporter](https://npmjs.org/package/mocha-lcov-reporter)) and send it to coveralls.io to report your code coverage there. Instrumenting your app for coverage is probably harder than it needs to be (read [here](http://www.seejohncode.com/2012/03/13/setting-up-mocha-jscoverage/) or [here](http://tjholowaychuk.com/post/18175682663/mocha-test-coverage)), but that's also a necessary step. -Once your app is instrumented for coverage, and building in travis-ci, you just need to pipe the lcov output to `./node_modules/coveralls/bin/coveralls.js`. +Once your app is instrumented for coverage, and building, you just need to pipe the lcov output to `./node_modules/coveralls/bin/coveralls.js`. In mocha, if you've got your code instrumented for coverage, the command for a travis build would look something like this: ```console YOURPACKAGE_COVERAGE=1 ./node_modules/.bin/mocha test -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js ``` -Note: this will only run on travis-ci, where a necessary TRAVIS_JOB_ID environment variable will exist. + +If you're running locally, you must have a `.coveralls.yml` file, as documented in their documentation, with your `repo_token` in it. Check out an example [Makefile](https://github.com/cainus/urlgrey/blob/master/Makefile) from one of my projects for an example, especially the test-coveralls build target. Note: Travis runs `npm test`, so whatever target you create in your Makefile must be the target that `npm test` runs (This is set in package.json's 'scripts' property). diff --git a/bin/coveralls.js b/bin/coveralls.js index 288b451..d3d18e1 100644..100755 --- a/bin/coveralls.js +++ b/bin/coveralls.js @@ -1,4 +1,7 @@ #!/usr/bin/env node +var fs = require('fs'); +var path = require('path'); +var YAML = require('libyaml'); var sendToCoveralls = require('../lib/sendToCoveralls'); var convertLcovToCoveralls = require('../lib/convertLcovToCoveralls'); @@ -8,18 +11,23 @@ process.stdin.setEncoding('utf8'); var input = ''; process.stdin.on('data', function(chunk) { - input += chunk; + input += chunk; }); process.stdin.on('end', function() { - inputToCoveralls(input); + inputToCoveralls(input); }); var inputToCoveralls = function(input){ - console.log(input); - var libDir = process.argv[2] || ''; - - convertLcovToCoveralls(input, libDir, function(err, postData){ + console.log(input); + var libDir = process.argv[2] || ''; + + var yml = path.join(process.cwd(), '.coveralls.yml'); + if (fs.statSync(yml).isFile()) { + repo_token = YAML.readFileSync(yml)[0]['repo_token']; + } + + convertLcovToCoveralls(input, libDir, repo_token, function(err, postData){ if (err){ throw err; } @@ -36,5 +44,3 @@ var inputToCoveralls = function(input){ }); }; - - diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js index f407893..2b5e223 100644 --- a/lib/convertLcovToCoveralls.js +++ b/lib/convertLcovToCoveralls.js @@ -25,7 +25,7 @@ var convertLcovFileObject = function(file, filepath){ coverage : coverage }; }; -var convertLcovToCoveralls = function(input, filepath, cb){ +var convertLcovToCoveralls = function(input, filepath, repo_token, cb){ console.log("in: ", filepath); if (filepath[0] !== '/'){ filepath = path.join(process.cwd(), filepath); @@ -33,10 +33,14 @@ var convertLcovToCoveralls = function(input, filepath, cb){ lcovParse(input, function(err, parsed){ if (err){ return cb(err); } var postJson = { - service_job_id : TRAVIS_JOB_ID, - service_name : "travis-ci", source_files : [] }; + if (typeof repo_token !== "undefined" && repo_token !== null) { + postJson.repo_token = repo_token; + } else { + postJson.service_job_id = TRAVIS_JOB_ID; + postJson.service_name = 'travis-ci'; + } parsed.forEach(function(file){ postJson.source_files.push(convertLcovFileObject(file, filepath)); }); diff --git a/package.json b/package.json index feca522..54c1821 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "Alan Gutierrez <[email protected]> (http://www.prettyrobots.com/)" ], "dependencies": { + "libyaml": "0.2.2", "request": "2.16.2", "lcov-parse": "0.0.4" }, diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js index 6cf9521..f989578 100644 --- a/test/convertLcovToCoveralls.js +++ b/test/convertLcovToCoveralls.js @@ -8,7 +8,7 @@ describe("convertLcovToCoveralls", function(){ var path = __dirname + "/../fixtures/onefile.lcov"; var input = fs.readFileSync(path, "utf8"); var libpath = __dirname + "/../fixtures/lib"; - convertLcovToCoveralls(input, libpath, function(err, output){ + convertLcovToCoveralls(input, libpath, null, function(err, output){ should.not.exist(err); output.source_files[0].name.should.equal("index.js"); output.source_files[0].source.split("\n").length.should.equal(225); @@ -22,7 +22,7 @@ describe("convertLcovToCoveralls", function(){ var path = __dirname + "/../fixtures/onefile.lcov"; var input = fs.readFileSync(path, "utf8"); var libpath = "fixtures/lib"; - convertLcovToCoveralls(input, libpath, function(err, output){ + convertLcovToCoveralls(input, libpath, null, function(err, output){ should.not.exist(err); output.source_files[0].name.should.equal("index.js"); output.source_files[0].source.split("\n").length.should.equal(225); |
