Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switching to instanbul for test coverage
- Loading branch information
1 parent
f2e77cd
commit faba5e1
Showing
8 changed files
with
200 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
test/settings.js | ||
doc | ||
lib-cov | ||
coverage | ||
coverage.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
if (process.env.EASY_MYSQL_JSCOV) { | ||
module.exports = require("./lib-cov/easy_mysql"); | ||
} else { | ||
module.exports = require("./lib/easy_mysql"); | ||
} | ||
module.exports = require("./lib/easy_mysql"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env node | ||
process.env.NODE_ENV = 'test'; | ||
require('../index'); | ||
|
||
var Mocha = require('mocha'); | ||
var optimist = require('optimist'); | ||
var walk_dir = require('./support/walk_dir'); | ||
|
||
var argv = optimist | ||
.usage("Usage: $0 -T [types] --reporter [reporter] --timeout [timeout]") | ||
.default({types: 'unit,component', reporter: 'spec', timeout: 6000}) | ||
.describe('types', 'The types of tests to run, separated by commas. E.g., unit,functional,acceptance') | ||
.describe('reporter', 'The mocha test reporter to use.') | ||
.describe('timeout', 'The mocha timeout to use per test (ms).') | ||
.boolean('bail') | ||
.describe('bail', 'Bail on first failure') | ||
.boolean('verbose') | ||
.describe('verbose', 'Verbose output') | ||
.boolean('help') | ||
.alias('types', 'T') | ||
.alias('timeout', 't') | ||
.alias('reporter', 'R') | ||
.alias('bail', 'b') | ||
.alias('help', 'h') | ||
.argv; | ||
|
||
var mocha = new Mocha({timeout: argv.timeout, reporter: argv.reporter, ui: 'bdd'}); | ||
mocha.checkLeaks(); | ||
if (argv.bail) { | ||
mocha.bail(); | ||
} | ||
|
||
var valid_test_types = ['unit', 'functional', 'acceptance', 'integration']; | ||
var requested_types = argv.types.split(','); | ||
var types_to_use = []; | ||
|
||
valid_test_types.forEach(function (valid_test_type) { | ||
if (requested_types.indexOf(valid_test_type) !== -1) { | ||
types_to_use.push(valid_test_type); | ||
} | ||
}); | ||
|
||
if (argv.help || types_to_use.length === 0) { | ||
console.log('\n' + optimist.help()); | ||
process.exit(); | ||
} | ||
|
||
var is_valid_file = function (file) { | ||
for (var i = 0; i < types_to_use.length; i++) { | ||
var test_type = types_to_use[i]; | ||
var ext = test_type + ".js"; | ||
|
||
if (file.indexOf(ext) !== -1) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
var test_files = []; | ||
|
||
function run(cb) { | ||
walk_dir.walk('test', is_valid_file, function (err, files) { | ||
if (err) { return cb(err); } | ||
|
||
files.forEach(function (file) { | ||
test_files.push(file); | ||
mocha.addFile(file); | ||
}); | ||
|
||
cb(); | ||
}); | ||
} | ||
|
||
run(function (err) { | ||
if (err) { throw err; } | ||
|
||
if (argv.verbose) { | ||
console.log("\nTest files:"); | ||
test_files.forEach(function (file) { | ||
console.log(file + " \\"); | ||
}); | ||
} | ||
mocha.run(function (failures) { | ||
process.exit(failures); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var util = require('util'); | ||
require('../../index'); | ||
|
||
module.exports = { | ||
fake_logger: require('./fake_logger'), | ||
|
||
random: require('./random'), | ||
|
||
walk_dir: require('./walk_dir'), | ||
|
||
shallow_clone: function (object) { | ||
var ret = {}; | ||
if (object) { | ||
Object.keys(object).forEach(function (val) { | ||
ret[val] = object[val]; | ||
}); | ||
} | ||
return ret; | ||
}, | ||
|
||
fake_error: function () { | ||
return new Error(this.random.string()); | ||
}, | ||
|
||
check_err: function (err) { | ||
if (err) { | ||
var msg; | ||
|
||
if (err instanceof Error) { | ||
msg = err; | ||
} else if (err.msg) { | ||
msg = err.msg; | ||
} else { | ||
msg = util.inspect(err); | ||
} | ||
|
||
throw new Error(msg); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var fs = require('fs'); | ||
|
||
var methods = { | ||
walk: function (dir, validation_function, cb) { | ||
if (arguments.length === 2) { | ||
cb = validation_function; | ||
validation_function = null; | ||
} | ||
|
||
var results = []; | ||
fs.readdir(dir, function (err, list) { | ||
if (err) { return cb(err); } | ||
|
||
var pending = list.length; | ||
|
||
if (!pending) { return cb(null, results); } | ||
|
||
list.forEach(function (file) { | ||
file = dir + '/' + file; | ||
fs.stat(file, function (err, stat) { | ||
if (stat && stat.isDirectory()) { | ||
methods.walk(file, validation_function, function (err, res) { | ||
results = results.concat(res); | ||
if (!--pending) { cb(null, results); } | ||
}); | ||
} else { | ||
if (typeof validation_function === 'function') { | ||
if (validation_function(file)) { | ||
results.push(file); | ||
} | ||
} else { | ||
results.push(file); | ||
} | ||
|
||
if (!--pending) { cb(null, results); } | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = methods; |