summaryrefslogtreecommitdiffstats
path: root/testing/xpcshell/node-ws/test/autobahn.js
blob: 51532fc52e8f15221a4f1bad389636d32d092317 (plain)
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
'use strict';

const WebSocket = require('../');

let currentTest = 1;
let testCount;

function nextTest() {
  let ws;

  if (currentTest > testCount) {
    ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
    return;
  }

  console.log(`Running test case ${currentTest}/${testCount}`);

  ws = new WebSocket(
    `ws://localhost:9001/runCase?case=${currentTest}&agent=ws`
  );
  ws.on('message', (data, isBinary) => {
    ws.send(data, { binary: isBinary });
  });
  ws.on('close', () => {
    currentTest++;
    process.nextTick(nextTest);
  });
  ws.on('error', (e) => console.error(e));
}

const ws = new WebSocket('ws://localhost:9001/getCaseCount');
ws.on('message', (data) => {
  testCount = parseInt(data);
});
ws.on('close', () => {
  if (testCount > 0) {
    nextTest();
  }
});