-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathdaemon.test.ts
More file actions
62 lines (55 loc) · 1.64 KB
/
daemon.test.ts
File metadata and controls
62 lines (55 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {spawn} from 'node:child_process';
import net from 'node:net';
import path from 'node:path';
import {describe, it} from 'node:test';
import {getSocketPath} from '../../src/daemon/utils.js';
const DAEMON_SCRIPT = path.join(
import.meta.dirname,
'..',
'..',
'src',
'daemon',
'daemon.js',
);
describe('Daemon', () => {
it('should terminate chrome instance when transport is closed', async () => {
const daemonProcess = spawn(process.execPath, [DAEMON_SCRIPT], {
env: {
...process.env,
},
stdio: ['ignore', 'pipe', 'pipe'],
});
const socketPath = getSocketPath();
// Wait for daemon to be ready
await new Promise<void>((resolve, reject) => {
const onData = (data: Buffer) => {
const output = data.toString();
// Wait for MCP client to connect
if (output.includes('MCP client connected')) {
daemonProcess.stdout.off('data', onData);
resolve();
}
};
daemonProcess.stdout.on('data', onData);
daemonProcess.stderr.on('data', data => {
console.log('err', data.toString('utf8'));
});
daemonProcess.on('error', reject);
daemonProcess.on('exit', (code: number) => {
if (code !== 0 && code !== null) {
reject(new Error(`Daemon exited with code ${code}`));
}
});
});
const socket = net.createConnection(socketPath);
await new Promise<void>(resolve => socket.on('connect', resolve));
daemonProcess.kill();
assert.ok(daemonProcess.killed);
});
});