comunicationLeap/node_modules/ws/test/autobahn.js
node_modules/ws/test/autobahn.jsRaw
1var WebSocket = require('../');
2var currentTest = 1;
3var lastTest = -1;
4var testCount = null;
5
6process.on('uncaughtException', function(err) {
7 console.log('Caught exception: ', err, err.stack);
8});
9
10process.on('SIGINT', function () {
11 try {
12 console.log('Updating reports and shutting down');
13 var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
14 ws.on('close', function() {
15 process.exit();
16 });
17 }
18 catch(e) {
19 process.exit();
20 }
21});
22
23function nextTest() {
24 if (currentTest > testCount || (lastTest != -1 && currentTest > lastTest)) {
25 console.log('Updating reports and shutting down');
26 var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
27 ws.on('close', function() {
28 process.exit();
29 });
30 return;
31 };
32 console.log('Running test case ' + currentTest + '/' + testCount);
33 var ws = new WebSocket('ws://localhost:9001/runCase?case=' + currentTest + '&agent=ws');
34 ws.on('message', function(data, flags) {
35 ws.send(flags.buffer, {binary: flags.binary === true, mask: true});
36 });
37 ws.on('close', function(data) {
38 currentTest += 1;
39 process.nextTick(nextTest);
40 });
41 ws.on('error', function(e) {});
42}
43
44var ws = new WebSocket('ws://localhost:9001/getCaseCount');
45ws.on('message', function(data, flags) {
46 testCount = parseInt(data);
47});
48ws.on('close', function() {
49 if (testCount > 0) {
50 nextTest();
51 }
52});