豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,8 @@ jobs:
shell: bash
run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns

- name: Run tests (node20)
if: ${{ matrix.node == '20' }}
shell: bash
run: npm run test:node20

- name: Run tests
shell: bash
if: ${{ matrix.node != '20' }}
run: npm run test:no-build

# Gating job for branch protection.
Expand Down
7 changes: 4 additions & 3 deletions GEMINI.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Instructions

- use `npm run build` to run tsc and test build.
- use `npm run test` to run tests, run all tests to verify correctness.
- use only scripts from `package.json` to run commands.
- Use only scripts from `package.json` to run commands.
- Use `npm run build` to run tsc and test build.
- Use `npm run test` to build and run tests, run all tests to verify correctness.
- use `npm run test path-to-test.ts` to build and run a single test file, for example, `npm run test tests/McpContext.test.ts`.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
"docs:generate": "node --experimental-strip-types scripts/generate-docs.ts",
"start": "npm run build && node build/src/index.js",
"start-debug": "DEBUG=mcp:* DEBUG_COLORS=false npm run build && node build/src/index.js",
"test:node20": "node --import ./build/tests/setup.js --test-reporter spec --test-force-exit --test build/tests",
"test:no-build": "node --import ./build/tests/setup.js --no-warnings=ExperimentalWarning --experimental-print-required-tla --test-reporter spec --test-force-exit --test \"build/tests/**/*.test.js\"",
"test": "npm run build && npm run test:no-build",
"test:only": "npm run build && npm run test:only:no-build",
"test:only:no-build": "node --import ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-reporter spec --test-force-exit --test --test-only \"build/tests/**/*.test.js\"",
"test:update-snapshots": "npm run build && node --import ./build/tests/setup.js --no-warnings=ExperimentalWarning --test-force-exit --test --test-update-snapshots \"build/tests/**/*.test.js\"",
"test:no-build": "node scripts/test.mjs",
"test:only": "npm run build && node scripts/test.mjs --test-only",
"test:update-snapshots": "npm run build && node scripts/test.mjs --test-update-snapshots",
"prepare": "node --experimental-strip-types scripts/prepare.ts",
"verify-server-json-version": "node --experimental-strip-types scripts/verify-server-json-version.ts"
},
Expand Down
59 changes: 59 additions & 0 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

// Note: can be converted to ts file once node 20 support is dropped.
// Node 20 does not support --experimental-strip-types flag.

import {spawn} from 'node:child_process';
import path from 'node:path';
import process from 'node:process';

const args = process.argv.slice(2);
const userArgs = args.filter(arg => !arg.startsWith('-'));
const flags = args.filter(arg => arg.startsWith('-'));

const files = [];

if (userArgs.length > 0) {
for (const arg of userArgs) {
// Map .ts files to build/ .js files
let testPath = arg;
if (testPath.endsWith('.ts')) {
testPath = testPath.replace(/\.ts$/, '.js');
if (!testPath.startsWith('build/')) {
testPath = path.join('build', testPath);
}
}
files.push(testPath);
}
} else {
const isNode20 = process.version.startsWith('v20.');
if (isNode20) {
files.push('build/tests');
} else {
files.push('build/tests/**/*.test.js');
}
}

const nodeArgs = [
'--import',
'./build/tests/setup.js',
'--no-warnings=ExperimentalWarning',
'--test-reporter',
'spec',
'--test-force-exit',
'--test',
...flags,
...files,
];

const child = spawn('node', nodeArgs, {
stdio: 'inherit',
});

child.on('close', code => {
process.exit(code ?? 1);
});
2 changes: 1 addition & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"noEmit": true,
"useUnknownInCatchVariables": false
},
"include": ["./**/*.ts", "./**/*.js"]
"include": ["./**/*.ts", "./**/*.js", "./**/*.mjs"]
}