Skip to content

Commit 3a22ab0

Browse files
committed
Adapted htmlfile tests.
1 parent 13e9727 commit 3a22ab0

File tree

1 file changed

+94
-45
lines changed

1 file changed

+94
-45
lines changed

test/transports.htmlfile.test.js

Lines changed: 94 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ HTMLFile.prototype.data = function (path, opts, fn) {
5151

5252
return this.request(path, opts, function (res) {
5353
var buf = ''
54+
, messages = 0
5455
, state = 0;
5556

5657
res.on('data', function (chunk) {
@@ -79,7 +80,7 @@ HTMLFile.prototype.data = function (path, opts, fn) {
7980
var data = buf.slice(0, buf.indexOf(foot))
8081
, obj = JSON.parse(data);
8182

82-
fn(obj === '' ? obj : parser.decodePayload(obj));
83+
fn(obj === '' ? obj : parser.decodePayload(obj), ++messages);
8384

8485
buf = buf.substr(data.length + foot.length);
8586
state = 1;
@@ -134,10 +135,19 @@ module.exports = {
134135
});
135136

136137
cl.handshake(function (sid) {
137-
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs) {
138-
msgs.should.have.length(1);
139-
msgs[0].type.should.eql('heartbeat');
140-
beat = true;
138+
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs, i) {
139+
switch (i) {
140+
case 1:
141+
msgs.should.have.length(1);
142+
msgs[0].type.should.eql('connect');
143+
msgs[0].endpoint.should.eql('');
144+
break;
145+
146+
case 2:
147+
msgs.should.have.length(1);
148+
msgs[0].type.should.eql('heartbeat');
149+
beat = true;
150+
};
141151
});
142152
});
143153
},
@@ -166,13 +176,25 @@ module.exports = {
166176
});
167177

168178
cl.handshake(function (sid) {
169-
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs) {
170-
heartbeats++;
179+
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs, i) {
180+
switch (i) {
181+
case 1:
182+
msgs.should.have.length(1);
183+
msgs[0].type.should.eql('connect');
184+
msgs[0].endpoint.should.eql('');
185+
break;
186+
187+
default:
188+
msgs.should.have.length(1);
189+
msgs[0].type.should.eql('heartbeat');
190+
191+
heartbeats++;
171192

172-
if (heartbeats == 1) {
173-
cl.post('/socket.io/{protocol}/htmlfile/' + sid, parser.encodePacket({
174-
type: 'heartbeat'
175-
}));
193+
if (heartbeats == 1) {
194+
cl.post('/socket.io/{protocol}/htmlfile/' + sid, parser.encodePacket({
195+
type: 'heartbeat'
196+
}));
197+
}
176198
}
177199
});
178200
});
@@ -215,9 +237,9 @@ module.exports = {
215237

216238
setTimeout(function () {
217239
cl.end();
218-
}, 10);
219-
}, 10);
220-
}, 10);
240+
}, 20);
241+
}, 20);
242+
}, 20);
221243
});
222244
},
223245

@@ -259,9 +281,9 @@ module.exports = {
259281

260282
setTimeout(function () {
261283
cl.end();
262-
}, 10);
263-
}, 10);
264-
}, 10);
284+
}, 20);
285+
}, 20);
286+
}, 20);
265287
});
266288
},
267289

@@ -303,9 +325,9 @@ module.exports = {
303325

304326
setTimeout(function () {
305327
cl.end();
306-
}, 10);
307-
}, 10);
308-
}, 10);
328+
}, 20);
329+
}, 20);
330+
}, 20);
309331
});
310332
},
311333

@@ -329,14 +351,23 @@ module.exports = {
329351
});
330352

331353
cl.handshake(function (sid) {
332-
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs) {
333-
msgs.should.have.length(1);
334-
msgs[0].should.eql({
335-
type: 'message'
336-
, data: 'woot'
337-
, endpoint: ''
338-
});
339-
cl.end();
354+
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs, i) {
355+
switch (i) {
356+
case 1:
357+
msgs.should.have.length(1);
358+
msgs[0].type.should.eql('connect');
359+
msgs[0].endpoint.should.eql('');
360+
break;
361+
362+
case 2:
363+
msgs.should.have.length(1);
364+
msgs[0].should.eql({
365+
type: 'message'
366+
, data: 'woot'
367+
, endpoint: ''
368+
});
369+
cl.end();
370+
}
340371
});
341372
});
342373
},
@@ -361,14 +392,23 @@ module.exports = {
361392
});
362393

363394
cl.handshake(function (sid) {
364-
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs) {
365-
msgs.should.have.length(1);
366-
msgs[0].should.eql({
367-
type: 'json'
368-
, data: ['woot']
369-
, endpoint: ''
370-
});
371-
cl.end();
395+
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs, i) {
396+
switch (i) {
397+
case 1:
398+
msgs.should.have.length(1);
399+
msgs[0].type.should.eql('connect');
400+
msgs[0].endpoint.should.eql('');
401+
break;
402+
403+
case 2:
404+
msgs.should.have.length(1);
405+
msgs[0].should.eql({
406+
type: 'json'
407+
, data: ['woot']
408+
, endpoint: ''
409+
});
410+
cl.end();
411+
}
372412
});
373413
});
374414
},
@@ -393,15 +433,24 @@ module.exports = {
393433
});
394434

395435
cl.handshake(function (sid) {
396-
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs) {
397-
msgs.should.have.length(1);
398-
msgs[0].should.eql({
399-
type: 'event'
400-
, name: 'aaa'
401-
, endpoint: ''
402-
, args: []
403-
});
404-
cl.end();
436+
cl.data('/socket.io/{protocol}/htmlfile/' + sid, function (msgs, i) {
437+
switch (i) {
438+
case 1:
439+
msgs.should.have.length(1);
440+
msgs[0].type.should.eql('connect');
441+
msgs[0].endpoint.should.eql('');
442+
break;
443+
444+
case 2:
445+
msgs.should.have.length(1);
446+
msgs[0].should.eql({
447+
type: 'event'
448+
, name: 'aaa'
449+
, endpoint: ''
450+
, args: []
451+
});
452+
cl.end();
453+
}
405454
});
406455
});
407456
}

0 commit comments

Comments
 (0)