From 9372af8ca1a0f9dc9ee653bd7d145c5265ce53c5 Mon Sep 17 00:00:00 2001 From: killa Date: Sat, 2 May 2026 23:16:51 +0800 Subject: [PATCH 1/9] chore(test): add ci benchmark harness --- package.json | 1 + scripts/ci-test-benchmark.js | 678 +++++++++++++++++++++++++++++++++++ 2 files changed, 679 insertions(+) create mode 100644 scripts/ci-test-benchmark.js diff --git a/package.json b/package.json index 7063b24ae8..1d8b94c162 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "pretest": "ut run clean-dist && ut run pretest --workspaces --if-present", "test": "vitest run --bail 1 --retry 2 --testTimeout 20000 --hookTimeout 20000", "test:cov": "ut run test -- --coverage", + "benchmark:ci-test": "node scripts/ci-test-benchmark.js", "preci": "ut run pretest --workspaces --if-present", "ci": "ut run test -- --coverage", "site:dev": "cd site && npm run dev", diff --git a/scripts/ci-test-benchmark.js b/scripts/ci-test-benchmark.js new file mode 100644 index 0000000000..7a50eb0142 --- /dev/null +++ b/scripts/ci-test-benchmark.js @@ -0,0 +1,678 @@ +#!/usr/bin/env node + +import { spawn } from 'node:child_process'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import process from 'node:process'; + +const DEFAULT_TOP_LIMIT = 20; +const DEFAULT_OUTPUT_ROOT = path.join('benchmark', 'ci-test'); +const VITEST_JSON_FILENAME = 'vitest-results.json'; +const REPORT_JSON_FILENAME = 'report.json'; +const REPORT_MARKDOWN_FILENAME = 'report.md'; +const VITEST_JSON_PLACEHOLDER = '{vitestJson}'; +const DEFAULT_COMMAND = [ + 'pnpm', + 'exec', + 'vitest', + 'run', + '--bail', + '1', + '--retry', + '2', + '--testTimeout', + '20000', + '--hookTimeout', + '20000', +]; + +function printHelp() { + console.log(` +Usage: + pnpm run benchmark:ci-test + pnpm run benchmark:ci-test -- --coverage + pnpm run benchmark:ci-test -- --output-dir .tmp/bench -- pnpm exec vitest run --maxWorkers=4 + +Options: + --output-dir Directory for report.md, report.json, and raw Vitest JSON. + --name