allure-cucumberjs 2.0.0-beta.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +188 -48
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +3 -2
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/CucumberAllureWorld.d.ts +25 -0
  7. package/dist/src/CucumberAllureWorld.js +102 -0
  8. package/dist/src/CucumberAllureWorld.js.map +1 -0
  9. package/dist/src/CucumberJSAllureReporter.d.ts +52 -67
  10. package/dist/src/CucumberJSAllureReporter.js +344 -222
  11. package/dist/src/CucumberJSAllureReporter.js.map +1 -1
  12. package/package.json +39 -28
  13. package/dist/src/CucumberAllureInterface.d.ts +0 -24
  14. package/dist/src/CucumberAllureInterface.js +0 -89
  15. package/dist/src/CucumberAllureInterface.js.map +0 -1
  16. package/dist/src/events/Example.d.ts +0 -8
  17. package/dist/src/events/Example.js +0 -26
  18. package/dist/src/events/Example.js.map +0 -1
  19. package/dist/src/events/GherkinDocument.d.ts +0 -17
  20. package/dist/src/events/GherkinDocument.js +0 -10
  21. package/dist/src/events/GherkinDocument.js.map +0 -1
  22. package/dist/src/events/GherkinExample.d.ts +0 -15
  23. package/dist/src/events/GherkinExample.js +0 -7
  24. package/dist/src/events/GherkinExample.js.map +0 -1
  25. package/dist/src/events/GherkinStep.d.ts +0 -17
  26. package/dist/src/events/GherkinStep.js +0 -7
  27. package/dist/src/events/GherkinStep.js.map +0 -1
  28. package/dist/src/events/GherkinTestCase.d.ts +0 -18
  29. package/dist/src/events/GherkinTestCase.js +0 -11
  30. package/dist/src/events/GherkinTestCase.js.map +0 -1
  31. package/dist/src/events/Result.d.ts +0 -5
  32. package/dist/src/events/Result.js +0 -7
  33. package/dist/src/events/Result.js.map +0 -1
  34. package/dist/src/events/SourceLocation.d.ts +0 -11
  35. package/dist/src/events/SourceLocation.js +0 -10
  36. package/dist/src/events/SourceLocation.js.map +0 -1
  37. package/dist/src/events/TestHookDefinition.d.ts +0 -8
  38. package/dist/src/events/TestHookDefinition.js +0 -3
  39. package/dist/src/events/TestHookDefinition.js.map +0 -1
  40. package/dist/src/utilities.d.ts +0 -7
  41. package/dist/src/utilities.js +0 -50
  42. package/dist/src/utilities.js.map +0 -1
  43. package/package-lock.json +0 -14
@@ -1,40 +1,76 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
3
25
  exports.CucumberJSAllureFormatter = exports.CucumberJSAllureFormatterConfig = exports.Allure = void 0;
4
- const cucumber_1 = require("cucumber");
26
+ const os_1 = __importDefault(require("os"));
27
+ const process_1 = __importDefault(require("process"));
28
+ const cucumber_1 = require("@cucumber/cucumber");
29
+ const messages = __importStar(require("@cucumber/messages"));
30
+ const messages_1 = require("@cucumber/messages");
5
31
  const allure_js_commons_1 = require("allure-js-commons");
6
- const SourceLocation_1 = require("./events/SourceLocation");
7
- const Example_1 = require("./events/Example");
8
- const CucumberAllureInterface_1 = require("./CucumberAllureInterface");
9
- const utilities_1 = require("./utilities");
10
- var allure_js_commons_2 = require("allure-js-commons");
11
- Object.defineProperty(exports, "Allure", { enumerable: true, get: function () { return allure_js_commons_2.Allure; } });
32
+ Object.defineProperty(exports, "Allure", { enumerable: true, get: function () { return allure_js_commons_1.Allure; } });
33
+ const internal_1 = require("allure-js-commons/internal");
34
+ const CucumberAllureWorld_1 = require("./CucumberAllureWorld");
12
35
  class CucumberJSAllureFormatterConfig {
13
36
  }
14
37
  exports.CucumberJSAllureFormatterConfig = CucumberJSAllureFormatterConfig;
38
+ const { ALLURE_HOST_NAME, ALLURE_THREAD_NAME } = process_1.default.env;
15
39
  class CucumberJSAllureFormatter extends cucumber_1.Formatter {
16
40
  constructor(options, allureRuntime, config) {
17
41
  super(options);
18
42
  this.allureRuntime = allureRuntime;
43
+ this.currentTestsMap = new Map();
44
+ this.hostname = ALLURE_HOST_NAME || os_1.default.hostname();
45
+ this.documentMap = new Map();
46
+ this.scenarioMap = new Map();
47
+ this.stepMap = new Map();
48
+ this.testStepMap = new Map();
49
+ this.pickleStepMap = new Map();
50
+ this.testCaseTestStepsResults = new Map();
51
+ this.pickleMap = new Map();
52
+ this.hookMap = new Map();
19
53
  this.sourceMap = new Map();
20
- this.stepsMap = new Map();
21
- this.featureMap = new Map();
22
- this.stepStack = [];
23
- this.currentGroup = null;
24
- this.currentTest = null;
25
- this.currentBefore = null;
26
- this.currentAfter = null;
27
- options.eventBroadcaster
28
- .on("source", this.onSource.bind(this))
29
- .on("gherkin-document", this.onGherkinDocument.bind(this))
30
- .on("test-case-prepared", this.onTestCasePrepared.bind(this))
31
- .on("test-case-started", this.onTestCaseStarted.bind(this))
32
- .on("test-step-started", this.onTestStepStarted.bind(this))
33
- .on("test-step-attachment", this.onTestStepAttachment.bind(this))
34
- .on("test-step-finished", this.onTestStepFinished.bind(this))
35
- .on("test-case-finished", this.onTestCaseFinished.bind(this));
36
- this.labels = config.labels || {};
37
- this.exceptionFormatter = function (message) {
54
+ this.testCaseMap = new Map();
55
+ this.testCaseStartedMap = new Map();
56
+ this.allureSteps = new Map();
57
+ this.convertStatus = (status) => {
58
+ switch (status) {
59
+ case messages_1.TestStepResultStatus.FAILED:
60
+ return allure_js_commons_1.Status.FAILED;
61
+ case messages_1.TestStepResultStatus.PASSED:
62
+ return allure_js_commons_1.Status.PASSED;
63
+ case messages_1.TestStepResultStatus.SKIPPED:
64
+ case messages_1.TestStepResultStatus.PENDING:
65
+ return allure_js_commons_1.Status.SKIPPED;
66
+ default:
67
+ return undefined;
68
+ }
69
+ };
70
+ options.eventBroadcaster.on("envelope", this.parseEnvelope.bind(this));
71
+ this.labelsMathers = config.labels || [];
72
+ this.linksMatchers = config.links || [];
73
+ this.exceptionFormatter = (message) => {
38
74
  if (config.exceptionFormatter !== undefined) {
39
75
  try {
40
76
  return config.exceptionFormatter(message);
@@ -45,230 +81,316 @@ class CucumberJSAllureFormatter extends cucumber_1.Formatter {
45
81
  }
46
82
  return message;
47
83
  };
48
- this.allureInterface = new CucumberAllureInterface_1.CucumberAllureInterface(this, this.allureRuntime);
49
- options.supportCodeLibrary.World.prototype.allure = this.allureInterface;
84
+ if (options.supportCodeLibrary.World === cucumber_1.World) {
85
+ options.supportCodeLibrary.World = CucumberAllureWorld_1.CucumberAllureWorld;
86
+ }
50
87
  this.beforeHooks = options.supportCodeLibrary.beforeTestCaseHookDefinitions;
51
88
  this.afterHooks = options.supportCodeLibrary.afterTestCaseHookDefinitions;
52
89
  }
53
- onSource(data) {
54
- this.sourceMap.set(data.uri, data.data.split(/\n/));
90
+ get tagsIgnorePatterns() {
91
+ const { linksMatchers, labelsMathers } = this;
92
+ return [...linksMatchers, ...labelsMathers].flatMap(({ pattern }) => pattern);
55
93
  }
56
- onGherkinDocument(data) {
57
- data.document.caseMap = new Map();
58
- data.document.stepMap = new Map();
59
- if (data.document.feature !== undefined) {
60
- for (const test of data.document.feature.children || []) {
61
- test.stepMap = new Map();
62
- if (test.type === "Background") {
63
- data.document.stepMap = new Map();
64
- for (const step of test.steps) {
65
- step.isBackground = true;
66
- data.document.stepMap.set(step.location.line, step);
67
- }
68
- }
69
- else {
70
- for (const step of test.steps) {
71
- test.stepMap.set(step.location.line, step);
72
- }
73
- }
74
- if (test.type === "ScenarioOutline") {
75
- for (const example of Example_1.examplesToSensibleFormat(test.examples || [])) {
76
- const copy = Object.assign({}, test);
77
- copy.example = example;
78
- data.document.caseMap.set(example.line, copy);
79
- }
80
- }
81
- else {
82
- data.document.caseMap.set(test.location.line, test);
83
- }
84
- }
94
+ parseEnvelope(envelope) {
95
+ if (envelope.gherkinDocument) {
96
+ this.onGherkinDocument(envelope.gherkinDocument);
85
97
  }
86
- this.featureMap.set(data.uri, data.document);
87
- }
88
- onTestCasePrepared(data) {
89
- this.stepsMap.clear();
90
- this.stepsMap.set(SourceLocation_1.SourceLocation.toKey(data), data.steps);
91
- this.currentBefore = null;
92
- this.currentAfter = null;
93
- }
94
- onTestCaseStarted(data) {
95
- const feature = this.featureMap.get(data.sourceLocation.uri);
96
- if (feature === undefined || feature.feature === undefined) {
97
- throw new Error("Unknown feature");
98
- }
99
- const test = feature.caseMap === undefined
100
- ? undefined : feature.caseMap.get(data.sourceLocation.line);
101
- if (test === undefined) {
102
- throw new Error("Unknown scenario");
103
- }
104
- this.currentGroup = this.allureRuntime.startGroup();
105
- this.currentTest =
106
- this.currentGroup.startTest(utilities_1.applyExample(test.name || "Unnamed test", test.example));
107
- const info = {
108
- uri: data.sourceLocation.uri,
109
- f: feature.feature.name,
110
- t: test.name,
111
- a: null
112
- };
113
- if (test.example !== undefined) {
114
- info.a = test.example.arguments;
115
- for (const prop in test.example.arguments) {
116
- if (!test.example.arguments[prop])
117
- continue;
118
- this.currentTest.addParameter(prop, test.example.arguments[prop]);
119
- }
98
+ else if (envelope.pickle) {
99
+ this.onPickle(envelope.pickle);
120
100
  }
121
- this.currentTest.historyId = utilities_1.hash(JSON.stringify(info));
122
- this.currentTest.addLabel(allure_js_commons_1.LabelName.THREAD, `${process.pid}`);
123
- this.currentTest.fullName = `${data.sourceLocation.uri}:${feature.feature.name}:${test.name}`;
124
- this.currentTest.addLabel(allure_js_commons_1.LabelName.FEATURE, feature.feature.name);
125
- this.currentTest.description = utilities_1.stripIndent(test.description || "");
126
- for (const tag of [...(test.tags || []), ...feature.feature.tags]) {
127
- this.currentTest.addLabel(allure_js_commons_1.LabelName.TAG, tag.name);
128
- for (const label in this.labels) {
129
- if (!this.labels[label])
130
- continue;
131
- for (const reg of this.labels[label]) {
132
- const match = tag.name.match(reg);
133
- if (match != null && match.length > 1) {
134
- this.currentTest.addLabel(label, match[1]);
135
- }
136
- }
137
- }
101
+ else if (envelope.testCase) {
102
+ this.onTestCase(envelope.testCase);
103
+ }
104
+ else if (envelope.testCaseStarted) {
105
+ this.onTestCaseStarted(envelope.testCaseStarted);
106
+ }
107
+ else if (envelope.testCaseFinished) {
108
+ this.onTestCaseFinished(envelope.testCaseFinished);
109
+ }
110
+ else if (envelope.attachment) {
111
+ this.onAttachment(envelope.attachment);
112
+ }
113
+ else if (envelope.hook) {
114
+ this.onHook(envelope.hook);
115
+ }
116
+ else if (envelope.source) {
117
+ this.onSource(envelope.source);
118
+ }
119
+ else if (envelope.testStepStarted) {
120
+ this.onTestStepStarted(envelope.testStepStarted);
121
+ }
122
+ else if (envelope.testStepFinished) {
123
+ this.onTestStepFinished(envelope.testStepFinished);
138
124
  }
139
125
  }
140
- onTestStepStarted(data) {
141
- const location = (this.stepsMap.get(SourceLocation_1.SourceLocation.toKey(data.testCase)) || [])[data.index];
142
- const feature = this.featureMap.get(data.testCase.sourceLocation.uri);
143
- if (feature === undefined)
144
- throw new Error("Unknown feature");
145
- const test = feature.caseMap === undefined
146
- ? undefined : feature.caseMap.get(data.testCase.sourceLocation.line);
147
- if (test === undefined)
148
- throw new Error("Unknown scenario");
149
- let step;
150
- if (location.sourceLocation !== undefined && feature.stepMap !== undefined) {
151
- step = test.stepMap.get(location.sourceLocation.line)
152
- || feature.stepMap.get(location.sourceLocation.line);
126
+ parseTagsLabels(tags) {
127
+ const labels = [];
128
+ if (this.labelsMathers.length === 0) {
129
+ return labels;
153
130
  }
154
- else {
155
- if (location.actionLocation === undefined)
156
- location.actionLocation = {
157
- uri: "unknown",
158
- line: -1
131
+ this.labelsMathers.forEach((matcher) => {
132
+ const matchedTags = tags.filter((tag) => matcher.pattern.some((pattern) => pattern.test(tag.name)));
133
+ const matchedLabels = matchedTags.map((tag) => {
134
+ const tagValue = tag.name.replace(/^@\S+:/, "");
135
+ return {
136
+ name: matcher.name,
137
+ value: tagValue,
159
138
  };
160
- step = {
161
- location: { line: -1 },
162
- text: `${location.actionLocation.uri}:${location.actionLocation.line}`,
163
- keyword: ""
164
- };
139
+ });
140
+ labels.push(...matchedLabels);
141
+ });
142
+ return labels;
143
+ }
144
+ parseTagsLinks(tags) {
145
+ const tagKeyRe = /^@\S+=/;
146
+ const links = [];
147
+ if (this.linksMatchers.length === 0) {
148
+ return links;
165
149
  }
166
- if (step === undefined)
167
- throw new Error("Unknown step");
168
- let stepText = utilities_1.applyExample(`${step.keyword}${step.text}`, test.example);
169
- const isAfter = this.afterHooks.find(({ uri, line }) => {
170
- if (location.actionLocation === undefined)
171
- return false;
172
- return uri === location.actionLocation.uri &&
173
- line === location.actionLocation.line;
150
+ this.linksMatchers.forEach((matcher) => {
151
+ const matchedTags = tags.filter((tag) => matcher.pattern.some((pattern) => pattern.test(tag.name)));
152
+ const matchedLinks = matchedTags.map((tag) => {
153
+ const tagValue = tag.name.replace(tagKeyRe, "");
154
+ return {
155
+ url: matcher.urlTemplate.replace(/%s$/, tagValue) || tagValue,
156
+ type: matcher.type,
157
+ };
158
+ });
159
+ links.push(...matchedLinks);
174
160
  });
175
- const isBefore = this.beforeHooks.find(({ uri, line }) => {
176
- if (location.actionLocation === undefined)
177
- return false;
178
- return uri === location.actionLocation.uri &&
179
- line === location.actionLocation.line;
161
+ return links;
162
+ }
163
+ onGherkinDocument(data) {
164
+ var _a, _b;
165
+ if (data.uri) {
166
+ this.documentMap.set(data.uri, data);
167
+ }
168
+ (_b = (_a = data.feature) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.forEach((fc) => {
169
+ if (fc.scenario) {
170
+ this.onScenario(fc.scenario);
171
+ }
180
172
  });
181
- if (step.isBackground) {
182
- if (this.currentBefore === null)
183
- this.currentBefore = this.currentGroup.addBefore();
173
+ }
174
+ onScenario(data) {
175
+ this.scenarioMap.set(data.id, data);
176
+ data.steps.forEach((step) => this.stepMap.set(step.id, step));
177
+ }
178
+ onPickle(data) {
179
+ this.pickleMap.set(data.id, data);
180
+ data.steps.forEach((ps) => this.pickleStepMap.set(ps.id, ps));
181
+ }
182
+ onTestCase(data) {
183
+ this.testCaseMap.set(data.id, data);
184
+ data.testSteps.forEach((ts) => this.testStepMap.set(ts.id, ts));
185
+ }
186
+ onTestCaseStarted(data) {
187
+ var _a, _b, _c;
188
+ const testCase = this.testCaseMap.get(data.testCaseId);
189
+ if (!testCase) {
190
+ console.error("onTestCaseStarted", "test case not found", data);
191
+ return;
184
192
  }
185
- else if (isBefore) {
186
- if (this.currentBefore === null)
187
- this.currentBefore = this.currentGroup.addBefore();
188
- stepText = `Before: ${isBefore.code.name || step.text}`;
193
+ const pickle = this.pickleMap.get(testCase.pickleId);
194
+ if (!pickle) {
195
+ console.error("onTestCaseStarted", "pickle not found", data);
196
+ return;
189
197
  }
190
- else if (isAfter) {
191
- if (this.currentAfter === null)
192
- this.currentAfter = this.currentGroup.addAfter();
193
- stepText = `After: ${isAfter.code.name || step.text}`;
198
+ const doc = this.documentMap.get(pickle.uri);
199
+ const scenarioId = (_a = pickle === null || pickle === void 0 ? void 0 : pickle.astNodeIds) === null || _a === void 0 ? void 0 : _a[0];
200
+ const scenario = this.scenarioMap.get(scenarioId);
201
+ const labels = this.parseTagsLabels((scenario === null || scenario === void 0 ? void 0 : scenario.tags) || []);
202
+ const links = this.parseTagsLinks((scenario === null || scenario === void 0 ? void 0 : scenario.tags) || []);
203
+ const currentTest = new allure_js_commons_1.AllureTest(this.allureRuntime, Date.now());
204
+ const thread = data.workerId || ALLURE_THREAD_NAME || process_1.default.pid.toString();
205
+ this.testCaseStartedMap.set(data.id, data);
206
+ this.testCaseTestStepsResults.set(data.id, []);
207
+ this.currentTestsMap.set(data.id, currentTest);
208
+ const fullName = `${pickle.uri}#${pickle.name}`;
209
+ const testCaseId = (0, allure_js_commons_1.md5)(fullName);
210
+ currentTest.name = pickle.name;
211
+ currentTest.fullName = fullName;
212
+ currentTest.testCaseId = testCaseId;
213
+ currentTest.historyId = testCaseId;
214
+ currentTest.addLabel(allure_js_commons_1.LabelName.HOST, this.hostname);
215
+ currentTest.addLabel(allure_js_commons_1.LabelName.LANGUAGE, "javascript");
216
+ currentTest.addLabel(allure_js_commons_1.LabelName.FRAMEWORK, "cucumberjs");
217
+ currentTest.addLabel(allure_js_commons_1.LabelName.THREAD, thread);
218
+ labels.forEach((label) => currentTest.addLabel(label.name, label.value));
219
+ links.forEach((link) => currentTest.addLink(link.url, link.name, link.type));
220
+ if (doc === null || doc === void 0 ? void 0 : doc.feature) {
221
+ currentTest.addLabel(allure_js_commons_1.LabelName.FEATURE, doc.feature.name);
194
222
  }
195
- else {
196
- if (this.currentBefore !== null)
197
- this.currentBefore = null;
198
- if (this.currentAfter !== null)
199
- this.currentAfter = null;
200
- }
201
- const allureStep = (this.currentAfter || this.currentBefore || this.currentTest).startStep(stepText);
202
- this.pushStep(allureStep);
203
- if (step.argument !== undefined) {
204
- if (step.argument.content !== undefined) {
205
- const file = this.allureRuntime.writeAttachment(step.argument.content, {
206
- contentType: allure_js_commons_1.ContentType.TEXT,
207
- });
208
- allureStep.addAttachment("Text", allure_js_commons_1.ContentType.TEXT, file);
209
- }
210
- if (step.argument.rows !== undefined) {
211
- const file = this.allureRuntime.writeAttachment(step.argument.rows.map(row => row.cells.map(cell => cell.value.replace(/\t/g, " ")).join("\t")).join("\n"), { contentType: allure_js_commons_1.ContentType.TSV });
212
- allureStep.addAttachment("Table", allure_js_commons_1.ContentType.TSV, file);
223
+ if (scenario) {
224
+ currentTest.addLabel(allure_js_commons_1.LabelName.SUITE, scenario.name);
225
+ }
226
+ if ((_b = pickle.tags) === null || _b === void 0 ? void 0 : _b.length) {
227
+ const filteredTags = pickle.tags.filter((tag) => !this.tagsIgnorePatterns.some((pattern) => pattern.test(tag.name)));
228
+ filteredTags.forEach((tag) => currentTest.addLabel(allure_js_commons_1.LabelName.TAG, tag.name));
229
+ }
230
+ if (!((_c = scenario === null || scenario === void 0 ? void 0 : scenario.examples) === null || _c === void 0 ? void 0 : _c.length)) {
231
+ return;
232
+ }
233
+ scenario.examples.forEach((example) => {
234
+ var _a;
235
+ const csvDataTableHeader = ((_a = example === null || example === void 0 ? void 0 : example.tableHeader) === null || _a === void 0 ? void 0 : _a.cells.map((cell) => cell.value).join(",")) || "";
236
+ const csvDataTableBody = (example === null || example === void 0 ? void 0 : example.tableBody.map((row) => row.cells.map((cell) => cell.value).join(",")).join("\n")) ||
237
+ "";
238
+ if (!csvDataTableHeader && !csvDataTableBody) {
239
+ return;
213
240
  }
241
+ const csvDataTable = `${csvDataTableHeader}\n${csvDataTableBody}\n`;
242
+ const attachmentFilename = this.allureRuntime.writeAttachment(csvDataTable, allure_js_commons_1.ContentType.CSV);
243
+ currentTest.addAttachment("Examples", {
244
+ contentType: allure_js_commons_1.ContentType.CSV,
245
+ }, attachmentFilename);
246
+ });
247
+ }
248
+ onAttachment(data) {
249
+ const currentTest = this.currentTestsMap.get((data === null || data === void 0 ? void 0 : data.testCaseStartedId) || "");
250
+ if (!currentTest) {
251
+ return;
252
+ }
253
+ const currentStep = this.allureSteps.get((data === null || data === void 0 ? void 0 : data.testStepId) || "");
254
+ if (!data) {
255
+ console.error("onAttachment", "attachment can't be empty");
256
+ return;
214
257
  }
258
+ const { fileName = "attachment", body, mediaType, contentEncoding } = data;
259
+ if (mediaType === internal_1.ALLURE_METADATA_CONTENT_TYPE) {
260
+ this.handleAllureAttachment({
261
+ test: currentTest,
262
+ step: currentStep,
263
+ metadata: JSON.parse(body),
264
+ });
265
+ return;
266
+ }
267
+ const encoding = Buffer.isEncoding(contentEncoding) ? contentEncoding : undefined;
268
+ const attachmentFilename = this.allureRuntime.writeAttachment(body, mediaType, encoding);
269
+ currentTest.addAttachment(fileName, {
270
+ contentType: mediaType,
271
+ }, attachmentFilename);
215
272
  }
216
- onTestStepAttachment(data) {
217
- if (this.currentStep === null)
218
- throw new Error("There is no step to add attachment to");
219
- const type = data.media.type;
220
- let content = data.data;
221
- if ([allure_js_commons_1.ContentType.JPEG, allure_js_commons_1.ContentType.PNG, allure_js_commons_1.ContentType.WEBM].indexOf(type) >= 0) {
222
- content = Buffer.from(content, "base64");
223
- }
224
- const file = this.allureRuntime.writeAttachment(content, { contentType: type });
225
- this.currentStep.addAttachment("attached", type, file);
273
+ handleAllureAttachment(payload) {
274
+ const { labels = [], links = [], parameter = [], steps = [], description, descriptionHtml, } = payload.metadata;
275
+ links.forEach((link) => payload.test.addLink(link.url, link.type, link.name));
276
+ labels.forEach((label) => payload.test.addLabel(label.name, label.value));
277
+ parameter.forEach(({ name, value, excluded, mode }) => payload.test.addParameter(name, value, {
278
+ excluded,
279
+ mode,
280
+ }));
281
+ steps.forEach((step) => {
282
+ this.handleAllureStep({
283
+ test: payload.test,
284
+ step: payload.step,
285
+ stepMetadata: step,
286
+ });
287
+ });
288
+ if (description) {
289
+ payload.test.description = description;
290
+ }
291
+ if (descriptionHtml) {
292
+ payload.test.descriptionHtml = descriptionHtml;
293
+ }
226
294
  }
227
- onTestStepFinished(data) {
228
- const currentStep = this.currentStep;
229
- if (currentStep === null)
230
- throw new Error("No current step defined");
231
- currentStep.status = utilities_1.statusTextToAllure(data.result.status);
232
- currentStep.stage = utilities_1.statusTextToStage(data.result.status);
233
- this.setException(currentStep, data.result.exception);
234
- currentStep.endStep();
235
- this.popStep();
295
+ handleAllureStep(payload) {
296
+ const step = allure_js_commons_1.AllureCommandStepExecutable.toExecutableItem(this.allureRuntime, payload.stepMetadata);
297
+ if (payload.step) {
298
+ payload.step.addStep(step);
299
+ return;
300
+ }
301
+ payload.test.addStep(step);
236
302
  }
237
303
  onTestCaseFinished(data) {
238
- if (this.currentTest === null || this.currentGroup === null) {
239
- throw new Error("No current test info");
240
- }
241
- this.currentTest.status = utilities_1.statusTextToAllure(data.result.status);
242
- this.currentTest.stage = utilities_1.statusTextToStage(data.result.status);
243
- this.setException(this.currentTest, data.result.exception);
244
- this.currentTest.endTest();
245
- this.currentGroup.endGroup();
246
- }
247
- setException(target, exception) {
248
- if (exception !== undefined) {
249
- if (typeof exception === "string") {
250
- target.detailsMessage = this.exceptionFormatter(exception);
251
- }
252
- else {
253
- target.detailsMessage =
254
- this.exceptionFormatter(exception.message || "Error.message === undefined");
255
- target.detailsTrace = exception.stack || "";
256
- }
304
+ const currentTest = this.currentTestsMap.get(data.testCaseStartedId);
305
+ if (!currentTest) {
306
+ console.error("onTestCaseFinished", "current test not found", data);
307
+ return;
257
308
  }
309
+ const testCaseStarted = this.testCaseStartedMap.get(data.testCaseStartedId);
310
+ if (!testCaseStarted) {
311
+ console.error("onTestCaseFinished", "testCaseStarted event not found", data);
312
+ return;
313
+ }
314
+ const testCase = this.testCaseMap.get(testCaseStarted.testCaseId);
315
+ if (!testCase) {
316
+ console.error("onTestCaseFinished", "testCase not found", data);
317
+ return;
318
+ }
319
+ const pickle = this.pickleMap.get(testCase.pickleId);
320
+ if (!pickle) {
321
+ console.error("onTestCaseFinished", "pickle not found", data);
322
+ return;
323
+ }
324
+ const testStepResults = this.testCaseTestStepsResults.get(testCaseStarted.id);
325
+ if (testStepResults === null || testStepResults === void 0 ? void 0 : testStepResults.length) {
326
+ const worstTestStepResult = messages.getWorstTestStepResult(testStepResults);
327
+ currentTest.status = currentTest.isAnyStepFailed
328
+ ? allure_js_commons_1.Status.FAILED
329
+ : this.convertStatus(worstTestStepResult.status);
330
+ currentTest.statusDetails = {
331
+ message: worstTestStepResult.message,
332
+ };
333
+ }
334
+ else {
335
+ currentTest.status = allure_js_commons_1.Status.PASSED;
336
+ }
337
+ currentTest.endTest(Date.now());
338
+ this.currentTestsMap.delete(data.testCaseStartedId);
258
339
  }
259
- pushStep(step) {
260
- this.stepStack.push(step);
340
+ onHook(data) {
341
+ this.hookMap.set(data.id, data);
261
342
  }
262
- popStep() {
263
- this.stepStack.pop();
343
+ onSource(data) {
344
+ if (data.uri) {
345
+ this.sourceMap.set(data.uri, data);
346
+ }
264
347
  }
265
- get currentStep() {
266
- if (this.stepStack.length > 0)
267
- return this.stepStack[this.stepStack.length - 1];
268
- return null;
348
+ onTestStepStarted(data) {
349
+ const currentTest = this.currentTestsMap.get(data.testCaseStartedId);
350
+ if (!currentTest) {
351
+ return;
352
+ }
353
+ const testStep = this.testStepMap.get(data.testStepId);
354
+ if (!testStep) {
355
+ console.error("onTestStepStarted", "can't find step", data);
356
+ return;
357
+ }
358
+ if (testStep.pickleStepId) {
359
+ const ps = this.pickleStepMap.get(testStep.pickleStepId);
360
+ if (!ps) {
361
+ return;
362
+ }
363
+ const keyword = ps.astNodeIds
364
+ .map((astNodeId) => this.stepMap.get(astNodeId))
365
+ .map((step) => step === null || step === void 0 ? void 0 : step.keyword)
366
+ .find((kw) => kw !== undefined) || "";
367
+ const { argument } = ps;
368
+ const allureStep = currentTest.startStep(keyword + ps.text, Date.now());
369
+ this.allureSteps.set(data.testStepId, allureStep);
370
+ if (!(argument === null || argument === void 0 ? void 0 : argument.dataTable)) {
371
+ return;
372
+ }
373
+ const csvDataTable = argument.dataTable.rows.reduce((acc, row) => `${acc + row.cells.map((cell) => cell.value).join(",")}\n`, "");
374
+ const attachmentFilename = this.allureRuntime.writeAttachment(csvDataTable, allure_js_commons_1.ContentType.CSV);
375
+ allureStep.addAttachment("Data table", {
376
+ contentType: allure_js_commons_1.ContentType.CSV,
377
+ }, attachmentFilename);
378
+ }
269
379
  }
270
- writeAttachment(content, options) {
271
- return this.allureRuntime.writeAttachment(content, options);
380
+ onTestStepFinished(data) {
381
+ var _a;
382
+ const currentTest = this.currentTestsMap.get(data.testCaseStartedId);
383
+ (_a = this.testCaseTestStepsResults.get(data.testCaseStartedId)) === null || _a === void 0 ? void 0 : _a.push(data.testStepResult);
384
+ if (!currentTest) {
385
+ return;
386
+ }
387
+ const allureStep = this.allureSteps.get(data.testStepId);
388
+ if (!allureStep) {
389
+ return;
390
+ }
391
+ allureStep.detailsMessage = data.testStepResult.message;
392
+ allureStep.status = this.convertStatus(data.testStepResult.status);
393
+ allureStep.endStep(Date.now());
272
394
  }
273
395
  }
274
396
  exports.CucumberJSAllureFormatter = CucumberJSAllureFormatter;