refactor(測試): 共用假 Gitea 的啟動與環境變數
每支測試各自寫一次「啟動 stub、登記 close、組環境變數」已經重複三次,抽到 helpers 之後新增測試檔只要一行。各檔仍保留自己的預設路由,因為那是該檔的 情境設定,不該共用。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -89,3 +89,17 @@ function safeParse(raw) {
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 啟動假 Gitea 並登記在測試結束時關掉,省去每支測試各寫一次 close。
|
||||
* @param {object} t node:test 的 TestContext
|
||||
* @param {Record<string, object|Function>} routes
|
||||
*/
|
||||
export async function withStubGitea(t, routes) {
|
||||
const stub = await startStubGitea(routes);
|
||||
t.after(() => stub.close());
|
||||
return stub;
|
||||
}
|
||||
|
||||
/** 把腳本指向這台假 Gitea 的環境變數 */
|
||||
export const stubEnv = (stub) => ({ TEA_SDLC_API_BASE: stub.base, TEA_SDLC_TOKEN: 'stub-token' });
|
||||
|
||||
Reference in New Issue
Block a user