Files
release-cleanup/app/test/logger.test.js
T
JefferyandClaude Opus 4.8 b9d7c4e970 test(release-cleanup): 補強逾時、非陣列、token 邊界與 failError 測試
新增 fetchAllPages 的 AbortError 逾時與非陣列回應測試、loadConfig 的
GITEA_TOKEN 邊界測試,以及 logger.failError 測試。測試共 47 項全數通過。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-26 11:04:29 +08:00

36 lines
905 B
JavaScript

import { test, afterEach } from 'node:test'
import assert from 'node:assert/strict'
import { failError } from '../logger.js'
const realWrite = process.stderr.write
afterEach(() => {
process.stderr.write = realWrite
})
// 攔截寫入 stderr 的內容
function captureStderr(fn) {
const chunks = []
process.stderr.write = (chunk) => {
chunks.push(String(chunk))
return true
}
try {
fn()
} finally {
process.stderr.write = realWrite
}
return chunks.join('')
}
test('failError 對 Error 物件輸出名稱、訊息與堆疊', () => {
const out = captureStderr(() => failError(new TypeError('boom')))
assert.match(out, /\[ERR\] TypeError: boom/)
assert.match(out, /at /) // 堆疊內容
})
test('failError 對非 Error 值輸出其字串形式', () => {
const out = captureStderr(() => failError('plain failure'))
assert.match(out, /\[ERR\] plain failure/)
})