我正在尝试学习如何为Cucumber JS编写简单的自定义格式化程序。
我已阅读https://github.com/cucumber/cucumber-js/blob/master/docs/custom_formatters.md
我在下面尝试了此示例。但是它没有输出任何东西。该文档讨论有关为日志功能设置基础流的信息。但是我看不到任何设置的流选项,自定义格式程序样本也没有。
所以我的问题是如何从下面获取此简单示例以将输出记录到stdout?
我正在按照文档中提到的以下方式运行测试,以使用此新格式化程序
./ node_modules / .bin / cucumber-js -f。\ simple_formatter.js ./Features -r ./Steps
const { Formatter, formatterHelpers, Status } = require("cucumber");
const { stdout } = require("process");
class SimpleFormatter extends Formatter {
constructor(options) {
super(options);
options.eventBroadcaster.on("envelope", (envelope) => {
if (envelope.testCaseFinished) {
this.logTestCaseFinished(envelope.testCaseFinished);
} else if (envelope.testRunFinished) {
this.logTestRunFinished(envelope.testRunFinished);
}
});
}
logTestCaseFinished(testCaseFinished) {
const testCaseAttempt = this.eventDataCollector.getTestCaseAttempt(
testCaseFinished.testCaseStartedId
);
this.log(
testCaseAttempt.gherkinDocument.feature.name +
" / " +
testCaseAttempt.pickle.name +
"\n"
);
const parsed = formatterHelpers.parseTestCaseAttempt({
cwd: this.cwd,
snippetBuilder: this.snippetBuilder,
supportCodeLibrary: this.supportCodeLibrary,
testCaseAttempt,
});
parsed.testSteps.forEach((testStep) => {
this.log(
" " +
testStep.keyword +
(testStep.text || "") +
" - " +
Status[testStep.result.status] +
"\n"
);
});
this.log("\n");
}
logTestRunFinished(testRunFinished) {
this.log(testRunFinished.success ? "SUCCESS" : "FAILURE");
}
}
module.exports = SimpleFormatter;