From 86d8666cda5bd6d447c2362c71e6bd57950ff3e3 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Fri, 15 May 2026 15:51:56 +0000 Subject: [PATCH] test: cover log helpers --- app/log.test.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/log.test.js diff --git a/app/log.test.js b/app/log.test.js new file mode 100644 index 0000000..c810d77 --- /dev/null +++ b/app/log.test.js @@ -0,0 +1,59 @@ +import { describe, it, afterEach, mock } from 'node:test'; +import assert from 'node:assert/strict'; +import { section, step, line, 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 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']); + }); +});