-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathclient.test.ts
More file actions
49 lines (39 loc) · 1.54 KB
/
client.test.ts
File metadata and controls
49 lines (39 loc) · 1.54 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
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it, afterEach} from 'node:test';
import {startDaemon, stopDaemon} from '../../src/daemon/client.js';
import {isDaemonRunning} from '../../src/daemon/utils.js';
describe('daemon client', () => {
afterEach(async () => {
if (isDaemonRunning()) {
await stopDaemon();
// Wait a bit for the daemon to fully terminate and clean up its files.
await new Promise(resolve => setTimeout(resolve, 1000));
}
});
it('should start and stop daemon', async () => {
assert.ok(!isDaemonRunning(), 'Daemon should not be running initially');
await startDaemon();
assert.ok(isDaemonRunning(), 'Daemon should be running after start');
await stopDaemon();
await new Promise(resolve => setTimeout(resolve, 1000));
assert.ok(!isDaemonRunning(), 'Daemon should not be running after stop');
});
it('should handle starting daemon when already running', async () => {
await startDaemon();
assert.ok(isDaemonRunning(), 'Daemon should be running');
// Starting again should be a no-op
await startDaemon();
assert.ok(isDaemonRunning(), 'Daemon should still be running');
});
it('should handle stopping daemon when not running', async () => {
assert.ok(!isDaemonRunning(), 'Daemon should not be running initially');
// Stopping when not running should be a no-op
await stopDaemon();
assert.ok(!isDaemonRunning(), 'Daemon should still not be running');
});
});