runner.js
1.5 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
require('jsclass')
var WebSocket = require('../lib/faye/websocket'),
fs = require('fs'),
http = require('http'),
https = require('https')
JS.ENV.EchoServer = function() {}
EchoServer.prototype.listen = function(port, ssl) {
var server = ssl
? https.createServer({
key: fs.readFileSync(__dirname + '/server.key'),
cert: fs.readFileSync(__dirname + '/server.crt')
})
: http.createServer()
server.addListener('upgrade', function(request, socket, head) {
var ws = new WebSocket(request, socket, head, ["echo"])
ws.onmessage = function(event) {
ws.send(event.data)
}
})
this._httpServer = server
server.listen(port)
}
EchoServer.prototype.stop = function(callback, scope) {
this._httpServer.addListener('close', function() {
if (callback) callback.call(scope);
});
this._httpServer.close();
}
JS.Packages(function() { with(this) {
autoload(/.*Spec/, {from: 'spec/faye/websocket'})
}})
JS.require('JS.Test', function() {
JS.Test.Unit.Assertions.define("assertBufferEqual", function(array, buffer) {
this.assertEqual(array.length, buffer.length);
var ary = [], n = buffer.length;
while (n--) ary[n] = buffer[n];
this.assertEqual(array, ary);
})
JS.require( 'ClientSpec',
'Draft75ParserSpec',
'Draft76ParserSpec',
'HybiParserSpec',
JS.Test.method('autorun'))
})