-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtdd.js
109 lines (92 loc) · 3.05 KB
/
tdd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env node
/**
* Module dependencies
*/
var nodeunit = require('./node_modules/nodeunit/lib/nodeunit'),
utils = require('./node_modules/nodeunit/lib/utils'),
fs = require('fs'),
path = require('path'),
growl = require('growl'),
AssertionError = require('assert').AssertionError;
/**
* Reporter info string
*/
exports.info = "Reporter for TDD and Dojos";
/**
* Run all tests within each module, reporting the results to the command-line.
*
* @param {Array} files
* @api public
*/
exports.run = function (files, options, callback) {
if (!options) {
// load default options
var content = fs.readFileSync(__dirname + '/node_modules/nodeunit/bin/nodeunit.json', 'utf8');
options = JSON.parse(content);
}
var start = new Date().getTime();
var opts = {
testspec: options.testspec,
testFullSpec: options.testFullSpec,
moduleDone: function (name, assertions) {
if (assertions.failures()) {
console.log('');
process.stdout.write(name + ': ');
assertions.forEach(function (a) {
if (a.failed()) {
a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) {
console.log('Assertion in test ' + a.testname + ': ' + a.message);
}
console.log(a.error.stack + '\n');
}
});
}
},
testStart: function () {
},
testDone: function (name, assertions) {
if (!assertions.failures()) {
process.stdout.write('.');
} else {
process.stdout.write('F');
assertions.forEach(
function (assertion) {
assertion.testname = name;
}
);
}
},
done: function (assertions) {
var end = new Date().getTime();
var duration = end - start;
var msg;
if (assertions.failures()) {
msg = '\nFAILURES: ' + assertions.failures() + '/' + assertions.length + ' assertions failed (' + assertions.duration + 'ms)';
} else {
msg = '\nOK: ' + assertions.length + ' assertions (' + assertions.duration + 'ms)';
}
console.log(msg);
growl(msg, {title: "nodeNES"});
if (callback) callback(assertions.failures() ? new Error('We have got test failures.') : undefined);
}
};
if (files && files.length) {
var paths = files.map(function (p) {
return path.join(process.cwd(), p);
});
nodeunit.runFiles(paths, opts);
} else {
nodeunit.runModules(files,opts);
}
};
try {
nodeunit.reporters.tdd = exports;
var reporter = nodeunit.reporters.tdd;
}
catch(e) {
console.log("Cannot find nodeunit module.");
process.exit();
}
process.chdir(__dirname);
reporter.run(['tests']);