Skip to content

Commit f211372

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

2 files changed

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

0 commit comments

Comments
 (0)