-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathchrome-devtools.test.ts
More file actions
143 lines (122 loc) · 3.88 KB
/
chrome-devtools.test.ts
File metadata and controls
143 lines (122 loc) · 3.88 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* @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',
);
}
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()}`,
);
const result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is running.\n',
);
});
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()}`,
);
let result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is running.\n',
);
const stopResult = spawnSync('node', [CLI_PATH, 'stop']);
assert.strictEqual(
stopResult.status,
0,
`stop command failed: ${stopResult.stderr.toString()}`,
);
result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is not running.\n',
);
});
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',
);
// Daemon should now be running.
const result = spawnSync('node', [CLI_PATH, 'status']);
assert.strictEqual(
result.stdout.toString(),
'chrome-devtools-mcp daemon is running.\n',
);
});
it('can take screenshot', async () => {
const startResult = spawnSync('node', [CLI_PATH, 'start', ...START_ARGS]);
assert.strictEqual(
startResult.status,
0,
`start command failed: ${startResult.stderr.toString()}`,
);
const result = spawnSync('node', [CLI_PATH, 'take_screenshot']);
assert.strictEqual(
result.status,
0,
`take_screenshot command failed: ${result.stderr.toString()}`,
);
assert(
result.stdout.toString().includes('.png'),
'take_screenshot output is unexpected',
);
});
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',
);
});
});