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/) })