forked from YahooArchive/mojito
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index-tests.js
235 lines (211 loc) · 7.01 KB
/
index-tests.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
YUI.add('mojito-server-tests', function(Y, NAME) {
var path = require('path'),
vm = require('vm'),
fs = require('fs'),
theServer = require(path.join(__dirname, '../../index.js')),
MojitoServer = theServer.constructor,
server,
suite = new YUITest.TestSuite(NAME),
A = YUITest.Assert,
OA = YUITest.ObjectAssert;
suite.add(new YUITest.TestCase({
name: 'HTTP server',
setUp: function() {
server = new MojitoServer();
},
tearDown: function() {
server = null;
},
'MojitoServer object is returned from require()': function() {
A.isObject(theServer);
},
'createServer creates an express app, installs it, and returns it': function() {
var appInstalled;
server.addMojitoToExpressApp = function(a) {
appInstalled = true;
// TODO: figure out how to test that this is a connect app
A.isObject(a, 'no app!');
};
var app = server.createServer();
A.isTrue(appInstalled, "app wasn't installed");
},
'TODO: addMojitoToExpressApp installs the static handler first': function() {
A.skip();
// var useCount = 0;
// var used;
// var app = {
// use: function(handle) {
// if (useCount === 0) {
// used = true;
// A.areSame('static', handle, 'static handler was not first');
// }
// useCount++;
// }
// };
//
// var SH = global.StaticHandler;
//
// global.StaticHandler = {
// handle: function() {
// return 'static';
// }
// };
//
// server.addMojitoToExpressApp(app);
//
// A.isTrue(used, "static handler was never used");
//
// global.StaticHandler = SH;
},
'TODO: addMojitoToExpressApp installs the body parser second': function() {
A.skip();
// var useCount = 0;
// var used;
// var app = {
// use: function(handle) {
// if (useCount === 1) {
// used = true;
// A.areSame('bodyParser', handle, 'bodyParser was not second');
// }
// useCount++;
// }
// };
//
// var EX = global.express;
//
// global.express = {
// bodyParser: function() {
// return 'bodyParser';
// },
// cookieParser: function() {
// return 'cookieParser';
// }
// };
//
// server.addMojitoToExpressApp(app);
//
// A.isTrue(used, "bodyParser was never used");
//
// global.express = EX;
},
'TODO: addMojitoToExpressApp installs the cookie parser third': function() {
A.skip();
// var useCount = 0;
// var used;
// var app = {
// use: function(handle) {
// if (useCount === 2) {
// used = true;
// A.areSame('cookieParser', handle, 'cookieParser was not third');
// }
// useCount++;
// }
// };
//
// var EX = global.express;
//
// global.express = {
// bodyParser: function() {
// return 'bodyParser';
// },
// cookieParser: function() {
// return 'cookieParser';
// }
// };
//
// server.addMojitoToExpressApp(app);
//
// A.isTrue(used, "bodyParser was never used");
//
// global.express = EX;
},
'TODO: addMojitoToExpressApp installs the request contextualizer fourth': function() {
A.skip();
// var useCount = 0;
// var used;
// var app = {
// use: function(handle) {
// if (useCount === 3) {
// used = true;
// A.areSame('rc', handle, 'RequestContextualizer was not fourth');
// }
// useCount++;
// }
// };
//
// var RC = global.RequestContextualizer;
//
// global.RequestContextualizer = {
// handle: function() {
// return 'rc';
// }
// };
//
// server.addMojitoToExpressApp(app);
//
// A.isTrue(used, "RequestContextualizer was never used");
//
// global.RequestContextualizer = RC;
},
'TODO: addMojitoToExpressApp installs the tunnel server fifth': function() {
A.skip();
// var useCount = 0;
// var used;
// var app = {
// use: function(handle) {
// if (useCount === 4) {
// used = true;
// A.areSame('tc', handle, 'TunnelServer was not fifth');
// }
// useCount++;
// }
// };
//
// var TC = global.TunnelServer;
//
// global.TunnelServer = {
// handle: function() {
// return 'tc';
// }
// };
//
// server.addMojitoToExpressApp(app);
//
// A.isTrue(used, "TunnelServer was never used");
//
// global.TunnelServer = TC;
},
'addMojitoToExpressApp only installs 7 middlewares': function() {
A.skip(); //FIX: this test reloads files, resetting test coverage
// var useCount = 0;
// var app = {
// use: function() {
// useCount++;
// }
// };
//
// server.addMojitoToExpressApp(app);
//
// A.areSame(7, useCount, "Should be 7 middlewares installed");
//
},
'setLogFormatter() accepts a log formatter': function() {
server.setLogFormatter("myVal");
A.areEqual("myVal", server._logFormatter, "setLogFormatter() did not set the expected private property");
},
'setLogPublisher() accepts a log publisher': function() {
server.setLogPublisher("myVal");
A.areEqual("myVal", server._logPublisher, "setLogPublisher() did not set the expected private property");
},
'setLogWriter() accepts a log writer': function() {
server.setLogWriter("myVal");
A.areEqual("myVal", server._logWriter, "setLogWriter() did not set the expected private property");
}
}));
YUITest.TestRunner.add(suite);
}, '0.0.1');