How to use the youch.Youch function in youch

To help you get started, we’ve selected a few youch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sakuli / sakuli / packages / sakuli-cli / src / render / render-test-entity.function.ts View on Github external
export async function renderTestEntity(
    entity: TestContextEntity,
    tick: number = 0,
    ident: number = 0
) {
    const defaultName = '';
    const identifier = `${entity.kind} ${entity.id || defaultName}`;
    const spinnerContent =  ['◜','◠','◝','◞','◡','◟'];
    const timeSinceStarted = entity.isStarted() ? (((new Date().getTime()) - (entity.startDate.getTime())) / 1000).toFixed(0) : '';
    const error = entity.error ? EOL + await new Youch(entity.error, {}).toJSON().then(forTerminal) : '';
    const color = chalk.bold.green;
    const main = !entity.isFinished()
        ? chalk`${spinnerContent[tick % spinnerContent.length]} {bold.yellow RUNNING} ${identifier} {gray for} ${timeSinceStarted.toString()}`
        : !!entity.error
            ? chalk`{bold.red ✗ ERROR} ${identifier} {gray after} ${(entity.duration || NaN).toString()}` + error
            : color(` ✓ ${getReadableStateName(entity.state)} `) + chalk`${identifier} {gray after} ${(entity.duration || NaN).toString()}`;
    let addition = '';
    if(entity instanceof TestSuiteContext) {
        addition = await renderArray(entity.testCases, tc => renderTestEntity(tc, tick, 1));
    }
    if(entity instanceof TestCaseContext) {
        addition = await renderArray(entity.testSteps, ts => renderTestEntity(ts, tick, 2));
    }
    return `${createIdent(ident)}${main}${EOL}${addition}`;
}

youch

HTML Pretty error stack viewer

MIT
Latest version published 6 months ago

Package Health Score

84 / 100
Full package analysis

Popular youch functions