Files
ws/test/autobahn.js
Luigi Pinca e173423c18 [major] Do not decode Buffers to strings
Avoid decoding text messages and close reasons to strings. Pass them as
`Buffer`s to the listeners of their respective events. Also, make
listeners of the `'message'` event take a boolean argument to speficy
whether or not the message is binary.

Refs: https://github.com/websockets/ws/issues/1878
Refs: https://github.com/websockets/ws/issues/1804
2021-07-14 21:26:04 +02:00

40 lines
806 B
JavaScript

'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();
}
});