52ed9b1fcc089b2e67353222e534263bde0e684f.svn-base
6.41 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
var assert = require('assert'),
fs = require('fs'),
path = require('path'),
nodeunit = require('../lib/nodeunit');
var setup = function (fn) {
return function (test) {
process.chdir(__dirname);
var env = {
mock_module1: require(__dirname + '/fixtures/mock_module1'),
mock_module2: require(__dirname + '/fixtures/mock_module2'),
mock_module3: require(__dirname + '/fixtures/dir/mock_module3'),
mock_module4: require(__dirname + '/fixtures/dir/mock_module4')
};
fn.call(env, test);
};
};
exports.testRunFiles = setup(function (test) {
test.expect(24);
var runModule_copy = nodeunit.runModule;
var runModule_calls = [];
var modules = [];
var opts = {
moduleStart: function () {
return 'moduleStart';
},
testDone: function () {
return 'testDone';
},
testStart: function () {
return 'testStart';
},
log: function () {
return 'log';
},
done: function (assertions) {
test.equals(assertions.failures(), 0, 'failures');
test.equals(assertions.length, 4, 'length');
test.ok(typeof assertions.duration === "number");
var called_with = function (name) {
return runModule_calls.some(function (m) {
return m.name === name;
});
};
test.ok(called_with('mock_module1'), 'mock_module1 ran');
test.ok(called_with('mock_module2'), 'mock_module2 ran');
test.ok(called_with('mock_module3'), 'mock_module3 ran');
test.ok(called_with('mock_module4'), 'mock_module4 ran');
test.equals(runModule_calls.length, 4);
nodeunit.runModule = runModule_copy;
test.done();
}
};
nodeunit.runModule = function (name, mod, options, callback) {
test.equals(options.testDone, opts.testDone);
test.equals(options.testStart, opts.testStart);
test.equals(options.log, opts.log);
test.ok(typeof name === "string");
runModule_calls.push(mod);
var m = [{failed: function () {
return false;
}}];
modules.push(m);
callback(null, m);
};
nodeunit.runFiles(
[__dirname + '/fixtures/mock_module1.js',
__dirname + '/fixtures/mock_module2.js',
__dirname + '/fixtures/dir'],
opts
);
});
exports.testRunFilesEmpty = function (test) {
test.expect(3);
nodeunit.runFiles([], {
moduleStart: function () {
test.ok(false, 'should not be called');
},
testDone: function () {
test.ok(false, 'should not be called');
},
testStart: function () {
test.ok(false, 'should not be called');
},
log: function () {
test.ok(false, 'should not be called');
},
done: function (assertions) {
test.equals(assertions.failures(), 0, 'failures');
test.equals(assertions.length, 0, 'length');
test.ok(typeof assertions.duration === "number");
test.done();
}
});
};
exports.testEmptyDir = function (test) {
var dir2 = __dirname + '/fixtures/dir2';
// git doesn't like empty directories, so we have to create one
path.exists(dir2, function (exists) {
if (!exists) {
fs.mkdirSync(dir2, 0777);
}
// runFiles on empty directory:
nodeunit.runFiles([dir2], {
moduleStart: function () {
test.ok(false, 'should not be called');
},
testDone: function () {
test.ok(false, 'should not be called');
},
testStart: function () {
test.ok(false, 'should not be called');
},
log: function () {
test.ok(false, 'should not be called');
},
done: function (assertions) {
test.equals(assertions.failures(), 0, 'failures');
test.equals(assertions.length, 0, 'length');
test.ok(typeof assertions.duration === "number");
test.done();
}
});
});
};
var CoffeeScript;
try {
CoffeeScript = require('coffee-script');
} catch (e) {
}
if (CoffeeScript) {
exports.testCoffeeScript = function (test) {
process.chdir(__dirname);
var env = {
mock_coffee_module: require(__dirname +
'/fixtures/coffee/mock_coffee_module')
};
test.expect(9);
var runModule_copy = nodeunit.runModule;
var runModule_calls = [];
var modules = [];
var opts = {
moduleStart: function () {
return 'moduleStart';
},
testDone: function () {
return 'testDone';
},
testStart: function () {
return 'testStart';
},
log: function () {
return 'log';
},
done: function (assertions) {
test.equals(assertions.failures(), 0, 'failures');
test.equals(assertions.length, 1, 'length');
test.ok(typeof assertions.duration === "number");
var called_with = function (name) {
return runModule_calls.some(function (m) {
return m.name === name;
});
};
test.ok(
called_with('mock_coffee_15'),
'mock_coffee_module ran'
);
test.equals(runModule_calls.length, 1);
nodeunit.runModule = runModule_copy;
test.done();
}
};
nodeunit.runModule = function (name, mod, options, callback) {
test.equals(options.testDone, opts.testDone);
test.equals(options.testStart, opts.testStart);
test.equals(options.log, opts.log);
test.ok(typeof name === "string");
runModule_calls.push(mod);
var m = [{failed: function () {
return false;
}}];
modules.push(m);
callback(null, m);
};
nodeunit.runFiles(
[__dirname + 'fixtures/coffee/mock_coffee_module.coffee'],
opts
);
};
}