diff --git a/src/index.ts b/src/index.ts index f20c4659..19f07d25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,13 @@ if (major === 22 && minor < 12) { process.exit(1); } +if (major === 21) { + console.error( + `ERROR: \`chrome-devtools-mcp\` does not support Node ${process.version}. Please upgrade to Node 20.19.0 LTS or a newer LTS.`, + ); + process.exit(1); +} + if (major < 20) { console.error( `ERROR: \`chrome-devtools-mcp\` does not support Node ${process.version}. Please upgrade to Node 20.19.0 LTS or a newer LTS.`, diff --git a/tests/version.test.ts b/tests/version.test.ts new file mode 100644 index 00000000..9cfe9e9c --- /dev/null +++ b/tests/version.test.ts @@ -0,0 +1,38 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import {describe, it, afterEach} from 'node:test'; +import assert from 'node:assert'; +import sinon from 'sinon'; + +describe('version check', () => { + afterEach(() => { + sinon.restore(); + }); + + it('should exit if node version is not supported', async (t) => { + const processExit = sinon.stub(process, 'exit'); + const consoleError = sinon.stub(console, 'error'); + + await t.test('v21.0.0', async () => { + Object.defineProperty(process, 'version', { + value: 'v21.0.0', + writable: true, + configurable: true, + }); + + // We need to dynamically import the index with a random query string + // to bypass the module cache and re-evaluate the version check. + await import(`../src/index.js?r=${Math.random()}`); + + assert.strictEqual(processExit.callCount, 1); + assert.strictEqual(processExit.getCall(0).args[0], 1); + assert.deepStrictEqual(consoleError.getCall(0).args, [ + 'ERROR: `chrome-devtools-mcp` does not support Node v21.0.0. Please upgrade to Node 20.19.0 LTS or a newer LTS.', + ]); + }); + }); +}); \ No newline at end of file