Skip to content

Commit b032c02

Browse files
committed
chore: fix arg forwarding
1 parent bedfd5d commit b032c02

2 files changed

Lines changed: 130 additions & 2 deletions

File tree

src/bin/chrome-devtools.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ const y = yargs(argv)
4444
y.command(
4545
'start',
4646
'Start or restart chrome-devtools-mcp',
47-
y => y.help(false), // Disable help for start command to avoid parsing issues with passed args
47+
y =>
48+
y
49+
.help(false) // Disable help for start command to avoid parsing issues with passed args.
50+
.example(
51+
'$0 start --port 8080 --url http://localhost:8080',
52+
'Start the server on port 8080 with a specific URL',
53+
)
54+
.strict(false), // Don't validate arguments for start, as they are passed through to the daemon.
4855
async () => {
4956
if (isDaemonRunning()) {
5057
await stopDaemon();
@@ -54,7 +61,7 @@ y.command(
5461
const args = startIndex !== -1 ? process.argv.slice(startIndex + 1) : [];
5562
await startDaemon([...args, ...defaultArgs]);
5663
},
57-
);
64+
).strict(); // Re-enable strict validation for other commands; this is applied to the yargs instance itself
5865

5966
y.command('status', 'Checks if chrome-devtools-mcp is running', async () => {
6067
if (isDaemonRunning()) {

tests/e2e/chrome-devtools.test.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import assert from 'node:assert';
8+
import {spawnSync} from 'node:child_process';
9+
import path from 'node:path';
10+
import {describe, it, afterEach, beforeEach} from 'node:test';
11+
12+
const CLI_PATH = path.resolve('build/src/bin/chrome-devtools.js');
13+
14+
describe('chrome-devtools', () => {
15+
const START_ARGS = ['--headless', '--isolated'];
16+
17+
beforeEach(() => {
18+
spawnSync(CLI_PATH, ['stop']);
19+
});
20+
21+
afterEach(() => {
22+
spawnSync(CLI_PATH, ['stop']);
23+
});
24+
25+
it('reports daemon status correctly', () => {
26+
let result = spawnSync(CLI_PATH, ['status']);
27+
assert.strictEqual(
28+
result.stdout.toString(),
29+
'chrome-devtools-mcp daemon is not running\n',
30+
);
31+
32+
spawnSync(CLI_PATH, ['start', ...START_ARGS]);
33+
34+
result = spawnSync(CLI_PATH, ['status']);
35+
assert.strictEqual(
36+
result.stdout.toString(),
37+
'chrome-devtools-mcp daemon is running.\n',
38+
);
39+
});
40+
41+
it('can start and stop the daemon', () => {
42+
let result = spawnSync(CLI_PATH, ['status']);
43+
assert.strictEqual(
44+
result.stdout.toString(),
45+
'chrome-devtools-mcp daemon is not running\n',
46+
);
47+
48+
const startResult = spawnSync(CLI_PATH, ['start', ...START_ARGS]);
49+
assert.strictEqual(
50+
startResult.status,
51+
0,
52+
`start command failed: ${startResult.stderr.toString()}`,
53+
);
54+
55+
result = spawnSync(CLI_PATH, ['status']);
56+
assert.strictEqual(
57+
result.stdout.toString(),
58+
'chrome-devtools-mcp daemon is running.\n',
59+
);
60+
61+
const stopResult = spawnSync(CLI_PATH, ['stop']);
62+
assert.strictEqual(
63+
stopResult.status,
64+
0,
65+
`stop command failed: ${stopResult.stderr.toString()}`,
66+
);
67+
68+
result = spawnSync(CLI_PATH, ['status']);
69+
assert.strictEqual(
70+
result.stdout.toString(),
71+
'chrome-devtools-mcp daemon is not running\n',
72+
);
73+
});
74+
75+
it('can invoke list_pages', async () => {
76+
// Daemon should not be running.
77+
let result = spawnSync(CLI_PATH, ['status']);
78+
assert.strictEqual(
79+
result.stdout.toString(),
80+
'chrome-devtools-mcp daemon is not running\n',
81+
);
82+
83+
const startResult = spawnSync(CLI_PATH, ['start', ...START_ARGS]);
84+
assert.strictEqual(
85+
startResult.status,
86+
0,
87+
`start command failed: ${startResult.stderr.toString()}`,
88+
);
89+
90+
const listPagesResult = spawnSync(CLI_PATH, ['list_pages']);
91+
assert.strictEqual(
92+
listPagesResult.status,
93+
0,
94+
`list_pages command failed: ${listPagesResult.stderr.toString()}`,
95+
);
96+
assert(
97+
listPagesResult.stdout.toString().includes('about:blank'),
98+
'list_pages output is unexpected',
99+
);
100+
101+
// Daemon should now be running.
102+
result = spawnSync(CLI_PATH, ['status']);
103+
assert.strictEqual(
104+
result.stdout.toString(),
105+
'chrome-devtools-mcp daemon is running.\n',
106+
);
107+
});
108+
109+
it('forwards disclaimers to stderr on start', () => {
110+
const result = spawnSync(CLI_PATH, ['start', ...START_ARGS]);
111+
assert.strictEqual(
112+
result.status,
113+
0,
114+
`start command failed: ${result.stderr.toString()}`,
115+
);
116+
assert(
117+
result.stderr.toString().includes('chrome-devtools-mcp exposes content'),
118+
'Disclaimer not found in stderr on start',
119+
);
120+
});
121+
});

0 commit comments

Comments
 (0)