test(test 目錄): 將 12 個單元測試移至 app/test 並更新 npm test 指令
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
51fd223b48
commit
303104bb20
@@ -0,0 +1,78 @@
|
||||
import { describe, it, afterEach, mock } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { section, step, line, input, output, result, ok, warn, error } from '../log.js';
|
||||
|
||||
afterEach(() => mock.restoreAll());
|
||||
|
||||
describe('log helpers', () => {
|
||||
it('formats section and step messages', () => {
|
||||
const calls = [];
|
||||
mock.method(console, 'log', (...args) => {
|
||||
calls.push(args.join(' '));
|
||||
});
|
||||
|
||||
section('Pipeline');
|
||||
step('Step1', 'Start');
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
'\n=== Pipeline ===',
|
||||
'\n[Step1] Start',
|
||||
]);
|
||||
});
|
||||
|
||||
it('formats line and ok messages with console.log', () => {
|
||||
const calls = [];
|
||||
mock.method(console, 'log', (...args) => {
|
||||
calls.push(args.join(' '));
|
||||
});
|
||||
|
||||
line('hello');
|
||||
ok('done');
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
' - hello',
|
||||
' ✓ done',
|
||||
]);
|
||||
});
|
||||
|
||||
it('formats input/output and pass/fail result messages', () => {
|
||||
const calls = [];
|
||||
mock.method(console, 'log', (...args) => {
|
||||
calls.push(args.join(' '));
|
||||
});
|
||||
|
||||
input('5 筆');
|
||||
output('3 筆');
|
||||
result(true, '通過');
|
||||
result(false, '未通過');
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
' ← 輸入:5 筆',
|
||||
' → 輸出:3 筆',
|
||||
' ✅ 成功:通過',
|
||||
' ❌ 失敗:未通過',
|
||||
]);
|
||||
});
|
||||
|
||||
it('formats warn messages with console.warn', () => {
|
||||
const calls = [];
|
||||
mock.method(console, 'warn', (...args) => {
|
||||
calls.push(args.join(' '));
|
||||
});
|
||||
|
||||
warn('careful');
|
||||
|
||||
assert.deepEqual(calls, [' ! careful']);
|
||||
});
|
||||
|
||||
it('formats error messages with console.error', () => {
|
||||
const calls = [];
|
||||
mock.method(console, 'error', (...args) => {
|
||||
calls.push(args.join(' '));
|
||||
});
|
||||
|
||||
error('boom');
|
||||
|
||||
assert.deepEqual(calls, [' x boom']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user