docs(calculate-version): 重建 README 並補齊指令檔註解與 logger JSDoc #11

Merged
admin merged 5 commits from ai-review-resolve/develop-20260630-164907 into develop 2026-06-30 10:23:29 +00:00
2 changed files with 29 additions and 10 deletions
Showing only changes of commit 1a531bfb87 - Show all commits
+6 -2
View File
@@ -5,8 +5,12 @@ const assert = require('node:assert/strict');
const { main } = require('../index');
// 安靜的 log 記錄器,避免測試輸出雜訊
const silentLog = { section() {}, info() {}, error() {} };
// 安靜的 log 記錄器,避免測試輸出雜訊;forStage 回傳同樣安靜的子記錄器
const silentLog = {
info() {},
error() {},
forStage() { return { info() {}, error() {} }; },
};
const okConfig = {
serverUrl: 'https://gitea.example.com',
+23 -8
View File
@@ -29,24 +29,39 @@ function capture(run) {
const TIME = /\[\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}\]/;
test('section 於 stdout 輸出標題與 50 寬分隔線區塊', () => {
const { out, err } = capture(() => logger.section('參數檢查'));
assert.equal(out, `\n${'='.repeat(50)}\n參數檢查\n${'-'.repeat(50)}\n`);
assert.equal(err, '');
});
test('info 以 [INF][時間]: 格式輸出至 stdout', () => {
test('info 未帶 stage 時以 [INF][時間]: 格式輸出至 stdout', () => {
const { out, err } = capture(() => logger.info('IS_BETA=false'));
assert.match(out, new RegExp(`^\\[INF\\]${TIME.source}: IS_BETA=false\\n$`));
assert.equal(err, '');
});
test('error 以 [ERR][時間]: 格式輸出至 stderr,且不寫入 stdout', () => {
test('info 帶 stage 時以 [階段][INF][時間]: 格式輸出至 stdout', () => {
const { out, err } = capture(() => logger.info('IS_BETA=false', '參數檢查'));
assert.match(out, new RegExp(`^\\[參數檢查\\]\\[INF\\]${TIME.source}: IS_BETA=false\\n$`));
assert.equal(err, '');
});
test('error 未帶 stage 時以 [ERR][時間]: 格式輸出至 stderr,且不寫入 stdout', () => {
const { out, err } = capture(() => logger.error('GITEA_SERVER_URL 未設定'));
assert.match(err, new RegExp(`^\\[ERR\\]${TIME.source}: GITEA_SERVER_URL 未設定\\n$`));
assert.equal(out, '');
});
test('error 帶 stage 時以 [階段][ERR][時間]: 格式輸出至 stderr', () => {
const { err } = capture(() => logger.error('讀取失敗', '取得舊版本'));
assert.match(err, new RegExp(`^\\[取得舊版本\\]\\[ERR\\]${TIME.source}: 讀取失敗\\n$`));
});
test('forStage 回傳的子記錄器自動帶入階段名稱', () => {
const staged = logger.forStage('計算版本號');
const { out, err } = capture(() => {
staged.info('NEW_VERSION=0.0.6');
staged.error('計算錯誤');
});
assert.match(out, new RegExp(`^\\[計算版本號\\]\\[INF\\]${TIME.source}: NEW_VERSION=0.0.6\\n$`));
assert.match(err, new RegExp(`^\\[計算版本號\\]\\[ERR\\]${TIME.source}: 計算錯誤\\n$`));
});
test('info/error 的時間戳為 yyyy/MM/dd HH:mm:ss 格式', () => {
const { out } = capture(() => logger.info('x'));
assert.match(out, TIME);