UNPKG

@tapjs/reporter

Version:

Pretty test output reporters for tap

52 lines 1.74 kB
import { render } from 'ink'; import { isStream } from 'minipass'; import React from 'react'; import { Base } from './base.js'; import * as components from './components.js'; import { Dot } from './dot.js'; import * as hooks from './hooks.js'; import { JSONReport, JSONStream } from './json.js'; import { JUnit } from './junit.js'; import { MarkdownStream } from './markdown.js'; import { Min } from './min.js'; import { Terse } from './terse.js'; import * as utils from './utils.js'; export { Base, Terse, Min, Dot, JSONReport, JSONStream, MarkdownStream, JUnit, hooks, components, utils, }; export const types = {}; export const addType = (name, report) => { types[name] = report; }; addType('base', Base); addType('terse', Terse); addType('min', Min); addType('dot', Dot); addType('jsonstream', JSONStream); addType('json', JSONReport); addType('junit', JUnit); addType('markdown', MarkdownStream); export const report = async (Type, tap, config, stdout = process.stdout) => { if (typeof Type === 'string') { if (types.hasOwnProperty(Type)) { Type = types[Type]; } else { throw new TypeError(`unknown report type: ${Type}`); } } tap.register(); if (isStream(Type.prototype)) { const reporter = new Type(); tap.pipe(reporter).pipe(stdout); } else { // always show the cursor when we finish tap.on('complete', () => process.stdout.write('\x1b[?25h')); const T = Type; const opts = stdout === process.stdout ? { patchConsole: false } : stdout; render(React.createElement(T, { test: tap, config: config }), opts); } return true; }; //# sourceMappingURL=index.js.map