-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathchrome-devtools.test.ts
More file actions
116 lines (96 loc) · 3 KB
/
chrome-devtools.test.ts
File metadata and controls
116 lines (96 loc) · 3 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {spawnSync} from 'node:child_process';
import path from 'node:path';
import {describe, it, afterEach, beforeEach} from 'node:test';
const CLI_PATH = path.resolve('build/src/bin/chrome-devtools.js');
describe('chrome-devtools', () => {
const START_ARGS = ['--headless', '--isolated'];
function assertDaemonIsNotRunning() {
const result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is not running.\n',
);
}
function assertDaemonIsRunning() {
const result = spawnSync('node', [CLI_PATH, 'status']);
assert.ok(
result.stdout
.toString()
.startsWith('chrome-devtools-mcp daemon is running.\n'),
'chrome-devtools-mcp daemon is not running',
);
}
beforeEach(() => {
spawnSync('node', [CLI_PATH, 'stop']);
assertDaemonIsNotRunning();
});
afterEach(() => {
spawnSync('node', [CLI_PATH, 'stop']);
assertDaemonIsNotRunning();
});
it('reports daemon status correctly', () => {
assertDaemonIsNotRunning();
const startResult = spawnSync('node', [CLI_PATH, 'start', ...START_ARGS]);
assert.strictEqual(
startResult.status,
0,
`start command failed: ${startResult.stderr.toString()}`,
);
assertDaemonIsRunning();
});
it('can start and stop the daemon', () => {
assertDaemonIsNotRunning();
const startResult = spawnSync('node', [CLI_PATH, 'start', ...START_ARGS]);
assert.strictEqual(
startResult.status,
0,
`start command failed: ${startResult.stderr.toString()}`,
);
assertDaemonIsRunning();
const stopResult = spawnSync('node', [CLI_PATH, 'stop']);
assert.strictEqual(
stopResult.status,
0,
`stop command failed: ${stopResult.stderr.toString()}`,
);
assertDaemonIsNotRunning();
});
it('can invoke list_pages', async () => {
assertDaemonIsNotRunning();
const startResult = spawnSync('node', [CLI_PATH, 'start', ...START_ARGS]);
assert.strictEqual(
startResult.status,
0,
`start command failed: ${startResult.stderr.toString()}`,
);
const listPagesResult = spawnSync('node', [CLI_PATH, 'list_pages']);
assert.strictEqual(
listPagesResult.status,
0,
`list_pages command failed: ${listPagesResult.stderr.toString()}`,
);
assert(
listPagesResult.stdout.toString().includes('about:blank'),
'list_pages output is unexpected',
);
assertDaemonIsRunning();
});
it('forwards disclaimers to stderr on start', () => {
const result = spawnSync('node', [CLI_PATH, 'start', ...START_ARGS]);
assert.strictEqual(
result.status,
0,
`start command failed: ${result.stderr.toString()}`,
);
assert(
result.stderr.toString().includes('chrome-devtools-mcp exposes content'),
'Disclaimer not found in stderr on start',
);
});
});