From db73afffff4eed8498df42f72c4b94024ddb164e Mon Sep 17 00:00:00 2001 From: Tamara Jordan Date: Thu, 7 May 2020 16:28:51 +0100 Subject: [PATCH] refactor(test): split up the test output slightly The config for each test now has a couple of new lines in between re #51 --- src/commands/test/test.ts | 6 +++--- src/messages.ts | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/commands/test/test.ts b/src/commands/test/test.ts index 6d26e7ee..29e9792b 100644 --- a/src/commands/test/test.ts +++ b/src/commands/test/test.ts @@ -12,16 +12,16 @@ const logTestResults = (baseUrl: string) => (displayName: string, endpoint: stri ): 0 | 1 => { const displayEndpoint = blue(`${baseUrl}${endpoint}`) if (!problems.length) { - logger.info(testPassed(displayName, displayEndpoint)) + logger.info(testPassed(displayName, displayEndpoint) + '\n') return 0 } else { - logger.error(testFailed(displayName, displayEndpoint, problems)) + logger.error(testFailed(displayName, displayEndpoint, problems) + '\n') return 1 } } const logTestError = (displayName: string) => (err: Error): void => { - logger.error(testError(displayName, err.message)) + logger.error(testError(displayName, err.message) + `\n`) } export const testConfigs = async ( diff --git a/src/messages.ts b/src/messages.ts index 00392e1f..8a8e9305 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -1,4 +1,4 @@ -import { red, green, blue, blueBright } from 'chalk' +import { red, green, blue } from 'chalk' import { ProblemResult } from '~config/mapper' import { gatherValidationErrors } from '~commands/shared' import Problem from '~problem' @@ -20,13 +20,15 @@ export const validationFailed = ({ name, problems }: ProblemResult): string => `${red('Validation failed')}: ${name} \n${gatherValidationErrors(problems)}\n` const testResult = (passed: boolean, name: string, suffix: string): string => { - const prefix = passed ? green('PASSED') : red('FAILED') - return `${prefix}: ${name} - ${suffix}` + const prefix = passed ? green('PASSED') : red.bold('FAILED') + const formattedName = passed ? name : red.bold(name) + return `${prefix}: ${formattedName}\n${suffix}\n` } -// TODO: it would be cool to reuse the ProblemResult abstraction here export const testPassed = (name: string, endpoint: string): string => - testResult(true, name, blueBright(endpoint)) + testResult(true, name, `URL: ${endpoint}`) + export const testFailed = (name: string, endpoint: string, problems: Problem[]): string => - `${testResult(false, name, blueBright(endpoint))}\n${gatherValidationErrors(problems)}` + `${testResult(false, name, `URL: ${endpoint}`)}\n${gatherValidationErrors(problems)}` + export const testError = (name: string, message: string): string => testResult(false, name, message)