[Pkg-javascript-commits] [node-coveralls] 60/332: improved testing.
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 9 13:53:40 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 311cdeedb62363ec047f0cfe8f1d9460a9735c3a
Author: cainus <gregg at caines.ca>
Date: Sat Jun 22 14:39:16 2013 -0700
improved testing.
---
index.js | 1 +
lib/convertLcovToCoveralls.js | 2 +-
lib/getOptions.js | 12 ++++++------
lib/handleInput.js | 2 +-
lib/logger.js | 15 +++++++--------
package.json | 2 +-
test/convertLcovToCoveralls.js | 19 +++++++++++++++++++
test/getOptions.js | 26 +++++++++++++++++++++++++-
test/logger.js | 11 +++++++++++
9 files changed, 72 insertions(+), 18 deletions(-)
diff --git a/index.js b/index.js
index d1195bc..3213209 100644
--- a/index.js
+++ b/index.js
@@ -6,3 +6,4 @@ exports.convertLcovToCoveralls = require(dir + 'convertLcovToCoveralls');
exports.sendToCoveralls = require(dir + 'sendToCoveralls');
exports.getOptions = require(dir + 'getOptions');
exports.handleInput = require(dir + 'handleInput');
+exports.logger = require(dir + 'logger');
diff --git a/lib/convertLcovToCoveralls.js b/lib/convertLcovToCoveralls.js
index a88b3ae..15bf962 100644
--- a/lib/convertLcovToCoveralls.js
+++ b/lib/convertLcovToCoveralls.js
@@ -2,7 +2,7 @@ var TRAVIS_JOB_ID = process.env.TRAVIS_JOB_ID || 'unknown';
var fs = require('fs');
var lcovParse = require('lcov-parse');
var path = require('path');
-var logger = require('./logger');
+var logger = require('./logger')();
var detailsToCoverage = function(length, details){
var coverage = new Array(length);
diff --git a/lib/getOptions.js b/lib/getOptions.js
index fa294b1..46957e5 100644
--- a/lib/getOptions.js
+++ b/lib/getOptions.js
@@ -1,7 +1,7 @@
var fs = require('fs');
var path = require('path');
var yaml = require('yaml');
-var logger = require('./logger');
+var logger = require('./logger')();
var getOptions = function(){
var options = {};
@@ -17,16 +17,16 @@ var getOptions = function(){
}
}
- if (process.env.git){
+ if (process.env.COVERALLS_GIT){
options.git = process.env.COVERALLS_GIT;
}
- if (process.env.service_job_id){
- options.git = process.env.COVERALLS_SERVICE_JOB_ID;
+ if (process.env.COVERALLS_SERVICE_JOB_ID){
+ options.service_job_id = process.env.COVERALLS_SERVICE_JOB_ID;
}
options.run_at = process.env.COVERALLS_RUN_AT || JSON.stringify(new Date()).slice(1, -1);
- if (process.env.service_name){
- options.service_name = service_name;
+ if (process.env.COVERALLS_SERVICE_NAME){
+ options.service_name = process.env.COVERALLS_SERVICE_NAME;
}
if (process.env.TRAVIS){
options.service_name = 'travis-ci';
diff --git a/lib/handleInput.js b/lib/handleInput.js
index 0ea17a9..8dee588 100644
--- a/lib/handleInput.js
+++ b/lib/handleInput.js
@@ -1,5 +1,5 @@
var index = require('../index');
-var logger = require('./logger');
+var logger = require('./logger')();
var handleInput = function(input){
logger.debug(input);
diff --git a/lib/logger.js b/lib/logger.js
index f44fe28..985b67b 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -1,9 +1,8 @@
-var logger = require('log-driver')({level : 'warn'});
-
-if (process.argv[2]) {
- if (~['-v', '--verbose'].indexOf(process.argv[2])) {
- logger = require('log-driver')({level : 'debug'});
+module.exports = function(){
+ if (process.argv[2]) {
+ if (~['-v', '--verbose'].indexOf(process.argv[2])) {
+ return require('log-driver')({level : 'debug'});
+ }
}
-}
-
-module.exports = logger;
+ return require('log-driver')({level : 'warn'});
+};
diff --git a/package.json b/package.json
index ef8d8e6..efe757b 100644
--- a/package.json
+++ b/package.json
@@ -5,7 +5,7 @@
"coverage",
"coveralls"
],
- "version": "2.0.14",
+ "version": "2.0.15",
"bugs": {
"url": "https://github.com/cainus/node-coveralls/issues"
},
diff --git a/test/convertLcovToCoveralls.js b/test/convertLcovToCoveralls.js
index c83dc6c..aea36a1 100644
--- a/test/convertLcovToCoveralls.js
+++ b/test/convertLcovToCoveralls.js
@@ -1,4 +1,5 @@
var convertLcovToCoveralls = require('../index').convertLcovToCoveralls;
+var getOptions = require('../index').getOptions;
var should = require('should');
var fs = require('fs');
var logger = require('../lib/logger');
@@ -19,6 +20,24 @@ describe("convertLcovToCoveralls", function(){
});
});
+ it ("should pass on all appropriate parameters from the environment", function(){
+ process.env.TRAVIS_JOB_ID = -1;
+ process.env.COVERALLS_GIT = "GIT_HASH";
+ process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
+ process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID";
+ process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN";
+
+ var options = getOptions();
+ var path = __dirname + "/../fixtures/onefile.lcov";
+ var input = fs.readFileSync(path, "utf8");
+ var libpath = "fixtures/lib";
+ options.filepath = libpath;
+ convertLcovToCoveralls(input, options, function(err, output){
+ should.not.exist(err);
+ console.log(output);
+ //output.git.should.equal("GIT_HASH");
+ });
+ });
it ("should work with a relative path as well", function(){
process.env.TRAVIS_JOB_ID = -1;
var path = __dirname + "/../fixtures/onefile.lcov";
diff --git a/test/getOptions.js b/test/getOptions.js
index e8e3c7a..c1c2133 100644
--- a/test/getOptions.js
+++ b/test/getOptions.js
@@ -2,6 +2,9 @@ var should = require('should');
var getOptions = require('../index').getOptions;
describe("getOptions", function(){
+ beforeEach(function(){
+ process.env = {};
+ });
it ("should get a filepath if there is one", function(){
process.argv[2] = "somepath";
getOptions().filepath.should.equal("somepath");
@@ -11,7 +14,28 @@ describe("getOptions", function(){
process.argv[2] = "--verbose";
process.argv[3] = "somepath";
getOptions().filepath.should.equal("somepath");
-
+ });
+ it ("should set service_job_id if it exists", function(){
+ process.env.COVERALLS_SERVICE_JOB_ID = "SERVICE_JOB_ID";
+ getOptions().service_job_id.should.equal("SERVICE_JOB_ID");
+ });
+ it ("should set git if it exists", function(){
+ process.env.COVERALLS_GIT = "qwer";
+ getOptions().git.should.equal("qwer");
+ });
+ it ("should set repo_token if it exists", function(){
+ process.env.COVERALLS_REPO_TOKEN = "REPO_TOKEN";
+ getOptions().repo_token.should.equal("REPO_TOKEN");
+ });
+ it ("should set service_name if it exists", function(){
+ process.env.COVERALLS_SERVICE_NAME = "SERVICE_NAME";
+ getOptions().service_name.should.equal("SERVICE_NAME");
+ });
+ it ("should set service_name and service_job_id if it's running on travis-ci", function(){
+ process.env.TRAVIS = "TRUE";
+ process.env.TRAVIS_JOB_ID = "1234";
+ getOptions().service_name.should.equal("travis-ci");
+ getOptions().service_job_id.should.equal("1234");
});
});
diff --git a/test/logger.js b/test/logger.js
new file mode 100644
index 0000000..c6899db
--- /dev/null
+++ b/test/logger.js
@@ -0,0 +1,11 @@
+var should = require('should');
+var sinon = require('sinon-restore');
+var index = require('../index');
+
+describe("logger", function(){
+ it ("should log at debug level when --verbose is set", function(){
+ process.argv[2] = '--verbose';
+ var logger = require('../index').logger();
+ logger.level.should.equal('debug');
+ });
+});
--
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