Skip to content

Commit

Permalink
Updates test framework to check for config and give a better error me…
Browse files Browse the repository at this point in the history
…ssage

Also, don't run a protocol if not configured (and specially don't
return error code for it)
  • Loading branch information
dresende committed Jul 30, 2013
1 parent 19ee31e commit b888d9e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
12 changes: 12 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ common.createConnection = function(cb) {
ORM.connect(this.getConnectionString(), cb);
};

common.hasConfig = function (proto) {
var config;

try {
config = require("./config");
} catch (ex) {
return 'not-found';
}

return (config.hasOwnProperty(proto) ? 'found' : 'not-defined');
};

common.getConfig = function () {
if (common.isTravis()) {
switch (this.protocol()) {
Expand Down
29 changes: 29 additions & 0 deletions test/logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var util = require("util");

exports.info = buildMethod(process.stdout, "[i]", 34);
exports.error = buildMethod(process.stderr, "[!]", 31);

function buildMethod(stream, prefix, color) {
return function () {
var params = Array.prototype.slice.apply(arguments);
var text = params.shift();

return printTo(stream, prefix + " ", color, text, params);
};
}

function printTo(stream, prefix, color, text, params) {
params.unshift(text);
text = util.format.apply(util, params);

stream.write(printColor(color, true) + prefix + printColor(color) + text.replace(/\*\*(.+?)\*\*/, function (m, t) {
return printColor(color, true) + t + printColor(color);
}) + printColor(null) + "\n");
}

function printColor(color, bold) {
if (color === null) {
return "\033[0m";
}
return "\033[" + (bold ? "1" : "0") + ";" + color + "m";
}
22 changes: 16 additions & 6 deletions test/run.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');
var Mocha = require("mocha");
var fs = require("fs");
var path = require("path");
var common = require("./common");
var logging = require("./logging");
var location = path.normalize(path.join(__dirname, "integration"));
var mocha = new Mocha({
reporter: "progress"
});

switch (common.hasConfig(common.protocol())) {
case 'not-defined':
logging.error("There's no configuration for protocol **%s**", common.protocol());
process.exit(0);
case 'not-found':
logging.error("**test/config.js** missing. Take a look at **test/config.example.js**");
process.exit(0);
}

runTests();

function runTests() {
Expand All @@ -19,8 +30,7 @@ function runTests() {
);
});

process.stdout.write("\033[1;34m[i] \033[0;34mTesting \033[1;34m" + process.env.ORM_PROTOCOL + "\033[0m\n");
process.stdout.write("\033[1;34m[i] \033[0;34mURI: \033[1;34m" + require('./common').getConnectionString() + "\033[0m\n");
logging.info("Testing **%s**", common.getConnectionString());

mocha.run(function (failures) {
process.exit(failures);
Expand All @@ -29,7 +39,7 @@ function runTests() {

function shouldRunTest(file) {
var name = file.substr(0, file.length - 3);
var proto = process.env.ORM_PROTOCOL;
var proto = common.protocol();

if (proto == "mongodb" && [ "model-aggregate",
"property-number-size", "smart-types" ].indexOf(name) >= 0) return false;
Expand Down

0 comments on commit b888d9e

Please sign in to comment.