autobahn.js (806B)
1 'use strict'; 2 3 const WebSocket = require('../'); 4 5 let currentTest = 1; 6 let testCount; 7 8 function nextTest() { 9 let ws; 10 11 if (currentTest > testCount) { 12 ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws'); 13 return; 14 } 15 16 console.log(`Running test case ${currentTest}/${testCount}`); 17 18 ws = new WebSocket( 19 `ws://localhost:9001/runCase?case=${currentTest}&agent=ws` 20 ); 21 ws.on('message', (data, isBinary) => { 22 ws.send(data, { binary: isBinary }); 23 }); 24 ws.on('close', () => { 25 currentTest++; 26 process.nextTick(nextTest); 27 }); 28 ws.on('error', (e) => console.error(e)); 29 } 30 31 const ws = new WebSocket('ws://localhost:9001/getCaseCount'); 32 ws.on('message', (data) => { 33 testCount = parseInt(data); 34 }); 35 ws.on('close', () => { 36 if (testCount > 0) { 37 nextTest(); 38 } 39 });