refactor(測試): 共用假 Gitea 的啟動與環境變數

每支測試各自寫一次「啟動 stub、登記 close、組環境變數」已經重複三次,抽到
helpers 之後新增測試檔只要一行。各檔仍保留自己的預設路由,因為那是該檔的
情境設定,不該共用。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 04:44:45 +00:00
co-authored by Claude Opus 5
parent 4f542d9c86
commit b0bd061852
4 changed files with 20 additions and 17 deletions
+2 -7
View File
@@ -1,20 +1,15 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { runScript } from './helpers/run-script.js';
import { startStubGitea, healthyRoutes } from './helpers/stub-gitea.js';
import { healthyRoutes, stubEnv as envFor, withStubGitea } from './helpers/stub-gitea.js';
const REPO = 'plugins/tea-sdlc';
/** 讓每個測試都拿到一台乾淨的假 Gitea,並在結束後關掉 */
async function withStub(t, overrides = {}) {
const stub = await startStubGitea(healthyRoutes(REPO, overrides));
t.after(() => stub.close());
return stub;
return withStubGitea(t, healthyRoutes(REPO, overrides));
}
function envFor(stub) {
return { TEA_SDLC_API_BASE: stub.base, TEA_SDLC_TOKEN: 'stub-token' };
}
test('列出目標 repo 的既有標籤,輸出單行 JSON 且 exit 0', async (t) => {
const stub = await withStub(t);