Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
refactor(test): split up the test output slightly
Browse files Browse the repository at this point in the history
The config for each test now has a couple of new lines in between

re #51
  • Loading branch information
tamj0rd2 committed May 7, 2020
1 parent e82f687 commit db73aff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/commands/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
14 changes: 8 additions & 6 deletions src/messages.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)

0 comments on commit db73aff

Please sign in to comment.