Skip to content

Commit 946ec5a

Browse files
committed
add test
1 parent 16a143c commit 946ec5a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { spawn } = require('node:child_process');
4+
const assert = require('node:assert');
5+
6+
(async () => {
7+
const child = spawn(
8+
process.execPath,
9+
['--inspect-wait=0', '-e', "console.log('test');"],
10+
{}
11+
);
12+
13+
const url = await new Promise((resolve) => {
14+
child.stderr.on('data', (data) => {
15+
const msg = data.toString();
16+
const match = msg.match(/ws:\/\/127\.0\.0\.1:(\d+)\/([a-f0-9-]+)/);
17+
if (match) {
18+
child.stderr.removeAllListeners('data');
19+
return resolve(match[0]);
20+
}
21+
});
22+
});
23+
24+
child.once('exit', (_, signal) => {
25+
assert.strictEqual(signal, 'SIGTERM');
26+
});
27+
28+
const socket = new WebSocket(url);
29+
30+
socket.addEventListener('open', common.mustCall(() => {
31+
socket.send('This is not a valid protocol message');
32+
}));
33+
34+
socket.addEventListener('message', common.mustCall((event) => {
35+
assert.ok(Object.keys(JSON.parse(event.data)).includes('error'));
36+
socket.close();
37+
child.kill();
38+
}));
39+
})().then(common.mustCall());

0 commit comments

Comments
 (0)