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

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