[Pkg-javascript-commits] [node-coveralls] 35/332: refactored for better testability.
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 9 13:53:37 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 4c0bde3ee9088d163f3956e8c3d85dfcdab9b5a0
Author: cainus <gregg at caines.ca>
Date: Wed May 29 15:07:50 2013 -0700
refactored for better testability.
---
.gitignore | 2 ++
Makefile | 8 +++++++-
bin/coveralls.js | 43 ++----------------------------------------
index.js | 7 +++++++
lib/convertLcovToCoveralls.js | 5 ++++-
lib/handleInput.js | 43 ++++++++++++++++++++++++++++++++++++++++++
package.json | 8 +++++---
test/convertLcovToCoveralls.js | 2 +-
8 files changed, 71 insertions(+), 47 deletions(-)
diff --git a/.gitignore b/.gitignore
index c2658d7..2c09685 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
node_modules/
+coverage.html
+lib-cov/
diff --git a/Makefile b/Makefile
index 3675272..4949c53 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,13 @@ lib-cov:
test-cov: lib-cov
echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID)
- @PERCOLATOR_COVERAGE=1 $(MAKE) test REPORTER=html-cov 1> coverage.html
+ @COVERALLS_COVERAGE=1 $(MAKE) test REPORTER=html-cov 1> coverage.html
+ rm -rf lib-cov
+
+test-coveralls:lib-cov
+ $(MAKE) test REPORTER=spec
+ echo TRAVIS_JOB_ID $(TRAVIS_JOB_ID)
+ @COVERALLS_COVERAGE=1 $(MAKE) test REPORTERPORTER=mocha-lcov-reporter | ./bin/coveralls.js
rm -rf lib-cov
.PHONY: test
diff --git a/bin/coveralls.js b/bin/coveralls.js
index 38e8071..698f177 100755
--- a/bin/coveralls.js
+++ b/bin/coveralls.js
@@ -1,10 +1,5 @@
#!/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');
-var repo_token;
+var handleInput = require('../lib/handleInput');
process.stdin.resume();
process.stdin.setEncoding('utf8');
@@ -16,40 +11,6 @@ process.stdin.on('data', function(chunk) {
});
process.stdin.on('end', function() {
- inputToCoveralls(input);
+ handleInput(input);
});
-var inputToCoveralls = function(input){
- console.log(input);
- var libDir = process.argv[2] || '';
-
- if (process.env.COVERALLS_REPO_TOKEN) {
- repo_token = process.env.COVERALLS_REPO_TOKEN;
- } else {
- var yml = path.join(process.cwd(), '.coveralls.yml');
- try {
- if (fs.statSync(yml).isFile()) {
- repo_token = YAML.readFileSync(yml)[0].repo_token;
- }
- } catch(ex){
- console.log("Repo token could not be determined. Continuing without it.");
- }
- }
-
- convertLcovToCoveralls(input, libDir, repo_token, function(err, postData){
- if (err){
- throw err;
- }
- sendToCoveralls(postData, function(err, response, body){
- if (err){
- throw err;
- }
- if (response.statusCode >= 400){
- throw "Bad response: " + response.statusCode + " " + body;
- }
- console.log(response.statusCode);
- console.log(body);
- });
- });
-
-};
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..7bd3e60
--- /dev/null
+++ b/index.js
@@ -0,0 +1,7 @@
+var dir = './lib/';
+if (process.env.COVERALLS_COVERAGE){
+ dir = './lib-cov/';
+}
+exports.convertLcovToCoveralls = require(dir + 'convertLcovToCoveralls');
+exports.sendToCoveralls = require(dir + 'sendToCoveralls');
+exports.handleInput = require(dir + 'handleInput');
diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js
index 3f63f15..00aa437 100644
--- a/lib/convertLcovToCoveralls.js
+++ b/lib/convertLcovToCoveralls.js
@@ -31,7 +31,10 @@ var convertLcovToCoveralls = function(input, filepath, repo_token, cb){
filepath = path.join(process.cwd(), filepath);
}
lcovParse(input, function(err, parsed){
- if (err){ return cb(err); }
+ if (err){
+ console.log("error from lcovParse: ", err);
+ return cb(err);
+ }
var postJson = {
source_files : []
};
diff --git a/lib/handleInput.js b/lib/handleInput.js
new file mode 100644
index 0000000..6a8168a
--- /dev/null
+++ b/lib/handleInput.js
@@ -0,0 +1,43 @@
+var fs = require('fs');
+var path = require('path');
+var YAML = require('libyaml');
+var sendToCoveralls = require('../index').sendToCoveralls;
+var convertLcovToCoveralls = require('../index').convertLcovToCoveralls;
+var repo_token;
+
+var handleInput = function(input){
+ console.log(input);
+ var libDir = process.argv[2] || '';
+
+ if (process.env.COVERALLS_REPO_TOKEN) {
+ repo_token = process.env.COVERALLS_REPO_TOKEN;
+ } else {
+ var yml = path.join(process.cwd(), '.coveralls.yml');
+ try {
+ if (fs.statSync(yml).isFile()) {
+ repo_token = YAML.readFileSync(yml)[0].repo_token;
+ }
+ } catch(ex){
+ console.log("Repo token could not be determined. Continuing without it.");
+ }
+ }
+
+ convertLcovToCoveralls(input, libDir, repo_token, function(err, postData){
+ if (err){
+ throw err;
+ }
+ sendToCoveralls(postData, function(err, response, body){
+ if (err){
+ throw err;
+ }
+ if (response.statusCode >= 400){
+ throw "Bad response: " + response.statusCode + " " + body;
+ }
+ console.log(response.statusCode);
+ console.log(body);
+ });
+ });
+
+};
+
+module.exports = handleInput;
diff --git a/package.json b/package.json
index 336cbef..815e135 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"url": "https://github.com/cainus/node-coveralls/issues"
},
"scripts": {
- "test": "make test"
+ "test": "make test-coveralls"
},
"bin": {
"coveralls": "./bin/coveralls.js"
@@ -18,7 +18,7 @@
"maintainers": [
"Gregg Caines <gregg at caines.ca> (http://caines.ca)"
],
- "contributors" : [
+ "contributors": [
"Alan Gutierrez <alan at prettyrobots.com> (http://www.prettyrobots.com/)",
"Kir Belevich (https://github.com/svg)",
"elliotcable <github at elliottcable.name> (http://elliottcable.name/)"
@@ -29,8 +29,10 @@
"lcov-parse": "0.0.4"
},
"devDependencies": {
+ "mocha-lcov-reporter": "0.0.1",
"mocha": "1.8.1",
- "should": "1.1.0"
+ "should": "1.1.0",
+ "jscoverage": "0.3.7"
},
"engines": {
"node": ">=0.8.6",
diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js
index f989578..9094631 100644
--- a/test/convertLcovToCoveralls.js
+++ b/test/convertLcovToCoveralls.js
@@ -1,4 +1,4 @@
-var convertLcovToCoveralls = require('../lib/convertLcovToCoveralls');
+var convertLcovToCoveralls = require('../index').convertLcovToCoveralls;
var should = require('should');
var fs = require('fs');
--
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