Skip to content

Instantly share code, notes, and snippets.

@alanrsoares
Created July 8, 2016 00:33
Show Gist options
  • Save alanrsoares/5e59afeddb91d1af928545a1ff958832 to your computer and use it in GitHub Desktop.
Save alanrsoares/5e59afeddb91d1af928545a1ff958832 to your computer and use it in GitHub Desktop.
const assert = f => ([a, b]) =>
(x => x === b
? { passed: true }
: {
failed: true,
message: `- expected f(${a}) to be ${b}, but was ${x}`
}
)(f(a))
const runTests = (cases, f) => {
const results = cases.map(assert(f))
const [passed, failed] = ['passed', 'failed'].map(
p => results.filter(x => x[p])
)
return { passed, failed }
}
const failureSummary = failed => [
`${failed.length} test${failed.length > 1 ? 's' : ''} have failed:`,
failed.map(x => x.message).join('\n\t')
].join('\n\t')
const report = ({ passed, failed }) => {
console.log(
`${passed.length} tests passed`
)
if (failed.length) {
const summary = failureSummary(failed)
console.error(summary)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment