mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-02 08:58:32 +00:00
feat(websockets): add websocket tests
This commit is contained in:
@@ -150,7 +150,7 @@ const WsQueryUrl = ({ item, collection, handleRun }) => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="cursor-pointer" onClick={handleRunClick}>
|
||||
<div data-testid="run-button" className="cursor-pointer" onClick={handleRunClick}>
|
||||
<IconArrowRight color={theme.requestTabPanel.url.icon} strokeWidth={1.5} size={22} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"lodash": "^4.17.21",
|
||||
"multer": "^1.4.5-lts.1"
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"ws": "^8.18.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ const echoRouter = require('./echo');
|
||||
const xmlParser = require('./utils/xmlParser');
|
||||
const multipartRouter = require('./multipart');
|
||||
const redirectRouter = require('./redirect');
|
||||
const wsRouter = require('./ws');
|
||||
|
||||
const app = new express();
|
||||
const port = process.env.PORT || 8081;
|
||||
@@ -47,6 +48,10 @@ app.get('/redirect-to-ping', function (req, res) {
|
||||
return res.redirect('/ping');
|
||||
});
|
||||
|
||||
app.listen(port, function () {
|
||||
const server = require('http').createServer(app);
|
||||
|
||||
server.on('upgrade', wsRouter);
|
||||
|
||||
server.listen(port, function () {
|
||||
console.log(`Testbench started on port: ${port}`);
|
||||
});
|
||||
});
|
||||
40
packages/bruno-tests/src/ws/index.js
Normal file
40
packages/bruno-tests/src/ws/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const ws = require('ws');
|
||||
|
||||
const onSocketError = (err) => {
|
||||
console.error(err);
|
||||
};
|
||||
|
||||
const wss = new ws.Server({
|
||||
noServer: true
|
||||
});
|
||||
|
||||
wss.on('connection', function connection(ws, request) {
|
||||
|
||||
ws.on('message', function message(data) {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
data: JSON.parse(Buffer.from(data).toString()),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
const wsRouter = (request, socket, head) => {
|
||||
socket.on('error', onSocketError);
|
||||
|
||||
if (request.url !== '/ws') {
|
||||
socket.write('HTTP/1.1 404 Not Found\r\n\r\n');
|
||||
socket.destroy();
|
||||
|
||||
socket.removeListener('error', onSocketError);
|
||||
return;
|
||||
}
|
||||
|
||||
wss.handleUpgrade(request, socket, head, function done(ws) {
|
||||
wss.emit('connection', ws, request);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = wsRouter;
|
||||
Reference in New Issue
Block a user