2a550bb76ba1c5225bb8788139fbc2c65badd030.svn-base
5.48 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
/* THIS FILE SHOULD BE BROWSER-COMPATIBLE JS!
* You can use @REMOVE_LINE_FOR_BROWSER to remove code from the browser build.
* Only code on that line will be removed, its mostly to avoid requiring code
* that is node specific
*/
var nodeunit = require('../lib/nodeunit'); // @REMOVE_LINE_FOR_BROWSER
exports.testRunModule = function (test) {
test.expect(11);
var call_order = [];
var testmodule = {
test1: function (test) {
call_order.push('test1');
test.ok(true, 'ok true');
test.done();
},
test2: function (test) {
call_order.push('test2');
test.ok(false, 'ok false');
test.ok(false, 'ok false');
test.done();
},
test3: function (test) {
call_order.push('test3');
test.done();
}
};
nodeunit.runModule('testmodule', testmodule, {
log: function (assertion) {
call_order.push('log');
},
testStart: function (name) {
call_order.push('testStart');
test.ok(
name.toString() === 'test1' ||
name.toString() === 'test2' ||
name.toString() === 'test3',
'testStart called with test name '
);
},
testDone: function (name, assertions) {
call_order.push('testDone');
test.ok(
name.toString() === 'test1' ||
name.toString() === 'test2' ||
name.toString() === 'test3',
'testDone called with test name'
);
},
moduleDone: function (name, assertions) {
call_order.push('moduleDone');
test.equals(assertions.length, 3);
test.equals(assertions.failures(), 2);
test.equals(name, 'testmodule');
test.ok(typeof assertions.duration === "number");
test.same(call_order, [
'testStart', 'test1', 'log', 'testDone',
'testStart', 'test2', 'log', 'log', 'testDone',
'testStart', 'test3', 'testDone',
'moduleDone'
]);
}
}, test.done);
};
exports.testRunModuleTestSpec = function (test) {
test.expect(6);
var call_order = [];
var testmodule = {
test1: function (test) {
test.ok(true, 'ok true');
test.done();
},
test2: function (test) {
call_order.push('test2');
test.ok(false, 'ok false');
test.ok(false, 'ok false');
test.done();
},
test3: function (test) {
test.done();
}
};
nodeunit.runModule('testmodule', testmodule, {
testspec: "test2",
log: function (assertion) {
call_order.push('log');
},
testStart: function (name) {
call_order.push('testStart');
test.equals(
name,'test2',
'testStart called with test name '
);
},
testDone: function (name, assertions) {
call_order.push('testDone');
test.equal(
name, 'test2',
'testDone called with test name'
);
},
moduleDone: function (name, assertions) {
call_order.push('moduleDone');
test.equals(assertions.length, 2);
test.equals(name, 'testmodule');
test.ok(typeof assertions.duration === "number");
test.same(call_order, [
'testStart', 'test2', 'log', 'log', 'testDone',
'moduleDone'
]);
}
}, test.done);
};
exports.testRunModuleEmpty = function (test) {
nodeunit.runModule('module with no exports', {}, {
log: function (assertion) {
test.ok(false, 'log should not be called');
},
testStart: function (name) {
test.ok(false, 'testStart should not be called');
},
testDone: function (name, assertions) {
test.ok(false, 'testDone should not be called');
},
moduleDone: function (name, assertions) {
test.equals(assertions.length, 0);
test.equals(assertions.failures(), 0);
test.equals(name, 'module with no exports');
test.ok(typeof assertions.duration === "number");
}
}, test.done);
};
exports.testNestedTests = function (test) {
var call_order = [];
var m = {
test1: function (test) {
test.done();
},
suite: {
t1: function (test) {
test.done();
},
t2: function (test) {
test.done();
},
another_suite: {
t3: function (test) {
test.done();
}
}
}
};
nodeunit.runModule('modulename', m, {
testStart: function (name) {
call_order.push(['testStart'].concat(name));
},
testDone: function (name, assertions) {
call_order.push(['testDone'].concat(name));
}
}, function () {
test.same(call_order, [
['testStart', 'test1'], ['testDone', 'test1'],
['testStart', 'suite', 't1'], ['testDone', 'suite', 't1'],
['testStart', 'suite', 't2'], ['testDone', 'suite', 't2'],
['testStart', 'suite', 'another_suite', 't3'],
['testDone', 'suite', 'another_suite', 't3']
]);
test.done();
});
};