Skip to content

Commit

Permalink
test: 优化test流程 (#21)
Browse files Browse the repository at this point in the history

* test: 优化test测试
  • Loading branch information
yuhao423 authored Jun 27, 2024
1 parent 6ef49b9 commit 30af538
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
7 changes: 2 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
const weServer = require('./websocketServer')

weServer.on('connection',()=>{
console.error('websocket-server connected');
})
const wsServer = require('./websocketServer')
const wsClient = require('./websocketClient')
25 changes: 25 additions & 0 deletions test/websocketClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

const ws = require('ws')

const wsClient = new ws.WebSocket('http://localhost:8000')

wsClient.on('error', console.error);

wsClient.on('open', function open() {
console.error('open');
const array = new Float32Array(5);

for (var i = 0; i < array.length; ++i) {
array[i] = i / 2;
}

wsClient.send('yuyu',()=>{
console.error('我发送了');
});
});

wsClient.on('message',(message)=>{
console.error('received: %s', message);
console.error(message,'message');
})
module.exports = wsClient
15 changes: 13 additions & 2 deletions test/websocketServer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@

const ws = require('ws')

const weServer = new ws.WebSocketServer({port:8000})
const wsServer = new ws.WebSocketServer({port:8000})
wsServer.on('connection',(ws)=>{
ws.on('error', console.error);

ws.on('message', function message(data) {
console.error('received: %s', data);
});

ws.send('something');
})

module.exports = wsServer


module.exports = weServer

0 comments on commit 30af538

Please sign in to comment.