playwright-bdd
Version:
BDD Testing with Playwright runner
78 lines • 2.94 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const message_1 = __importDefault(require("./message"));
const html_1 = __importDefault(require("./html"));
const junit_1 = __importDefault(require("./junit"));
const json_1 = __importDefault(require("./json"));
const custom_1 = __importDefault(require("./custom"));
const env_1 = require("../../config/env");
const reporters_registry_1 = require("./reporters-registry");
const builtinReporters = {
html: html_1.default,
message: message_1.default,
junit: junit_1.default,
'junit-modern': junit_1.default, // Deprecated alias for junit
json: json_1.default,
};
class CucumberReporterAdapter {
constructor(fullOptions) {
const { $type, ...userOptions } = fullOptions;
this.type = $type;
this.userOptions = userOptions;
this.reporter = this.createCucumberReporter();
this.isFirstReporter = (0, reporters_registry_1.registerReporter)();
}
onBegin(config) {
if (this.isFirstReporter)
(0, reporters_registry_1.getMessagesBuilder)().onBegin(config);
}
printsToStdio() {
return this.reporter.printsToStdio();
}
onTestEnd(test, result) {
if (this.isFirstReporter)
(0, reporters_registry_1.getMessagesBuilder)().onTestEnd(test, result);
}
/**
* Error not related to any test, e.g. worker teardown.
*/
onError(error) {
if (this.isFirstReporter)
(0, reporters_registry_1.getMessagesBuilder)().onError(error);
}
async onEnd(result) {
try {
if (this.isFirstReporter)
await (0, reporters_registry_1.getMessagesBuilder)().onEnd(result);
await (0, reporters_registry_1.getMessagesBuilder)().finished;
await this.reporter.init();
(0, reporters_registry_1.getMessagesBuilder)().emitMessages(this.reporter.eventBroadcaster);
await this.reporter.finished();
}
finally {
(0, reporters_registry_1.unregisterReporter)();
}
}
createCucumberReporter() {
const internalOptions = {
cwd: (0, env_1.getConfigDirFromEnv)(),
messagesBuilder: (0, reporters_registry_1.getMessagesBuilder)(),
};
if (isBuiltInReporter(this.type)) {
const BuiltInReporter = builtinReporters[this.type];
return new BuiltInReporter(internalOptions, this.userOptions);
}
else {
const reporterPath = this.type;
return new custom_1.default(internalOptions, reporterPath, this.userOptions);
}
}
}
exports.default = CucumberReporterAdapter;
function isBuiltInReporter(type) {
return type in builtinReporters;
}
//# sourceMappingURL=index.js.map