Skip to content

Commit b888d9e

Browse files
committed
Updates test framework to check for config and give a better error message
Also, don't run a protocol if not configured (and specially don't return error code for it)
1 parent 19ee31e commit b888d9e

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

test/common.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ common.createConnection = function(cb) {
1717
ORM.connect(this.getConnectionString(), cb);
1818
};
1919

20+
common.hasConfig = function (proto) {
21+
var config;
22+
23+
try {
24+
config = require("./config");
25+
} catch (ex) {
26+
return 'not-found';
27+
}
28+
29+
return (config.hasOwnProperty(proto) ? 'found' : 'not-defined');
30+
};
31+
2032
common.getConfig = function () {
2133
if (common.isTravis()) {
2234
switch (this.protocol()) {

test/logging.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var util = require("util");
2+
3+
exports.info = buildMethod(process.stdout, "[i]", 34);
4+
exports.error = buildMethod(process.stderr, "[!]", 31);
5+
6+
function buildMethod(stream, prefix, color) {
7+
return function () {
8+
var params = Array.prototype.slice.apply(arguments);
9+
var text = params.shift();
10+
11+
return printTo(stream, prefix + " ", color, text, params);
12+
};
13+
}
14+
15+
function printTo(stream, prefix, color, text, params) {
16+
params.unshift(text);
17+
text = util.format.apply(util, params);
18+
19+
stream.write(printColor(color, true) + prefix + printColor(color) + text.replace(/\*\*(.+?)\*\*/, function (m, t) {
20+
return printColor(color, true) + t + printColor(color);
21+
}) + printColor(null) + "\n");
22+
}
23+
24+
function printColor(color, bold) {
25+
if (color === null) {
26+
return "\033[0m";
27+
}
28+
return "\033[" + (bold ? "1" : "0") + ";" + color + "m";
29+
}

test/run.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
var Mocha = require('mocha');
2-
var fs = require('fs');
3-
var path = require('path');
1+
var Mocha = require("mocha");
2+
var fs = require("fs");
3+
var path = require("path");
4+
var common = require("./common");
5+
var logging = require("./logging");
46
var location = path.normalize(path.join(__dirname, "integration"));
57
var mocha = new Mocha({
68
reporter: "progress"
79
});
810

11+
switch (common.hasConfig(common.protocol())) {
12+
case 'not-defined':
13+
logging.error("There's no configuration for protocol **%s**", common.protocol());
14+
process.exit(0);
15+
case 'not-found':
16+
logging.error("**test/config.js** missing. Take a look at **test/config.example.js**");
17+
process.exit(0);
18+
}
19+
920
runTests();
1021

1122
function runTests() {
@@ -19,8 +30,7 @@ function runTests() {
1930
);
2031
});
2132

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

2535
mocha.run(function (failures) {
2636
process.exit(failures);
@@ -29,7 +39,7 @@ function runTests() {
2939

3040
function shouldRunTest(file) {
3141
var name = file.substr(0, file.length - 3);
32-
var proto = process.env.ORM_PROTOCOL;
42+
var proto = common.protocol();
3343

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

0 commit comments

Comments
 (0)