@zohodesk/testinglibrary 0.1.8 → 0.1.9
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.
- package/.babelrc +3 -0
- package/build/bdd-framework/cli/commands/env.js +1 -1
- package/build/bdd-framework/config/configDir.js +35 -0
- package/build/bdd-framework/config/enrichReporterData.js +23 -0
- package/build/bdd-framework/config/index.js +10 -6
- package/build/bdd-framework/cucumber/createTestStep.js +43 -0
- package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +126 -0
- package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +72 -0
- package/build/bdd-framework/cucumber/formatter/PickleParser.js +25 -0
- package/build/bdd-framework/cucumber/formatter/durationHelpers.js +13 -0
- package/build/bdd-framework/cucumber/formatter/getColorFns.js +57 -0
- package/build/bdd-framework/cucumber/formatter/index.js +16 -0
- package/build/bdd-framework/cucumber/formatter/locationHelpers.js +16 -0
- package/build/bdd-framework/cucumber/loadFeatures.js +62 -31
- package/build/bdd-framework/cucumber/loadSteps.js +7 -0
- package/build/bdd-framework/cucumber/resolveFeaturePaths.js +62 -0
- package/build/bdd-framework/cucumber/stepArguments.js +21 -0
- package/build/bdd-framework/cucumber/valueChecker.js +23 -0
- package/build/bdd-framework/gen/formatter.js +11 -23
- package/build/bdd-framework/gen/index.js +41 -20
- package/build/bdd-framework/gen/testFile.js +69 -26
- package/build/bdd-framework/gen/testMeta.js +60 -0
- package/build/bdd-framework/gen/testNode.js +11 -12
- package/build/bdd-framework/hooks/scenario.js +29 -6
- package/build/bdd-framework/hooks/worker.js +7 -1
- package/build/bdd-framework/index.js +8 -1
- package/build/bdd-framework/playwright/getLocationInFile.js +36 -9
- package/build/bdd-framework/playwright/loadUtils.js +33 -0
- package/build/bdd-framework/playwright/transform.js +5 -1
- package/build/bdd-framework/reporter/cucumber/base.js +57 -0
- package/build/bdd-framework/reporter/cucumber/custom.js +73 -0
- package/build/bdd-framework/reporter/cucumber/helper.js +12 -0
- package/build/bdd-framework/reporter/cucumber/html.js +35 -0
- package/build/bdd-framework/reporter/cucumber/index.js +74 -0
- package/build/bdd-framework/reporter/cucumber/json.js +312 -0
- package/build/bdd-framework/reporter/cucumber/junit.js +205 -0
- package/build/bdd-framework/reporter/cucumber/message.js +20 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +64 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +196 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +43 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +52 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +105 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +70 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +45 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +27 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +38 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +128 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +126 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +102 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +50 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +88 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +30 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwUtils.js +51 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +35 -0
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +5 -0
- package/build/bdd-framework/run/StepInvoker.js +21 -26
- package/build/bdd-framework/run/bddDataAttachment.js +46 -0
- package/build/bdd-framework/run/bddFixtures.js +31 -10
- package/build/bdd-framework/run/bddWorld.js +5 -2
- package/build/bdd-framework/run/bddWorldInternal.js +15 -0
- package/build/bdd-framework/snippets/index.js +3 -7
- package/build/bdd-framework/stepDefinitions/defineStep.js +1 -1
- package/build/bdd-framework/utils/AutofillMap.js +20 -0
- package/build/bdd-framework/utils/index.js +23 -0
- package/build/bdd-framework/utils/stripAnsiEscapes.js +20 -0
- package/build/core/playwright/builtInFixtures/cacheLayer.js +1 -0
- package/build/core/playwright/builtInFixtures/context.js +18 -1
- package/build/core/playwright/builtInFixtures/i18N.js +33 -0
- package/build/core/playwright/builtInFixtures/index.js +17 -1
- package/build/core/playwright/builtInFixtures/page.js +69 -39
- package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
- package/build/core/playwright/clear-caches.js +19 -8
- package/build/core/playwright/codegen.js +4 -4
- package/build/core/playwright/constants/browserTypes.js +12 -0
- package/build/core/playwright/custom-commands.js +1 -1
- package/build/core/playwright/env-initializer.js +10 -6
- package/build/core/playwright/helpers/auth/accountLogin.js +18 -0
- package/build/core/playwright/helpers/auth/checkAuthCookies.js +47 -0
- package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
- package/build/core/playwright/helpers/auth/getUsers.js +72 -0
- package/build/core/playwright/helpers/auth/index.js +58 -0
- package/build/core/playwright/helpers/auth/loginSteps.js +36 -0
- package/build/core/playwright/helpers/configFileNameProvider.js +17 -0
- package/build/core/playwright/helpers/getUserFixtures.js +23 -0
- package/build/core/playwright/helpers/mergeObjects.js +13 -0
- package/build/core/playwright/helpers/parseUserArgs.js +11 -0
- package/build/core/playwright/index.js +51 -1
- package/build/core/playwright/readConfigFile.js +23 -12
- package/build/core/playwright/report-generator.js +7 -7
- package/build/core/playwright/setup/config-creator.js +4 -1
- package/build/core/playwright/setup/config-utils.js +43 -7
- package/build/core/playwright/setup/custom-reporter.js +3 -2
- package/build/core/playwright/test-runner.js +19 -8
- package/build/core/playwright/types.js +43 -0
- package/build/index.d.ts +21 -2
- package/build/index.js +48 -11
- package/build/lib/cli.js +12 -3
- package/build/lib/post-install.js +18 -10
- package/build/setup-folder-structure/helper.js +3 -0
- package/build/utils/cliArgsToObject.js +5 -1
- package/build/utils/fileUtils.js +3 -0
- package/build/utils/rootPath.js +16 -9
- package/changelog.md +13 -0
- package/npm-shrinkwrap.json +18 -12
- package/package.json +6 -4
- package/build/bdd-framework/config/dir.js +0 -27
- package/build/bdd-framework/cucumber/loadSources.js +0 -57
- /package/build/bdd-framework/cucumber/{gherkin.d.js → types.js} +0 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var messages = _interopRequireWildcard(require("@cucumber/messages"));
|
|
9
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
10
|
+
var GherkinDocumentParser = _interopRequireWildcard(require("../../cucumber/formatter/GherkinDocumentParser"));
|
|
11
|
+
var PickleParser = _interopRequireWildcard(require("../../cucumber/formatter/PickleParser"));
|
|
12
|
+
var _valueChecker = require("../../cucumber/valueChecker");
|
|
13
|
+
var _stepArguments = require("../../cucumber/stepArguments");
|
|
14
|
+
var _durationHelpers = require("../../cucumber/formatter/durationHelpers");
|
|
15
|
+
var _locationHelpers = require("../../cucumber/formatter/locationHelpers");
|
|
16
|
+
var _GherkinDocument = require("./messagesBuilder/GherkinDocument");
|
|
17
|
+
var _Projects = require("./messagesBuilder/Projects");
|
|
18
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
+
/**
|
|
21
|
+
* Cucumber json reporter.
|
|
22
|
+
* Based on: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/json_formatter.ts
|
|
23
|
+
*
|
|
24
|
+
* Although json reporter is marked as deprecated in CucumberJS docs
|
|
25
|
+
* (see https://github.com/cucumber/cucumber-js/blob/main/docs/formatters.md#json),
|
|
26
|
+
* this decision was rolled back:
|
|
27
|
+
* (see https://github.com/cucumber/json-formatter/issues/34).
|
|
28
|
+
*
|
|
29
|
+
* See also: separate tool to convert cucumber messages to cucumber json:
|
|
30
|
+
* https://github.com/vrymar/cucumber-json-report-formatter/tree/master
|
|
31
|
+
*/
|
|
32
|
+
/* eslint-disable max-lines, max-statements, max-nested-callbacks, complexity */
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
getGherkinExampleRuleMap,
|
|
36
|
+
getGherkinScenarioLocationMap,
|
|
37
|
+
getGherkinStepMap,
|
|
38
|
+
getGherkinScenarioMap
|
|
39
|
+
} = GherkinDocumentParser;
|
|
40
|
+
const {
|
|
41
|
+
getScenarioDescription,
|
|
42
|
+
getPickleStepMap,
|
|
43
|
+
getStepKeyword
|
|
44
|
+
} = PickleParser;
|
|
45
|
+
class JsonReporter extends _base.default {
|
|
46
|
+
userOptions;
|
|
47
|
+
// for now omit step definitions
|
|
48
|
+
supportCodeLibrary = {
|
|
49
|
+
stepDefinitions: []
|
|
50
|
+
};
|
|
51
|
+
constructor(internalOptions, userOptions = {}) {
|
|
52
|
+
super(internalOptions);
|
|
53
|
+
this.userOptions = userOptions;
|
|
54
|
+
this.setOutputStream(this.userOptions.outputFile);
|
|
55
|
+
this.eventBroadcaster.on('envelope', envelope => {
|
|
56
|
+
if ((0, _valueChecker.doesHaveValue)(envelope.testRunFinished)) {
|
|
57
|
+
this.onTestRunFinished();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
convertNameToId(obj) {
|
|
62
|
+
return obj.name.replace(/ /g, '-').toLowerCase();
|
|
63
|
+
}
|
|
64
|
+
formatDataTable(dataTable) {
|
|
65
|
+
return {
|
|
66
|
+
rows: dataTable.rows.map(row => ({
|
|
67
|
+
cells: row.cells.map(x => x.value)
|
|
68
|
+
}))
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
formatDocString(docString, gherkinStep) {
|
|
72
|
+
var _gherkinStep$docStrin;
|
|
73
|
+
return {
|
|
74
|
+
content: docString.content,
|
|
75
|
+
line: (_gherkinStep$docStrin = gherkinStep.docString) === null || _gherkinStep$docStrin === void 0 ? void 0 : _gherkinStep$docStrin.location.line
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
formatStepArgument(stepArgument, gherkinStep) {
|
|
79
|
+
if ((0, _valueChecker.doesNotHaveValue)(stepArgument)) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
return [(0, _stepArguments.parseStepArgument)(stepArgument, {
|
|
83
|
+
dataTable: dataTable => this.formatDataTable(dataTable),
|
|
84
|
+
docString: docString => this.formatDocString(docString, gherkinStep)
|
|
85
|
+
})];
|
|
86
|
+
}
|
|
87
|
+
onTestRunFinished() {
|
|
88
|
+
const groupedTestCaseAttempts = {};
|
|
89
|
+
this.eventDataCollector.getTestCaseAttempts().forEach(testCaseAttempt => {
|
|
90
|
+
if (!testCaseAttempt.willBeRetried) {
|
|
91
|
+
const uri = testCaseAttempt.pickle.uri;
|
|
92
|
+
if ((0, _valueChecker.doesNotHaveValue)(groupedTestCaseAttempts[uri])) {
|
|
93
|
+
groupedTestCaseAttempts[uri] = [];
|
|
94
|
+
}
|
|
95
|
+
groupedTestCaseAttempts[uri].push(testCaseAttempt);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
const features = Object.keys(groupedTestCaseAttempts).map(uri => {
|
|
99
|
+
const group = groupedTestCaseAttempts[uri];
|
|
100
|
+
const {
|
|
101
|
+
gherkinDocument
|
|
102
|
+
} = group[0];
|
|
103
|
+
const gherkinStepMap = getGherkinStepMap(gherkinDocument);
|
|
104
|
+
const gherkinScenarioMap = getGherkinScenarioMap(gherkinDocument);
|
|
105
|
+
const gherkinExampleRuleMap = getGherkinExampleRuleMap(gherkinDocument);
|
|
106
|
+
const gherkinScenarioLocationMap = getGherkinScenarioLocationMap(gherkinDocument);
|
|
107
|
+
const elements = group.map(testCaseAttempt => {
|
|
108
|
+
const {
|
|
109
|
+
pickle
|
|
110
|
+
} = testCaseAttempt;
|
|
111
|
+
const pickleStepMap = getPickleStepMap(pickle);
|
|
112
|
+
let isBeforeHook = true;
|
|
113
|
+
const steps = testCaseAttempt.testCase.testSteps.map(testStep => {
|
|
114
|
+
isBeforeHook = isBeforeHook && !(0, _valueChecker.doesHaveValue)(testStep.pickleStepId);
|
|
115
|
+
return this.getStepData({
|
|
116
|
+
isBeforeHook,
|
|
117
|
+
gherkinStepMap,
|
|
118
|
+
pickleStepMap,
|
|
119
|
+
testStep,
|
|
120
|
+
testStepAttachments: testCaseAttempt.stepAttachments[testStep.id],
|
|
121
|
+
testStepResult: testCaseAttempt.stepResults[testStep.id]
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
return this.getScenarioData({
|
|
125
|
+
feature: gherkinDocument.feature,
|
|
126
|
+
gherkinScenarioLocationMap,
|
|
127
|
+
gherkinExampleRuleMap,
|
|
128
|
+
gherkinScenarioMap,
|
|
129
|
+
pickle,
|
|
130
|
+
steps
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
return this.getFeatureData({
|
|
134
|
+
gherkinDocument,
|
|
135
|
+
elements
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
this.outputStream.write(JSON.stringify(features, null, 2));
|
|
139
|
+
}
|
|
140
|
+
getFeatureData({
|
|
141
|
+
gherkinDocument,
|
|
142
|
+
elements
|
|
143
|
+
}) {
|
|
144
|
+
const meta = _GherkinDocument.GherkinDocumentMessage.extractMeta(gherkinDocument);
|
|
145
|
+
const feature = gherkinDocument.feature;
|
|
146
|
+
const featureNameWithProject = (0, _Projects.getFeatureNameWithProject)(meta.projectName, feature.name);
|
|
147
|
+
return {
|
|
148
|
+
description: feature.description,
|
|
149
|
+
elements,
|
|
150
|
+
id: this.convertNameToId({
|
|
151
|
+
name: featureNameWithProject
|
|
152
|
+
}),
|
|
153
|
+
line: feature.location.line,
|
|
154
|
+
keyword: feature.keyword,
|
|
155
|
+
name: this.userOptions.addProjectToFeatureName ? featureNameWithProject : feature.name,
|
|
156
|
+
tags: this.getFeatureTags(feature),
|
|
157
|
+
uri: meta.originalUri,
|
|
158
|
+
metadata: this.getFeatureMetadata(gherkinDocument)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
getFeatureMetadata(gherkinDocument) {
|
|
162
|
+
if (!this.userOptions.addMetadata) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const meta = _GherkinDocument.GherkinDocumentMessage.extractMeta(gherkinDocument);
|
|
166
|
+
const metadata = {
|
|
167
|
+
Project: meta.projectName || '',
|
|
168
|
+
Browser: meta.browserName || ''
|
|
169
|
+
};
|
|
170
|
+
return this.userOptions.addMetadata === 'object' ? metadata : Object.keys(metadata).map(name => ({
|
|
171
|
+
name,
|
|
172
|
+
value: metadata[name]
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
getScenarioData({
|
|
176
|
+
feature,
|
|
177
|
+
gherkinScenarioLocationMap,
|
|
178
|
+
gherkinExampleRuleMap,
|
|
179
|
+
gherkinScenarioMap,
|
|
180
|
+
pickle,
|
|
181
|
+
steps
|
|
182
|
+
}) {
|
|
183
|
+
const description = getScenarioDescription({
|
|
184
|
+
pickle,
|
|
185
|
+
gherkinScenarioMap
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
description,
|
|
189
|
+
id: this.formatScenarioId({
|
|
190
|
+
feature,
|
|
191
|
+
pickle,
|
|
192
|
+
gherkinExampleRuleMap
|
|
193
|
+
}),
|
|
194
|
+
keyword: gherkinScenarioMap[pickle.astNodeIds[0]].keyword,
|
|
195
|
+
line: gherkinScenarioLocationMap[pickle.astNodeIds[pickle.astNodeIds.length - 1]].line,
|
|
196
|
+
name: pickle.name,
|
|
197
|
+
steps,
|
|
198
|
+
tags: this.getScenarioTags({
|
|
199
|
+
feature,
|
|
200
|
+
pickle,
|
|
201
|
+
gherkinScenarioMap
|
|
202
|
+
}),
|
|
203
|
+
type: 'scenario'
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
formatScenarioId({
|
|
207
|
+
feature,
|
|
208
|
+
pickle,
|
|
209
|
+
gherkinExampleRuleMap
|
|
210
|
+
}) {
|
|
211
|
+
let parts;
|
|
212
|
+
const rule = gherkinExampleRuleMap[pickle.astNodeIds[0]];
|
|
213
|
+
if ((0, _valueChecker.doesHaveValue)(rule)) {
|
|
214
|
+
parts = [feature, rule, pickle];
|
|
215
|
+
} else {
|
|
216
|
+
parts = [feature, pickle];
|
|
217
|
+
}
|
|
218
|
+
return parts.map(part => this.convertNameToId(part)).join(';');
|
|
219
|
+
}
|
|
220
|
+
getStepData({
|
|
221
|
+
isBeforeHook,
|
|
222
|
+
gherkinStepMap,
|
|
223
|
+
pickleStepMap,
|
|
224
|
+
testStep,
|
|
225
|
+
testStepAttachments,
|
|
226
|
+
testStepResult
|
|
227
|
+
}) {
|
|
228
|
+
const data = {};
|
|
229
|
+
if ((0, _valueChecker.doesHaveValue)(testStep.pickleStepId)) {
|
|
230
|
+
const pickleStep = pickleStepMap[testStep.pickleStepId];
|
|
231
|
+
data.arguments = this.formatStepArgument(pickleStep.argument, gherkinStepMap[pickleStep.astNodeIds[0]]);
|
|
232
|
+
data.keyword = getStepKeyword({
|
|
233
|
+
pickleStep,
|
|
234
|
+
gherkinStepMap
|
|
235
|
+
});
|
|
236
|
+
data.line = gherkinStepMap[pickleStep.astNodeIds[0]].location.line;
|
|
237
|
+
data.name = pickleStep.text;
|
|
238
|
+
} else {
|
|
239
|
+
data.keyword = isBeforeHook ? 'Before' : 'After';
|
|
240
|
+
data.hidden = true;
|
|
241
|
+
}
|
|
242
|
+
if ((0, _valueChecker.doesHaveValue)(testStep.stepDefinitionIds) && testStep.stepDefinitionIds.length === 1) {
|
|
243
|
+
const stepDefinition = this.supportCodeLibrary.stepDefinitions.find(s => {
|
|
244
|
+
var _testStep$stepDefinit;
|
|
245
|
+
return s.id === ((_testStep$stepDefinit = testStep.stepDefinitionIds) === null || _testStep$stepDefinit === void 0 ? void 0 : _testStep$stepDefinit[0]);
|
|
246
|
+
});
|
|
247
|
+
if ((0, _valueChecker.doesHaveValue)(stepDefinition)) {
|
|
248
|
+
data.match = {
|
|
249
|
+
location: (0, _locationHelpers.formatLocation)(stepDefinition)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const {
|
|
254
|
+
message,
|
|
255
|
+
status
|
|
256
|
+
} = testStepResult;
|
|
257
|
+
data.result = {
|
|
258
|
+
status: messages.TestStepResultStatus[status].toLowerCase()
|
|
259
|
+
};
|
|
260
|
+
if ((0, _valueChecker.doesHaveValue)(testStepResult.duration)) {
|
|
261
|
+
data.result.duration = (0, _durationHelpers.durationToNanoseconds)(testStepResult.duration);
|
|
262
|
+
}
|
|
263
|
+
if (status === messages.TestStepResultStatus.FAILED && (0, _valueChecker.doesHaveValue)(message)) {
|
|
264
|
+
data.result.error_message = message;
|
|
265
|
+
}
|
|
266
|
+
const allowedAttachments = this.getAllowedAttachments(testStepAttachments);
|
|
267
|
+
if (allowedAttachments && allowedAttachments.length > 0) {
|
|
268
|
+
data.embeddings = allowedAttachments.map(attachment => ({
|
|
269
|
+
data: attachment.contentEncoding === messages.AttachmentContentEncoding.IDENTITY ? Buffer.from(attachment.body).toString('base64') : attachment.body,
|
|
270
|
+
mime_type: attachment.mediaType
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
return data;
|
|
274
|
+
}
|
|
275
|
+
getFeatureTags(feature) {
|
|
276
|
+
return feature.tags.map(tagData => ({
|
|
277
|
+
name: tagData.name,
|
|
278
|
+
line: tagData.location.line
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
getScenarioTags({
|
|
282
|
+
feature,
|
|
283
|
+
pickle,
|
|
284
|
+
gherkinScenarioMap
|
|
285
|
+
}) {
|
|
286
|
+
const scenario = gherkinScenarioMap[pickle.astNodeIds[0]];
|
|
287
|
+
return pickle.tags.map(tagData => this.getScenarioTag(tagData, feature, scenario));
|
|
288
|
+
}
|
|
289
|
+
getScenarioTag(tagData, feature, scenario) {
|
|
290
|
+
var _tag$location;
|
|
291
|
+
const byAstNodeId = tag => tag.id === tagData.astNodeId;
|
|
292
|
+
const flatten = (acc, val) => acc.concat(val);
|
|
293
|
+
const tag = feature.tags.find(byAstNodeId) || scenario.tags.find(byAstNodeId) || scenario.examples.map(e => e.tags).reduce((acc, val) => flatten(acc, val), []).find(byAstNodeId);
|
|
294
|
+
return {
|
|
295
|
+
name: tagData.name,
|
|
296
|
+
line: tag === null || tag === void 0 || (_tag$location = tag.location) === null || _tag$location === void 0 ? void 0 : _tag$location.line
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
getAllowedAttachments(testStepAttachments) {
|
|
300
|
+
const {
|
|
301
|
+
skipAttachments
|
|
302
|
+
} = this.userOptions;
|
|
303
|
+
if (Array.isArray(skipAttachments)) {
|
|
304
|
+
return testStepAttachments === null || testStepAttachments === void 0 ? void 0 : testStepAttachments.filter(attachment => {
|
|
305
|
+
return !skipAttachments.includes(attachment.mediaType);
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
return skipAttachments ? [] : testStepAttachments;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
exports.default = JsonReporter;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _xmlbuilder = _interopRequireDefault(require("xmlbuilder"));
|
|
9
|
+
var _messages = require("@cucumber/messages");
|
|
10
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
11
|
+
var _valueChecker = require("../../cucumber/valueChecker");
|
|
12
|
+
var _GherkinDocumentParser = require("../../cucumber/formatter/GherkinDocumentParser");
|
|
13
|
+
var _PickleParser = require("../../cucumber/formatter/PickleParser");
|
|
14
|
+
var _GherkinDocument = require("./messagesBuilder/GherkinDocument");
|
|
15
|
+
var _Projects = require("./messagesBuilder/Projects");
|
|
16
|
+
/**
|
|
17
|
+
* Cucumber junit reporter.
|
|
18
|
+
* Based on: https://github.com/cucumber/cucumber-js/blob/main/src/formatter/junit_formatter.ts
|
|
19
|
+
* Junit spec(ish): https://github.com/testmoapp/junitxml
|
|
20
|
+
* See also: https://github.com/cucumber/cucumber-junit-xml-formatter
|
|
21
|
+
* See also: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/reporters/junit.ts
|
|
22
|
+
*/
|
|
23
|
+
/* eslint-disable complexity, max-lines, max-statements */
|
|
24
|
+
|
|
25
|
+
class JunitReporter extends _base.default {
|
|
26
|
+
userOptions;
|
|
27
|
+
names = {};
|
|
28
|
+
constructor(internalOptions, userOptions = {}) {
|
|
29
|
+
super(internalOptions);
|
|
30
|
+
this.userOptions = userOptions;
|
|
31
|
+
this.setOutputStream(this.userOptions.outputFile);
|
|
32
|
+
this.eventBroadcaster.on('envelope', envelope => {
|
|
33
|
+
if ((0, _valueChecker.doesHaveValue)(envelope.testRunFinished)) {
|
|
34
|
+
this.onTestRunFinished();
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
get suiteName() {
|
|
39
|
+
return (0, _valueChecker.valueOrDefault)(this.userOptions.suiteName, 'cucumber-js');
|
|
40
|
+
}
|
|
41
|
+
getTestCases() {
|
|
42
|
+
return this.eventDataCollector.getTestCaseAttempts().filter(attempt => !attempt.willBeRetried);
|
|
43
|
+
}
|
|
44
|
+
getTestSteps(testCaseAttempt, gherkinStepMap, pickleStepMap) {
|
|
45
|
+
return testCaseAttempt.testCase.testSteps.map(testStep => {
|
|
46
|
+
const isBeforeHook = !(0, _valueChecker.doesHaveValue)(testStep.pickleStepId);
|
|
47
|
+
return this.getTestStep({
|
|
48
|
+
isBeforeHook,
|
|
49
|
+
gherkinStepMap,
|
|
50
|
+
pickleStepMap,
|
|
51
|
+
testStep,
|
|
52
|
+
testStepAttachments: testCaseAttempt.stepAttachments[testStep.id],
|
|
53
|
+
testStepResult: testCaseAttempt.stepResults[testStep.id]
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getTestStep({
|
|
58
|
+
isBeforeHook,
|
|
59
|
+
gherkinStepMap,
|
|
60
|
+
pickleStepMap,
|
|
61
|
+
testStep,
|
|
62
|
+
testStepAttachments,
|
|
63
|
+
testStepResult
|
|
64
|
+
}) {
|
|
65
|
+
const data = {};
|
|
66
|
+
if (testStep.pickleStepId) {
|
|
67
|
+
const pickleStep = pickleStepMap[testStep.pickleStepId];
|
|
68
|
+
data.keyword = (0, _PickleParser.getStepKeyword)({
|
|
69
|
+
pickleStep,
|
|
70
|
+
gherkinStepMap
|
|
71
|
+
});
|
|
72
|
+
data.line = gherkinStepMap[pickleStep.astNodeIds[0]].location.line;
|
|
73
|
+
data.name = pickleStep.text;
|
|
74
|
+
} else {
|
|
75
|
+
data.keyword = isBeforeHook ? 'Before' : 'After';
|
|
76
|
+
data.hidden = true;
|
|
77
|
+
}
|
|
78
|
+
data.result = testStepResult;
|
|
79
|
+
data.time = testStepResult.duration ? this.durationToSeconds(testStepResult.duration) : 0;
|
|
80
|
+
data.attachments = testStepAttachments;
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
getTestCaseResult(steps) {
|
|
84
|
+
const {
|
|
85
|
+
status,
|
|
86
|
+
message,
|
|
87
|
+
exception
|
|
88
|
+
} = (0, _messages.getWorstTestStepResult)(steps.map(step => step.result));
|
|
89
|
+
return {
|
|
90
|
+
status,
|
|
91
|
+
failure: message || exception ? {
|
|
92
|
+
type: (exception === null || exception === void 0 ? void 0 : exception.type) || '',
|
|
93
|
+
message: exception === null || exception === void 0 ? void 0 : exception.message,
|
|
94
|
+
detail: message || ''
|
|
95
|
+
} : undefined
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
durationToSeconds(duration) {
|
|
99
|
+
const NANOS_IN_SECOND = 1_000_000_000;
|
|
100
|
+
return (duration.seconds * NANOS_IN_SECOND + duration.nanos) / NANOS_IN_SECOND;
|
|
101
|
+
}
|
|
102
|
+
nameOrDefault(name, fallbackSuffix) {
|
|
103
|
+
if (!name) {
|
|
104
|
+
return `(unnamed ${fallbackSuffix})`;
|
|
105
|
+
}
|
|
106
|
+
return name;
|
|
107
|
+
}
|
|
108
|
+
getTestCaseName(featureName, rule, pickle) {
|
|
109
|
+
const pickleName = this.nameOrDefault(pickle.name, 'scenario');
|
|
110
|
+
const testCaseName = [featureName, rule ? this.nameOrDefault(rule.name, 'rule') : '', pickleName].filter(Boolean).join(_Projects.TITLE_SEPARATOR);
|
|
111
|
+
if (!this.names[featureName]) {
|
|
112
|
+
this.names[featureName] = [];
|
|
113
|
+
}
|
|
114
|
+
let index = 0;
|
|
115
|
+
while (this.names[featureName].includes(index > 0 ? `${testCaseName} [${index}]` : testCaseName)) {
|
|
116
|
+
index++;
|
|
117
|
+
}
|
|
118
|
+
const name = index > 0 ? `${testCaseName} [${index}]` : testCaseName;
|
|
119
|
+
this.names[featureName].push(name);
|
|
120
|
+
return name;
|
|
121
|
+
}
|
|
122
|
+
formatTestSteps(steps) {
|
|
123
|
+
return steps.filter(step => !step.hidden).map(step => {
|
|
124
|
+
const statusText = step.result.status.toLowerCase();
|
|
125
|
+
const maxLength = 80 - statusText.length - 3;
|
|
126
|
+
const stepText = `${step.keyword}${step.name}`.padEnd(maxLength, '.').substring(0, maxLength);
|
|
127
|
+
return `${stepText}...${statusText}`;
|
|
128
|
+
}).join('\n');
|
|
129
|
+
}
|
|
130
|
+
onTestRunFinished() {
|
|
131
|
+
const testCases = this.getTestCases();
|
|
132
|
+
const tests = testCases.map(testCaseAttempt => {
|
|
133
|
+
const {
|
|
134
|
+
gherkinDocument,
|
|
135
|
+
pickle
|
|
136
|
+
} = testCaseAttempt;
|
|
137
|
+
const {
|
|
138
|
+
feature
|
|
139
|
+
} = gherkinDocument;
|
|
140
|
+
if (!feature) {
|
|
141
|
+
throw new Error(`Gherkin document without feature: ${gherkinDocument.uri}`);
|
|
142
|
+
}
|
|
143
|
+
const meta = _GherkinDocument.GherkinDocumentMessage.extractMeta(gherkinDocument);
|
|
144
|
+
const gherkinExampleRuleMap = (0, _GherkinDocumentParser.getGherkinExampleRuleMap)(gherkinDocument);
|
|
145
|
+
const rule = gherkinExampleRuleMap[pickle.astNodeIds[0]];
|
|
146
|
+
const gherkinStepMap = (0, _GherkinDocumentParser.getGherkinStepMap)(gherkinDocument);
|
|
147
|
+
const pickleStepMap = (0, _PickleParser.getPickleStepMap)(pickle);
|
|
148
|
+
const steps = this.getTestSteps(testCaseAttempt, gherkinStepMap, pickleStepMap);
|
|
149
|
+
const stepDuration = steps.reduce((total, step) => total + (step.time || 0), 0);
|
|
150
|
+
const featureName = this.nameOrDefault(feature.name, 'feature');
|
|
151
|
+
const featureNameWithProject = (0, _Projects.getFeatureNameWithProject)(meta.projectName, featureName);
|
|
152
|
+
return {
|
|
153
|
+
classname: featureName,
|
|
154
|
+
// always add project to testcase name
|
|
155
|
+
// see: https://github.com/microsoft/playwright/issues/23432
|
|
156
|
+
name: this.getTestCaseName(featureNameWithProject, rule, pickle),
|
|
157
|
+
time: stepDuration,
|
|
158
|
+
result: this.getTestCaseResult(steps),
|
|
159
|
+
systemOutput: this.formatTestSteps(steps),
|
|
160
|
+
steps
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
const passed = tests.filter(item => item.result.status === _messages.TestStepResultStatus.PASSED).length;
|
|
164
|
+
const skipped = tests.filter(item => item.result.status === _messages.TestStepResultStatus.SKIPPED).length;
|
|
165
|
+
const failures = tests.length - passed - skipped;
|
|
166
|
+
const testSuite = {
|
|
167
|
+
name: this.suiteName,
|
|
168
|
+
tests,
|
|
169
|
+
failures,
|
|
170
|
+
skipped,
|
|
171
|
+
time: tests.reduce((total, test) => total + test.time, 0)
|
|
172
|
+
};
|
|
173
|
+
this.outputStream.write(this.buildXmlReport(testSuite));
|
|
174
|
+
}
|
|
175
|
+
buildXmlReport(testSuite) {
|
|
176
|
+
const xmlReport = _xmlbuilder.default.create('testsuite', {
|
|
177
|
+
encoding: 'UTF-8',
|
|
178
|
+
invalidCharReplacement: ''
|
|
179
|
+
}).att('failures', testSuite.failures).att('skipped', testSuite.skipped).att('name', testSuite.name).att('time', testSuite.time).att('tests', testSuite.tests.length);
|
|
180
|
+
testSuite.tests.forEach(test => {
|
|
181
|
+
const xmlTestCase = xmlReport.ele('testcase', {
|
|
182
|
+
classname: test.classname,
|
|
183
|
+
name: test.name,
|
|
184
|
+
time: test.time
|
|
185
|
+
});
|
|
186
|
+
if (test.result.status === _messages.TestStepResultStatus.SKIPPED) {
|
|
187
|
+
xmlTestCase.ele('skipped');
|
|
188
|
+
} else if (test.result.status !== _messages.TestStepResultStatus.PASSED) {
|
|
189
|
+
var _test$result$failure, _test$result$failure2, _test$result;
|
|
190
|
+
const xmlFailure = xmlTestCase.ele('failure', {
|
|
191
|
+
type: (_test$result$failure = test.result.failure) === null || _test$result$failure === void 0 ? void 0 : _test$result$failure.type,
|
|
192
|
+
message: (_test$result$failure2 = test.result.failure) === null || _test$result$failure2 === void 0 ? void 0 : _test$result$failure2.message
|
|
193
|
+
});
|
|
194
|
+
if ((_test$result = test.result) !== null && _test$result !== void 0 && _test$result.failure) {
|
|
195
|
+
xmlFailure.cdata(test.result.failure.detail);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
xmlTestCase.ele('system-out', {}).cdata(test.systemOutput);
|
|
199
|
+
});
|
|
200
|
+
return xmlReport.end({
|
|
201
|
+
pretty: true
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.default = JunitReporter;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
9
|
+
class MessageReporter extends _base.default {
|
|
10
|
+
userOptions;
|
|
11
|
+
constructor(internalOptions, userOptions = {}) {
|
|
12
|
+
super(internalOptions);
|
|
13
|
+
this.userOptions = userOptions;
|
|
14
|
+
this.setOutputStream(this.userOptions.outputFile);
|
|
15
|
+
this.eventBroadcaster.on('envelope', envelope => {
|
|
16
|
+
this.outputStream.write(JSON.stringify(envelope) + '\n');
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = MessageReporter;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AttachmentMapper = void 0;
|
|
7
|
+
var _AutofillMap = require("../../../utils/AutofillMap");
|
|
8
|
+
var _pwUtils = require("./pwUtils");
|
|
9
|
+
var _bddDataAttachment = require("../../../run/bddDataAttachment");
|
|
10
|
+
class AttachmentMapper {
|
|
11
|
+
result;
|
|
12
|
+
stepAttachments = new _AutofillMap.AutofillMap();
|
|
13
|
+
unusedAttachments = [];
|
|
14
|
+
constructor(result) {
|
|
15
|
+
this.result = result;
|
|
16
|
+
this.mapAttachments();
|
|
17
|
+
}
|
|
18
|
+
getStepAttachments(pwStep) {
|
|
19
|
+
return this.stepAttachments.get(pwStep) || [];
|
|
20
|
+
}
|
|
21
|
+
mapAttachments() {
|
|
22
|
+
const allAttachments = this.result.attachments.slice();
|
|
23
|
+
const attachmentSteps = (0, _pwUtils.collectStepsWithCategory)(this.result, 'attach');
|
|
24
|
+
attachmentSteps.forEach(attachmentStep => {
|
|
25
|
+
this.mapAttachment(attachmentStep, allAttachments);
|
|
26
|
+
});
|
|
27
|
+
this.unusedAttachments.push(...allAttachments);
|
|
28
|
+
this.mapUnusedAttachments();
|
|
29
|
+
}
|
|
30
|
+
mapAttachment(attachmentStep, allAttachments) {
|
|
31
|
+
const index = allAttachments.findIndex(a => getAttachmentStepTitle(a.name) === attachmentStep.title);
|
|
32
|
+
if (index === -1) {
|
|
33
|
+
throw new Error(`Attachment not found for step: ${attachmentStep.title}`);
|
|
34
|
+
}
|
|
35
|
+
const [foundAttachment] = allAttachments.splice(index, 1);
|
|
36
|
+
if ((0, _bddDataAttachment.isBddDataAttachment)(foundAttachment)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const parentStep = attachmentStep.parent;
|
|
40
|
+
// step.parent is empty:
|
|
41
|
+
// - in PW = 1.34 for screenshot attachment
|
|
42
|
+
// - in PW <= 1.40 when testInfo.attach() promise
|
|
43
|
+
// is awaited in the next async tick: 'attach' steps are on the top level
|
|
44
|
+
const stepAttachments = parentStep ? this.stepAttachments.getOrCreate(parentStep, () => []) : this.unusedAttachments;
|
|
45
|
+
stepAttachments.push(foundAttachment);
|
|
46
|
+
}
|
|
47
|
+
mapUnusedAttachments() {
|
|
48
|
+
if (!this.unusedAttachments.length) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// map unused attachments to the 'After Hooks' step
|
|
52
|
+
const afterHooksRoot = (0, _pwUtils.getHooksRootStep)(this.result, 'after');
|
|
53
|
+
if (!afterHooksRoot) {
|
|
54
|
+
throw new Error(`Can not find after hooks root to attach unused attachments.`);
|
|
55
|
+
}
|
|
56
|
+
const stepAttachments = this.stepAttachments.getOrCreate(afterHooksRoot, () => []);
|
|
57
|
+
stepAttachments.push(...this.unusedAttachments);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/worker/testInfo.ts#L413
|
|
61
|
+
exports.AttachmentMapper = AttachmentMapper;
|
|
62
|
+
function getAttachmentStepTitle(attachmentName) {
|
|
63
|
+
return `attach "${attachmentName}"`;
|
|
64
|
+
}
|