allure-cucumberjs 2.0.0-beta.2 → 2.0.0-beta.21

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