Mercurial > hg > nodescore
comparison node_modules/node-static/test/integration/node-static-test.js @ 69:333afcfd3f3a
added node_modules to project and fixed path to chronometer
also added deps to installer script
author | tzara <rc-web@kiben.net> |
---|---|
date | Sat, 26 Oct 2013 14:12:50 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
68:b076cd17638c | 69:333afcfd3f3a |
---|---|
1 var vows = require('vows') | |
2 , request = require('request') | |
3 , assert = require('assert') | |
4 , static = require('../../lib/node-static'); | |
5 | |
6 var fileServer = new static.Server(__dirname + '/../fixtures'); | |
7 var suite = vows.describe('node-static'); | |
8 var TEST_PORT = 8080; | |
9 var TEST_SERVER = 'http://localhost:' + TEST_PORT; | |
10 var version = static.version.join('.'); | |
11 var server; | |
12 var callback; | |
13 | |
14 headers = { | |
15 'requesting headers': { | |
16 topic : function(){ | |
17 request.head(TEST_SERVER + '/index.html', this.callback); | |
18 } | |
19 } | |
20 } | |
21 headers['requesting headers']['should respond with node-static/' + version] = function(error, response, body){ | |
22 assert.equal(response.headers['server'], 'node-static/' + version); | |
23 } | |
24 | |
25 suite.addBatch({ | |
26 'once an http server is listening with a callback': { | |
27 topic: function () { | |
28 server = require('http').createServer(function (request, response) { | |
29 fileServer.serve(request, response, function(err, result) { | |
30 if (callback) | |
31 callback(request, response, err, result); | |
32 else | |
33 request.end(); | |
34 }); | |
35 }).listen(TEST_PORT, this.callback) | |
36 }, | |
37 'should be listening' : function(){ | |
38 /* This test is necessary to ensure the topic execution. | |
39 * A topic without tests will be not executed */ | |
40 assert.isTrue(true); | |
41 } | |
42 }, | |
43 }).addBatch({ | |
44 'streaming a 404 page': { | |
45 topic: function(){ | |
46 callback = function(request, response, err, result) { | |
47 if (err) { | |
48 response.writeHead(err.status, err.headers); | |
49 setTimeout(function() { | |
50 response.end('Custom 404 Stream.') | |
51 }, 100); | |
52 } | |
53 } | |
54 request.get(TEST_SERVER + '/not-found', this.callback); | |
55 }, | |
56 'should respond with 404' : function(error, response, body){ | |
57 assert.equal(response.statusCode, 404); | |
58 }, | |
59 'should respond with the streamed content': function(error, response, body){ | |
60 callback = null; | |
61 assert.equal(body, 'Custom 404 Stream.'); | |
62 } | |
63 } | |
64 }).addBatch({ | |
65 'once an http server is listening without a callback': { | |
66 topic: function () { | |
67 server.close(); | |
68 server = require('http').createServer(function (request, response) { | |
69 fileServer.serve(request, response); | |
70 }).listen(TEST_PORT, this.callback) | |
71 }, | |
72 'should be listening' : function(){ | |
73 /* This test is necessary to ensure the topic execution. | |
74 * A topic without tests will be not executed */ | |
75 assert.isTrue(true); | |
76 } | |
77 } | |
78 }).addBatch({ | |
79 'requesting a file not found': { | |
80 topic : function(){ | |
81 request.get(TEST_SERVER + '/not-found', this.callback); | |
82 }, | |
83 'should respond with 404' : function(error, response, body){ | |
84 assert.equal(response.statusCode, 404); | |
85 } | |
86 } | |
87 }) | |
88 .addBatch({ | |
89 'requesting a malformed URI': { | |
90 topic: function(){ | |
91 request.get(TEST_SERVER + '/a%AFc', this.callback); | |
92 }, | |
93 'should respond with 400': function(error, response, body){ | |
94 assert.equal(response.statusCode, 400); | |
95 } | |
96 } | |
97 }) | |
98 .addBatch({ | |
99 'serving hello.txt': { | |
100 topic : function(){ | |
101 request.get(TEST_SERVER + '/hello.txt', this.callback); | |
102 }, | |
103 'should respond with 200' : function(error, response, body){ | |
104 assert.equal(response.statusCode, 200); | |
105 }, | |
106 'should respond with text/plain': function(error, response, body){ | |
107 assert.equal(response.headers['content-type'], 'text/plain'); | |
108 }, | |
109 'should respond with hello world': function(error, response, body){ | |
110 assert.equal(body, 'hello world'); | |
111 } | |
112 } | |
113 }).addBatch({ | |
114 'serving directory index': { | |
115 topic : function(){ | |
116 request.get(TEST_SERVER, this.callback); | |
117 }, | |
118 'should respond with 200' : function(error, response, body){ | |
119 assert.equal(response.statusCode, 200); | |
120 }, | |
121 'should respond with text/html': function(error, response, body){ | |
122 assert.equal(response.headers['content-type'], 'text/html'); | |
123 } | |
124 } | |
125 }).addBatch({ | |
126 'serving index.html from the cache': { | |
127 topic : function(){ | |
128 request.get(TEST_SERVER + '/index.html', this.callback); | |
129 }, | |
130 'should respond with 200' : function(error, response, body){ | |
131 assert.equal(response.statusCode, 200); | |
132 }, | |
133 'should respond with text/html': function(error, response, body){ | |
134 assert.equal(response.headers['content-type'], 'text/html'); | |
135 } | |
136 } | |
137 }).addBatch({ | |
138 'requesting with If-None-Match': { | |
139 topic : function(){ | |
140 var _this = this; | |
141 request.get(TEST_SERVER + '/index.html', function(error, response, body){ | |
142 request({ | |
143 method: 'GET', | |
144 uri: TEST_SERVER + '/index.html', | |
145 headers: {'if-none-match': response.headers['etag']} | |
146 }, | |
147 _this.callback); | |
148 }); | |
149 }, | |
150 'should respond with 304' : function(error, response, body){ | |
151 assert.equal(response.statusCode, 304); | |
152 } | |
153 }, | |
154 'requesting with If-None-Match and If-Modified-Since': { | |
155 topic : function(){ | |
156 var _this = this; | |
157 request.get(TEST_SERVER + '/index.html', function(error, response, body){ | |
158 var modified = Date.parse(response.headers['last-modified']); | |
159 var oneDayLater = new Date(modified + (24 * 60 * 60 * 1000)).toUTCString(); | |
160 var nonMatchingEtag = '1111222233334444'; | |
161 request({ | |
162 method: 'GET', | |
163 uri: TEST_SERVER + '/index.html', | |
164 headers: { | |
165 'if-none-match': nonMatchingEtag, | |
166 'if-modified-since': oneDayLater | |
167 } | |
168 }, | |
169 _this.callback); | |
170 }); | |
171 }, | |
172 'should respond with a 200': function(error, response, body){ | |
173 assert.equal(response.statusCode, 200); | |
174 } | |
175 } | |
176 }) | |
177 .addBatch({ | |
178 'requesting POST': { | |
179 topic : function(){ | |
180 request.post(TEST_SERVER + '/index.html', this.callback); | |
181 }, | |
182 'should respond with 200' : function(error, response, body){ | |
183 assert.equal(response.statusCode, 200); | |
184 }, | |
185 'should not be empty' : function(error, response, body){ | |
186 assert.isNotEmpty(body); | |
187 } | |
188 } | |
189 }) | |
190 .addBatch({ | |
191 'requesting HEAD': { | |
192 topic : function(){ | |
193 request.head(TEST_SERVER + '/index.html', this.callback); | |
194 }, | |
195 'should respond with 200' : function(error, response, body){ | |
196 assert.equal(response.statusCode, 200); | |
197 }, | |
198 'head must has no body' : function(error, response, body){ | |
199 assert.isEmpty(body); | |
200 } | |
201 } | |
202 }) | |
203 .addBatch(headers) | |
204 .addBatch({ | |
205 'addings custom mime types': { | |
206 topic : function(){ | |
207 static.mime.define({'application/font-woff': ['woff']}); | |
208 this.callback(); | |
209 }, | |
210 'should add woff' : function(error, response, body){ | |
211 assert.equal(static.mime.lookup('woff'), 'application/font-woff'); | |
212 } | |
213 } | |
214 }) | |
215 .addBatch({ | |
216 'serving subdirectory index': { | |
217 topic : function(){ | |
218 request.get(TEST_SERVER + '/there/', this.callback); // with trailing slash | |
219 }, | |
220 'should respond with 200' : function(error, response, body){ | |
221 assert.equal(response.statusCode, 200); | |
222 }, | |
223 'should respond with text/html': function(error, response, body){ | |
224 assert.equal(response.headers['content-type'], 'text/html'); | |
225 } | |
226 } | |
227 }) | |
228 .addBatch({ | |
229 'redirecting to subdirectory index': { | |
230 topic : function(){ | |
231 request.get({ url: TEST_SERVER + '/there', followRedirect: false }, this.callback); // without trailing slash | |
232 }, | |
233 'should respond with 301' : function(error, response, body){ | |
234 assert.equal(response.statusCode, 301); | |
235 }, | |
236 'should respond with location header': function(error, response, body){ | |
237 assert.equal(response.headers['location'], '/there/'); // now with trailing slash | |
238 }, | |
239 'should respond with empty string body' : function(error, response, body){ | |
240 assert.equal(body, ''); | |
241 } | |
242 } | |
243 }) | |
244 .addBatch({ | |
245 'requesting a subdirectory (with trailing slash) not found': { | |
246 topic : function(){ | |
247 request.get(TEST_SERVER + '/notthere/', this.callback); // with trailing slash | |
248 }, | |
249 'should respond with 404' : function(error, response, body){ | |
250 assert.equal(response.statusCode, 404); | |
251 } | |
252 } | |
253 }) | |
254 .addBatch({ | |
255 'requesting a subdirectory (without trailing slash) not found': { | |
256 topic : function(){ | |
257 request.get({ url: TEST_SERVER + '/notthere', followRedirect: false }, this.callback); // without trailing slash | |
258 }, | |
259 'should respond with 404' : function(error, response, body){ | |
260 assert.equal(response.statusCode, 404); | |
261 } | |
262 } | |
263 }).export(module); | |
264 |