Skip to content

Commit fb8cab4

Browse files
feat: Add Node.js v21 version check
The entrypoint script `src/index.ts` was missing a check for Node.js version 21. Although the `package.json` `engines` field specifies supported versions, this check provides a more user-friendly error message. This change adds a condition to exit with an error if the major version of Node.js is 21, consistent with other version checks in the file. A new test file, `tests/version.test.ts`, is added to verify this behavior in isolation, ensuring that the script exits as expected when an unsupported version is used.
1 parent 9b4cd8e commit fb8cab4

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ if (major === 22 && minor < 12) {
2424
process.exit(1);
2525
}
2626

27+
if (major === 21) {
28+
console.error(
29+
`ERROR: \`chrome-devtools-mcp\` does not support Node ${process.version}. Please upgrade to Node 20.19.0 LTS or a newer LTS.`,
30+
);
31+
process.exit(1);
32+
}
33+
2734
if (major < 20) {
2835
console.error(
2936
`ERROR: \`chrome-devtools-mcp\` does not support Node ${process.version}. Please upgrade to Node 20.19.0 LTS or a newer LTS.`,

tests/version.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import {describe, it, afterEach} from 'node:test';
8+
import assert from 'node:assert';
9+
import sinon from 'sinon';
10+
11+
describe('version check', () => {
12+
afterEach(() => {
13+
sinon.restore();
14+
});
15+
16+
it('should exit if node version is not supported', async (t) => {
17+
const processExit = sinon.stub(process, 'exit');
18+
const consoleError = sinon.stub(console, 'error');
19+
20+
await t.test('v21.0.0', async () => {
21+
Object.defineProperty(process, 'version', {
22+
value: 'v21.0.0',
23+
writable: true,
24+
configurable: true,
25+
});
26+
27+
// We need to dynamically import the index with a random query string
28+
// to bypass the module cache and re-evaluate the version check.
29+
await import(`../src/index.js?r=${Math.random()}`);
30+
31+
assert.strictEqual(processExit.callCount, 1);
32+
assert.strictEqual(processExit.getCall(0).args[0], 1);
33+
assert.deepStrictEqual(consoleError.getCall(0).args, [
34+
'ERROR: `chrome-devtools-mcp` does not support Node v21.0.0. Please upgrade to Node 20.19.0 LTS or a newer LTS.',
35+
]);
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)