allure-cucumberjs
Advanced tools
Comparing version 2.0.0-beta.18 to 2.0.0-beta.19
@@ -8,17 +8,15 @@ import { World as CucumberWorld, Formatter } from "@cucumber/cucumber"; | ||
} | ||
export declare type LabelMatcher = { | ||
pattern: RegExp[]; | ||
name: "epic" | "severity" | string; | ||
}; | ||
export declare type LinkMatcher = { | ||
pattern: RegExp[]; | ||
urlTemplate: string; | ||
type: "tms" | "issue" | string; | ||
}; | ||
export declare class CucumberJSAllureFormatterConfig { | ||
exceptionFormatter?: (message: string) => string; | ||
labels?: { | ||
[key: string]: RegExp[]; | ||
}; | ||
links?: { | ||
issue?: { | ||
pattern: RegExp[]; | ||
urlTemplate: string; | ||
}; | ||
tms?: { | ||
pattern: RegExp[]; | ||
urlTemplate: string; | ||
}; | ||
}; | ||
labels?: LabelMatcher[]; | ||
links?: LinkMatcher[]; | ||
} | ||
@@ -35,5 +33,6 @@ export declare class CucumberJSAllureFormatter extends Formatter { | ||
private readonly exceptionFormatter; | ||
private readonly labels; | ||
private readonly links; | ||
private readonly labelsMathers; | ||
private readonly linksMatchers; | ||
private stepStack; | ||
private hostname; | ||
private readonly documentMap; | ||
@@ -53,4 +52,8 @@ private readonly featureMap; | ||
private readonly allureSteps; | ||
private runningTestsMap; | ||
constructor(options: IFormatterOptions, allureRuntime: AllureRuntime, config: CucumberJSAllureFormatterConfig); | ||
private get tagsIgnorePatterns(); | ||
private parseEnvelope; | ||
private parseTagsLabels; | ||
private parseTagsLinks; | ||
private onGherkinDocument; | ||
@@ -57,0 +60,0 @@ private onScenario; |
@@ -21,4 +21,9 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CucumberJSAllureFormatter = exports.CucumberJSAllureFormatterConfig = exports.Allure = void 0; | ||
const os_1 = __importDefault(require("os")); | ||
const process_1 = __importDefault(require("process")); | ||
const cucumber_1 = require("@cucumber/cucumber"); | ||
@@ -34,2 +39,3 @@ const messages = __importStar(require("@cucumber/messages")); | ||
exports.CucumberJSAllureFormatterConfig = CucumberJSAllureFormatterConfig; | ||
const { ALLURE_HOST_NAME, ALLURE_THREAD_NAME } = process_1.default.env; | ||
class CucumberJSAllureFormatter extends cucumber_1.Formatter { | ||
@@ -44,2 +50,3 @@ constructor(options, allureRuntime, config) { | ||
this.stepStack = []; | ||
this.hostname = ALLURE_HOST_NAME || os_1.default.hostname(); | ||
this.documentMap = new Map(); | ||
@@ -59,2 +66,3 @@ this.featureMap = new Map(); | ||
this.allureSteps = new Map(); | ||
this.runningTestsMap = new Map(); | ||
this.convertStatus = (status) => { | ||
@@ -74,4 +82,4 @@ switch (status) { | ||
options.eventBroadcaster.on("envelope", this.parseEnvelope.bind(this)); | ||
this.labels = config.labels || {}; | ||
this.links = config.links || {}; | ||
this.labelsMathers = config.labels || []; | ||
this.linksMatchers = config.links || []; | ||
this.exceptionFormatter = (message) => { | ||
@@ -93,2 +101,6 @@ if (config.exceptionFormatter !== undefined) { | ||
} | ||
get tagsIgnorePatterns() { | ||
const { linksMatchers, labelsMathers } = this; | ||
return [...linksMatchers, ...labelsMathers].flatMap(({ pattern }) => pattern); | ||
} | ||
parseEnvelope(envelope) { | ||
@@ -126,2 +138,39 @@ if (envelope.gherkinDocument) { | ||
} | ||
parseTagsLabels(tags) { | ||
const labels = []; | ||
if (this.labelsMathers.length === 0) { | ||
return labels; | ||
} | ||
this.labelsMathers.forEach((matcher) => { | ||
const matchedTags = tags.filter((tag) => matcher.pattern.some((pattern) => pattern.test(tag.name))); | ||
const matchedLabels = matchedTags.map((tag) => { | ||
const tagValue = tag.name.replace(/^@\S+:/, ""); | ||
return { | ||
name: matcher.name, | ||
value: tagValue, | ||
}; | ||
}); | ||
labels.push(...matchedLabels); | ||
}); | ||
return labels; | ||
} | ||
parseTagsLinks(tags) { | ||
const tagKeyRe = /^@\S+=/; | ||
const links = []; | ||
if (this.linksMatchers.length === 0) { | ||
return links; | ||
} | ||
this.linksMatchers.forEach((matcher) => { | ||
const matchedTags = tags.filter((tag) => matcher.pattern.some((pattern) => pattern.test(tag.name))); | ||
const matchedLinks = matchedTags.map((tag) => { | ||
const tagValue = tag.name.replace(tagKeyRe, ""); | ||
return { | ||
url: matcher.urlTemplate.replace(/%s$/, tagValue) || tagValue, | ||
type: matcher.type, | ||
}; | ||
}); | ||
links.push(...matchedLinks); | ||
}); | ||
return links; | ||
} | ||
onGherkinDocument(data) { | ||
@@ -151,3 +200,3 @@ var _a, _b; | ||
onTestCaseStarted(data) { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b; | ||
const testCase = this.testCaseMap.get(data.testCaseId); | ||
@@ -166,23 +215,32 @@ if (!testCase) { | ||
const scenario = this.scenarioMap.get(scenarioId); | ||
const labels = this.parseTagsLabels((scenario === null || scenario === void 0 ? void 0 : scenario.tags) || []); | ||
const links = this.parseTagsLinks((scenario === null || scenario === void 0 ? void 0 : scenario.tags) || []); | ||
const currentTest = new allure_js_commons_1.AllureTest(this.allureRuntime, Date.now()); | ||
this.runningTestsMap.set(data.id, currentTest); | ||
this.testCaseStartedMap.set(data.id, data); | ||
this.testCaseTestStepsResults.set(data.id, []); | ||
this.currentTest = new allure_js_commons_1.AllureTest(this.allureRuntime, Date.now()); | ||
this.currentTest.name = pickle.name; | ||
(_b = this.currentTest) === null || _b === void 0 ? void 0 : _b.addLabel(allure_js_commons_1.LabelName.LANGUAGE, "javascript"); | ||
(_c = this.currentTest) === null || _c === void 0 ? void 0 : _c.addLabel(allure_js_commons_1.LabelName.FRAMEWORK, "cucumberjs"); | ||
currentTest.name = pickle.name; | ||
currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLabel(allure_js_commons_1.LabelName.HOST, this.hostname); | ||
currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLabel(allure_js_commons_1.LabelName.THREAD, ALLURE_THREAD_NAME || process_1.default.getuid().toString()); | ||
currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLabel(allure_js_commons_1.LabelName.LANGUAGE, "javascript"); | ||
currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLabel(allure_js_commons_1.LabelName.FRAMEWORK, "cucumberjs"); | ||
if (doc === null || doc === void 0 ? void 0 : doc.feature) { | ||
this.currentTest.addLabel(allure_js_commons_1.LabelName.FEATURE, doc.feature.name); | ||
currentTest.addLabel(allure_js_commons_1.LabelName.FEATURE, doc.feature.name); | ||
} | ||
if (scenario) { | ||
(_d = this.currentTest) === null || _d === void 0 ? void 0 : _d.addLabel(allure_js_commons_1.LabelName.SUITE, scenario.name); | ||
currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLabel(allure_js_commons_1.LabelName.SUITE, scenario.name); | ||
} | ||
if ((_e = pickle.tags) === null || _e === void 0 ? void 0 : _e.length) { | ||
pickle.tags.forEach((tag) => { | ||
var _a; | ||
(_a = this.currentTest) === null || _a === void 0 ? void 0 : _a.addLabel(allure_js_commons_1.LabelName.TAG, tag.name); | ||
if (labels.length > 0) { | ||
labels.forEach((label) => currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLabel(label.name, label.value)); | ||
} | ||
if ((_b = pickle.tags) === null || _b === void 0 ? void 0 : _b.length) { | ||
const filteredTags = pickle.tags.filter((tag) => !this.tagsIgnorePatterns.some((pattern) => pattern.test(tag.name))); | ||
filteredTags.forEach((tag) => { | ||
currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLabel(allure_js_commons_1.LabelName.TAG, tag.name); | ||
}); | ||
} | ||
links.forEach((link) => currentTest === null || currentTest === void 0 ? void 0 : currentTest.addLink(link.url, link.name, link.type)); | ||
pickle.steps.forEach((ps) => { | ||
const { argument } = ps; | ||
if (!this.currentTest || !(argument === null || argument === void 0 ? void 0 : argument.dataTable)) { | ||
if (!currentTest || !(argument === null || argument === void 0 ? void 0 : argument.dataTable)) { | ||
return; | ||
@@ -192,3 +250,3 @@ } | ||
const attachmentFilename = this.allureRuntime.writeAttachment(csvDataTable, "text/csv"); | ||
this.currentTest.addAttachment("Data table", { | ||
currentTest.addAttachment("Data table", { | ||
contentType: "text/csv", | ||
@@ -205,3 +263,3 @@ }, attachmentFilename); | ||
var _a; | ||
if (!this.currentTest) { | ||
if (!currentTest) { | ||
return; | ||
@@ -217,3 +275,3 @@ } | ||
const attachmentFilename = this.allureRuntime.writeAttachment(csvDataTable, "text/csv"); | ||
this.currentTest.addAttachment("Examples", { | ||
currentTest.addAttachment("Examples", { | ||
contentType: "text/csv", | ||
@@ -224,3 +282,4 @@ }, attachmentFilename); | ||
onAttachment(data) { | ||
if (!this.currentTest) { | ||
const currentTest = this.runningTestsMap.get((data === null || data === void 0 ? void 0 : data.testCaseStartedId) || ""); | ||
if (!currentTest) { | ||
return; | ||
@@ -232,5 +291,6 @@ } | ||
} | ||
const { fileName = "attachment", body, mediaType } = data; | ||
const attachmentFilename = this.allureRuntime.writeAttachment(body, mediaType); | ||
this.currentTest.addAttachment(fileName, { | ||
const { fileName = "attachment", body, mediaType, contentEncoding } = data; | ||
const encoding = Buffer.isEncoding(contentEncoding) ? contentEncoding : undefined; | ||
const attachmentFilename = this.allureRuntime.writeAttachment(body, mediaType, encoding); | ||
currentTest.addAttachment(fileName, { | ||
contentType: mediaType, | ||
@@ -240,3 +300,4 @@ }, attachmentFilename); | ||
onTestCaseFinished(data) { | ||
if (!this.currentTest) { | ||
const currentTest = this.runningTestsMap.get(data.testCaseStartedId); | ||
if (!currentTest) { | ||
console.error("onTestCaseFinished", "current test not found", data); | ||
@@ -263,4 +324,4 @@ return; | ||
const worstTestStepResult = messages.getWorstTestStepResult(testStepResults); | ||
this.currentTest.status = this.convertStatus(worstTestStepResult.status); | ||
this.currentTest.statusDetails = { | ||
currentTest.status = this.convertStatus(worstTestStepResult.status); | ||
currentTest.statusDetails = { | ||
message: worstTestStepResult.message, | ||
@@ -270,5 +331,6 @@ }; | ||
else { | ||
this.currentTest.status = allure_js_commons_1.Status.PASSED; | ||
currentTest.status = allure_js_commons_1.Status.PASSED; | ||
} | ||
this.currentTest.endTest(Date.now()); | ||
currentTest.endTest(Date.now()); | ||
this.runningTestsMap.delete(data.testCaseStartedId); | ||
} | ||
@@ -284,3 +346,4 @@ onHook(data) { | ||
onTestStepStarted(data) { | ||
if (!this.currentTest) { | ||
const currentTest = this.runningTestsMap.get(data.testCaseStartedId); | ||
if (!currentTest) { | ||
return; | ||
@@ -302,3 +365,3 @@ } | ||
.find((kw) => kw !== undefined) || ""; | ||
const allureStep = this.currentTest.startStep(keyword + ps.text, Date.now()); | ||
const allureStep = currentTest.startStep(keyword + ps.text, Date.now()); | ||
this.allureSteps.set(data.testStepId, allureStep); | ||
@@ -309,4 +372,5 @@ } | ||
var _a; | ||
const currentTest = this.runningTestsMap.get(data.testCaseStartedId); | ||
(_a = this.testCaseTestStepsResults.get(data.testCaseStartedId)) === null || _a === void 0 ? void 0 : _a.push(data.testStepResult); | ||
if (!this.currentTest) { | ||
if (!currentTest) { | ||
return; | ||
@@ -313,0 +377,0 @@ } |
{ | ||
"name": "allure-cucumberjs", | ||
"version": "2.0.0-beta.18", | ||
"version": "2.0.0-beta.19", | ||
"description": "Allure Cucumber.JS integration", | ||
@@ -27,4 +27,5 @@ "license": "Apache-2.0", | ||
"@types/node": "^16.7.8", | ||
"@types/sinon": "^10.0.11", | ||
"@types/verror": "^1.10.3", | ||
"allure-mocha": "2.0.0-beta.18", | ||
"allure-mocha": "2.0.0-beta.19", | ||
"chai": "^4.3.4", | ||
@@ -40,2 +41,3 @@ "chai-like": "^1.1.1", | ||
"rimraf": "^3.0.2", | ||
"sinon": "^14.0.0", | ||
"ts-node": "^10.2.1", | ||
@@ -51,3 +53,3 @@ "typescript": "^4.4.2", | ||
"@cucumber/messages": "^19.1.2", | ||
"allure-js-commons": "2.0.0-beta.18" | ||
"allure-js-commons": "2.0.0-beta.19" | ||
}, | ||
@@ -54,0 +56,0 @@ "files": [ |
@@ -16,16 +16,24 @@ # allure-cucumberjs | ||
{ | ||
labels: { | ||
epic: [/@feature:(.*)/], | ||
severity: [/@severity:(.*)/] | ||
}, | ||
links: { | ||
issue: { | ||
labels: [ | ||
{ | ||
pattern: [/@feature:(.*)/], | ||
name: "epic" | ||
}, | ||
{ | ||
pattern: [/@severity:(.*)/], | ||
name: "severity" | ||
} | ||
], | ||
links: [ | ||
{ | ||
pattern: [/@issue=(.*)/], | ||
type: "issue", | ||
urlTemplate: "http://localhost:8080/issue/%s" | ||
}, | ||
tms: { | ||
{ | ||
pattern: [/@tms=(.*)/], | ||
type: "tms", | ||
urlTemplate: "http://localhost:8080/tms/%s" | ||
} | ||
} | ||
] | ||
} | ||
@@ -32,0 +40,0 @@ ); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
58044
579
98
0
22
+ Addedallure-js-commons@2.0.0-beta.19(transitive)
- Removedallure-js-commons@2.0.0-beta.18(transitive)