[Pkg-javascript-commits] [node-coveralls] 29/332: Supporting command-line usage outside of Travis-CI

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:53:35 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-coveralls.

commit 92783b483630b516b83cab3b555cce2fb5b79982
Author: elliottcable <me at ell.io>
Date:   Fri May 24 02:42:15 2013 -0400

    Supporting command-line usage outside of Travis-CI
---
 README.md                      |  7 ++++---
 bin/coveralls.js               | 22 ++++++++++++++--------
 lib/convertLcovToCoveralls.js  | 10 +++++++---
 package.json                   |  1 +
 test/convertLcovToCoveralls.js |  4 ++--
 5 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md
index 1eebbb1..4f41665 100644
--- a/README.md
+++ b/README.md
@@ -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
old mode 100644
new mode 100755
index 288b451..d3d18e1
--- 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 <alan at prettyrobots.com> (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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-coveralls.git



More information about the Pkg-javascript-commits mailing list