@cucumber/cucumber
Version:
The official JavaScript implementation of Cucumber.
52 lines • 2.67 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.initializeFormatters = initializeFormatters;
const node_util_1 = require("node:util");
const builder_1 = __importDefault(require("../formatter/builder"));
const create_stream_1 = require("../formatter/create_stream");
const resolve_implementation_1 = require("../formatter/resolve_implementation");
async function initializeFormatters({ env, cwd, stdout, logger, onStreamError, eventBroadcaster, eventDataCollector, configuration, supportCodeLibrary, pluginManager, }) {
const cleanupFns = [];
async function initializeFormatter(stream, directory, target, specifier) {
if (specifier === 'progress-bar' && !stream.isTTY) {
logger.warn(`Cannot use 'progress-bar' formatter for output to '${target}' as not a TTY. Switching to 'progress' formatter.`);
specifier = 'progress';
}
const implementation = await (0, resolve_implementation_1.resolveImplementation)(specifier, cwd);
if (typeof implementation === 'function') {
const typeOptions = {
env,
cwd,
eventBroadcaster,
eventDataCollector,
log: stream.write.bind(stream),
parsedArgvOptions: configuration.options,
stream,
cleanup: stream === stdout
? async () => await Promise.resolve()
: (0, node_util_1.promisify)(stream.end.bind(stream)),
supportCodeLibrary,
};
const formatter = await builder_1.default.build(implementation, typeOptions);
cleanupFns.push(async () => formatter.finished());
}
else {
await pluginManager.initFormatter(implementation, configuration.options, stream, stream.write.bind(stream), directory);
if (stream !== stdout) {
cleanupFns.push((0, node_util_1.promisify)(stream.end.bind(stream)));
}
}
}
await initializeFormatter(stdout, undefined, 'stdout', configuration.stdout);
for (const [target, specifier] of Object.entries(configuration.files)) {
const { stream, directory } = await (0, create_stream_1.createStream)(target, onStreamError, cwd, logger);
await initializeFormatter(stream, directory, target, specifier);
}
return async function () {
await Promise.all(cleanupFns.map((cleanupFn) => cleanupFn()));
};
}
//# sourceMappingURL=formatters.js.map