Skip to content

Commit

Permalink
feat(test): improve test CLI output
Browse files Browse the repository at this point in the history
  • Loading branch information
dalssoft committed May 24, 2022
1 parent ed285c1 commit b2da950
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,29 @@ const cmd = {
if (instance.isSpec) specs.push(instance)
}

const { grey, green, red } = toolbox.print.colors
const passed = 'passed'
const { grey, green, red, white, blue, italic } = toolbox.print.colors
const failed = 'failed'
for (const spec of specs) {
const ret = await spec.run()
const usecase = spec.usecase().description
const result = (ret) => ret === passed ? green('🗸') : red('•')
toolbox.print.info(`${grey(usecase)} ${result(ret)}`)
const result = (ret) => ret !== failed ? green('🗸') : red('•')
toolbox.print.info(`${white(usecase)} ${result(ret)} ${grey(italic('(spec)'))}`)
for (const scenario of spec.scenarios) {
toolbox.print.info(` ${grey(scenario.description)} ${result(scenario.state)}`)
toolbox.print.info(` ${result(scenario.state)} ${white(scenario.description)} ${grey(italic('(scenario)'))}`)
if (scenario.state !== failed) continue
const steps = (step) => step.forEach(e => {
const description = e.builtin ? `When run` : e.description
const color = e.state !== failed ? grey : red
const type = `(${e.type})`
toolbox.print.info(` ${result(e.state)} ${color(description)} ${grey(italic(type))}`)
if (e.error)
toolbox.print.info(`\n ${blue(e.error)} \n`)
})
steps(scenario.givens)
if (scenario.stage === 'given') continue
steps(scenario.whens)
if (scenario.stage === 'when') continue
steps(scenario.checks)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/domain/useCases/delete.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const <%- props.name.pascalCase %>Repository = require('../../../infra/data/repo
const dependency = { <%- props.name.pascalCase %>Repository }

const delete<%- props.name.pascalCase %> = injection =>
usecase('Delete the <%- props.name.pascalCase %>', {
usecase('Delete <%- props.name.pascalCase %>', {
// Input/Request metadata and validation
request: {
id: Number
Expand Down

0 comments on commit b2da950

Please sign in to comment.