From 267fce1f8ecc22b64696c5addf374597ae8463a7 Mon Sep 17 00:00:00 2001 From: dblock Date: Mon, 8 Jul 2024 18:50:09 -0400 Subject: [PATCH] Fix: tests. Signed-off-by: dblock --- tools/src/tester/ResultLogger.ts | 16 +++++++++++++--- tools/tests/tester/ResultLogger.test.ts | 4 ++-- tools/tests/tester/test.test.ts | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/src/tester/ResultLogger.ts b/tools/src/tester/ResultLogger.ts index 50b9c5574..4ffc95aa9 100644 --- a/tools/src/tester/ResultLogger.ts +++ b/tools/src/tester/ResultLogger.ts @@ -90,10 +90,20 @@ export class ConsoleResultLogger implements ResultLogger { #log_evaluation (evaluation: Evaluation, title: string, prefix: number = 0): void { const result = ansi.padding(this.#result(evaluation.result), 0, prefix) + var message = evaluation.message - if (message !== undefined && message?.length > 128 && !this._verbose) message = message.split(',')[0] + ', ...' - if (message !== undefined) message = ansi.gray(`${message}`) - console.log(`${result} ${title} ${message}`) + + if (message !== undefined && message?.length > 128 && !this._verbose) { + const message_part = message.split(',')[0] + message = message_part === message ? message : message_part + ', ...' + } + + if (message !== undefined) { + message = ansi.gray(`(${message})`) + console.log(`${result} ${title} ${message}`) + } else { + console.log(`${result} ${title}`) + } } #result (r: Result): string { diff --git a/tools/tests/tester/ResultLogger.test.ts b/tools/tests/tester/ResultLogger.test.ts index 5cc8975d1..8c0470dae 100644 --- a/tools/tests/tester/ResultLogger.test.ts +++ b/tools/tests/tester/ResultLogger.test.ts @@ -47,8 +47,8 @@ describe('ConsoleResultLogger', () => { expect(log.mock.calls).toEqual([ [], [`${ansi.green('PASSED ')} ${ansi.cyan(ansi.b('path'))} ${ansi.gray('(message)')}`], - [` ${ansi.green('PASSED ')} CHAPTERS `], - [` ${ansi.green('PASSED ')} ${ansi.i('title')} `], + [` ${ansi.green('PASSED ')} CHAPTERS`], + [` ${ansi.green('PASSED ')} ${ansi.i('title')}`], [] ]) }) diff --git a/tools/tests/tester/test.test.ts b/tools/tests/tester/test.test.ts index bab385367..e2b2ea330 100644 --- a/tools/tests/tester/test.test.ts +++ b/tools/tests/tester/test.test.ts @@ -41,7 +41,7 @@ test('displays story filename', () => { test('invalid story', () => { expect(spec(['--tests', 'tools/tests/tester/fixtures/invalid_story.yaml']).stdout).toContain( - `${ansi.gray("(Invalid Story: data/epilogues/0 must NOT have unevaluated properties, data/chapters/0 must have required property 'method', data/chapters/1/method must be equal to one of the allowed values)")}` + `${ansi.gray("(Invalid Story: data/epilogues/0 must NOT have unevaluated properties, ...)")}` ) })