playwright-bdd
Version:
BDD Testing with Playwright runner
60 lines • 2.22 kB
JavaScript
;
/**
* Cucumber JUnit reporter.
*
* Uses https://github.com/cucumber/junit-xml-formatter.
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const junit_xml_formatter_1 = __importDefault(require("@cucumber/junit-xml-formatter"));
const base_1 = __importDefault(require("./base"));
const GherkinDocument_1 = require("./messagesBuilder/GherkinDocument");
// title separator used in Playwright
const PLAYWRIGHT_TITLE_SEPARATOR = ' › ';
class JunitReporter extends base_1.default {
constructor(internalOptions, userOptions = {}) {
super(internalOptions);
this.userOptions = userOptions;
this.setOutputStream(this.userOptions.outputFile);
}
async init() {
junit_xml_formatter_1.default.formatter({
options: {
suiteName: this.userOptions.suiteName,
testNamingStrategy: this.getNamingStrategy(),
},
on: (_type, handler) => this.eventBroadcaster.on('envelope', handler),
write: (data) => this.outputStream.write(data),
});
}
getNamingStrategy() {
return this.userOptions.nameFormat === 'playwright'
? new PlaywrightNamingStrategy()
: undefined;
}
}
exports.default = JunitReporter;
class PlaywrightNamingStrategy {
reduce(lineage, pickle) {
const meta = lineage.gherkinDocument
? GherkinDocument_1.GherkinDocumentMessage.extractMeta(lineage.gherkinDocument)
: undefined;
const scenarioName = lineage.scenario?.name ?? pickle.name;
const pickleName = pickle.name;
return [
meta?.projectName, // prettier-ignore
lineage.feature?.name,
lineage.rule?.name,
!hasPlaceholders(scenarioName) ? scenarioName : undefined,
pickleName !== scenarioName ? pickleName : undefined,
]
.filter(Boolean)
.join(PLAYWRIGHT_TITLE_SEPARATOR);
}
}
function hasPlaceholders(value) {
return /<[^>]+>/.test(value);
}
//# sourceMappingURL=junit.js.map