From 230a7ad1624ad91120289a2a6bd29fe3da45135f Mon Sep 17 00:00:00 2001 From: Mike North Date: Thu, 2 Aug 2018 14:16:04 -0700 Subject: [PATCH] [testing] logCountAssert counts are optional (#6) * fix: Make each log count assertion (error, log, debug, warn) optional * fix: test printer captures all arguments passed to log, debug, etc... (not just the first one) --- test/test-helpers.ts | 76 ++++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/test/test-helpers.ts b/test/test-helpers.ts index 606f248..9fe4f6a 100644 --- a/test/test-helpers.ts +++ b/test/test-helpers.ts @@ -3,22 +3,22 @@ import { Printer } from 'bite-log'; export function makeTestPrinter(): Printer & { messages: any } { const printer = { messages: { - log: [] as string[], - debug: [] as string[], - warn: [] as string[], - error: [] as string[] + log: [] as any[][], + debug: [] as any[][], + warn: [] as any[][], + error: [] as any[][] }, - log(msg: string) { - printer.messages.log.push(msg); + log(_msg: string) { + printer.messages.log.push([...arguments]); }, - debug(msg: string) { - printer.messages.debug.push(msg); + debug(_msg: string) { + printer.messages.debug.push([...arguments]); }, - warn(msg: string) { - printer.messages.warn.push(msg); + warn(_msg: string) { + printer.messages.warn.push([...arguments]); }, - error(msg: string) { - printer.messages.error.push(msg); + error(_msg: string) { + printer.messages.error.push([...arguments]); } }; return printer; @@ -29,27 +29,35 @@ export function logCountAssert( message, assert, printer - }: { message: string; assert: Assert; printer: Printer; }, - { e, w, l, d }: { e: number; w: number; l: number; d: number } + }: { message: string; assert: Assert; printer: Printer }, + { e, w, l, d }: { e?: number; w?: number; l?: number; d?: number } ) { - assert.equal( - (printer as any).messages.error.length, - e, - `${message}: ${e} error(s) were logged` - ); - assert.equal( - (printer as any).messages.warn.length, - w, - `${message}: ${w} warning(s) was logged` - ); - assert.equal( - (printer as any).messages.debug.length, - d, - `${message}: ${d} debug(s) were logged` - ); - assert.equal( - (printer as any).messages.log.length, - l, - `${message}: ${l} log(s) were logged` - ); + if (typeof e !== 'undefined') { + assert.equal( + (printer as any).messages.error.length, + e, + `${message}: ${e} error(s) were logged` + ); + } + if (typeof w !== 'undefined') { + assert.equal( + (printer as any).messages.warn.length, + w, + `${message}: ${w} warning(s) was logged` + ); + } + if (typeof d !== 'undefined') { + assert.equal( + (printer as any).messages.debug.length, + d, + `${message}: ${d} debug(s) were logged` + ); + } + if (typeof l !== 'undefined') { + assert.equal( + (printer as any).messages.log.length, + l, + `${message}: ${l} log(s) were logged` + ); + } }