豆豆友情提示:这是一个非官方 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
3 changes: 2 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ jobs:

- name: Run tests
shell: bash
run: npm run test:no-build
# Retry tests if they fail in the merge queue.
run: npm run test:no-build -- ${{ github.event_name == 'merge_group' && '--retry' || '' }}

# Gating job for branch protection.
test-success:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"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": "npm run build && npm run test:no-build",
"test": "npm run build && node scripts/test.mjs",
"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",
Expand Down
38 changes: 32 additions & 6 deletions scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const flags = args.filter(arg => arg.startsWith('-'));

const files = [];

let shouldRetry = false;
Comment thread
OrKoN marked this conversation as resolved.
const retryIndex = flags.indexOf('--retry');
if (retryIndex !== -1) {
shouldRetry = true;
flags.splice(retryIndex, 1);
}

if (userArgs.length > 0) {
for (const arg of userArgs) {
// Map .ts files to build/ .js files
Expand Down Expand Up @@ -50,10 +57,29 @@ const nodeArgs = [
...files,
];

const child = spawn('node', nodeArgs, {
stdio: 'inherit',
});
async function runTests(attempt) {
if (attempt > 1) {
console.log(`\nRun attempt ${attempt}...\n`);
}
return new Promise(resolve => {
const child = spawn('node', nodeArgs, {
stdio: 'inherit',
});

child.on('close', code => {
resolve(code);
});
});
}

const maxAttempts = shouldRetry ? 3 : 1;
let exitCode = 1;

for (let i = 1; i <= maxAttempts; i++) {
exitCode = await runTests(i);
if (exitCode === 0) {
break;
}
}

child.on('close', code => {
process.exit(code ?? 1);
});
process.exit(exitCode ?? 1);