@zohodesk/testinglibrary 2.9.1 → 3.0.2

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 (136) hide show
  1. package/.gitlab-ci.yml +16 -23
  2. package/README.md +32 -1
  3. package/build/core/playwright/constants/fileMutexConfig.js +11 -0
  4. package/build/core/playwright/fixtures.js +24 -0
  5. package/build/core/playwright/helpers/auth/checkAuthCookies.js +2 -8
  6. package/build/core/playwright/helpers/auth/loginSteps.js +25 -18
  7. package/build/core/playwright/helpers/checkAuthDirectory.js +17 -0
  8. package/build/core/playwright/helpers/fileMutex.js +58 -0
  9. package/build/core/playwright/index.js +10 -23
  10. package/build/core/playwright/setup/config-creator.js +3 -3
  11. package/build/core/playwright/setup/config-utils.js +8 -25
  12. package/build/core/playwright/test-runner.js +1 -1
  13. package/build/decorators.d.ts +1 -1
  14. package/build/decorators.js +1 -1
  15. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  16. package/build/setup-folder-structure/samples/auth-setup-sample.js +14 -66
  17. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  18. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  19. package/build/setup-folder-structure/samples/settings.json +7 -0
  20. package/build/setup-folder-structure/setupProject.js +18 -5
  21. package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +94 -0
  22. package/nobdd/uat/conf/default/actors/index.js +1 -4
  23. package/nobdd/uat/conf/default/settings.json +1 -1
  24. package/nobdd/uat/conf/nobdd/uat.config.js +11 -4
  25. package/nobdd/uat/env-config.json +3 -3
  26. package/nobdd/uat/fixtures/setup.teardown.js +2 -1
  27. package/nobdd/uat/modules/nobdd/steps/VerifyNoBDD.feature.spec.js +3 -3
  28. package/nobdd/uat.config.js +8 -3
  29. package/package.json +8 -7
  30. package/build/bdd-framework/cli/commands/env.js +0 -42
  31. package/build/bdd-framework/cli/commands/export.js +0 -62
  32. package/build/bdd-framework/cli/commands/test.js +0 -64
  33. package/build/bdd-framework/cli/index.js +0 -11
  34. package/build/bdd-framework/cli/options.js +0 -19
  35. package/build/bdd-framework/cli/worker.js +0 -13
  36. package/build/bdd-framework/config/configDir.js +0 -35
  37. package/build/bdd-framework/config/enrichReporterData.js +0 -23
  38. package/build/bdd-framework/config/env.js +0 -50
  39. package/build/bdd-framework/config/index.js +0 -94
  40. package/build/bdd-framework/config/lang.js +0 -14
  41. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
  42. package/build/bdd-framework/cucumber/createTestStep.js +0 -43
  43. package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +0 -126
  44. package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +0 -72
  45. package/build/bdd-framework/cucumber/formatter/PickleParser.js +0 -25
  46. package/build/bdd-framework/cucumber/formatter/durationHelpers.js +0 -13
  47. package/build/bdd-framework/cucumber/formatter/getColorFns.js +0 -57
  48. package/build/bdd-framework/cucumber/formatter/index.js +0 -16
  49. package/build/bdd-framework/cucumber/formatter/locationHelpers.js +0 -16
  50. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  51. package/build/bdd-framework/cucumber/loadFeatures.js +0 -70
  52. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  53. package/build/bdd-framework/cucumber/loadSteps.js +0 -47
  54. package/build/bdd-framework/cucumber/resolveFeaturePaths.js +0 -62
  55. package/build/bdd-framework/cucumber/stepArguments.js +0 -21
  56. package/build/bdd-framework/cucumber/types.js +0 -5
  57. package/build/bdd-framework/cucumber/valueChecker.js +0 -23
  58. package/build/bdd-framework/decorators.js +0 -18
  59. package/build/bdd-framework/gen/fixtures.js +0 -48
  60. package/build/bdd-framework/gen/formatter.js +0 -167
  61. package/build/bdd-framework/gen/i18n.js +0 -39
  62. package/build/bdd-framework/gen/index.js +0 -197
  63. package/build/bdd-framework/gen/specialTags.js +0 -70
  64. package/build/bdd-framework/gen/testFile.js +0 -470
  65. package/build/bdd-framework/gen/testMeta.js +0 -60
  66. package/build/bdd-framework/gen/testNode.js +0 -35
  67. package/build/bdd-framework/gen/testPoms.js +0 -133
  68. package/build/bdd-framework/hooks/scenario.js +0 -130
  69. package/build/bdd-framework/hooks/worker.js +0 -89
  70. package/build/bdd-framework/index.js +0 -52
  71. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -93
  72. package/build/bdd-framework/playwright/getLocationInFile.js +0 -79
  73. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  74. package/build/bdd-framework/playwright/loadUtils.js +0 -33
  75. package/build/bdd-framework/playwright/testTypeImpl.js +0 -79
  76. package/build/bdd-framework/playwright/transform.js +0 -88
  77. package/build/bdd-framework/playwright/types.js +0 -12
  78. package/build/bdd-framework/playwright/utils.js +0 -56
  79. package/build/bdd-framework/reporter/cucumber/base.js +0 -52
  80. package/build/bdd-framework/reporter/cucumber/custom.js +0 -73
  81. package/build/bdd-framework/reporter/cucumber/helper.js +0 -12
  82. package/build/bdd-framework/reporter/cucumber/html.js +0 -40
  83. package/build/bdd-framework/reporter/cucumber/index.js +0 -74
  84. package/build/bdd-framework/reporter/cucumber/json.js +0 -312
  85. package/build/bdd-framework/reporter/cucumber/junit.js +0 -205
  86. package/build/bdd-framework/reporter/cucumber/message.js +0 -20
  87. package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +0 -82
  88. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -197
  89. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +0 -43
  90. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +0 -52
  91. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +0 -105
  92. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +0 -70
  93. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +0 -45
  94. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +0 -27
  95. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +0 -38
  96. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +0 -128
  97. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +0 -154
  98. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -123
  99. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -67
  100. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -114
  101. package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
  102. package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +0 -70
  103. package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +0 -35
  104. package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +0 -5
  105. package/build/bdd-framework/run/StepInvoker.js +0 -69
  106. package/build/bdd-framework/run/bddData/index.js +0 -59
  107. package/build/bdd-framework/run/bddData/types.js +0 -5
  108. package/build/bdd-framework/run/bddFixtures.js +0 -192
  109. package/build/bdd-framework/run/bddWorld.js +0 -79
  110. package/build/bdd-framework/run/bddWorldInternal.js +0 -11
  111. package/build/bdd-framework/snippets/index.js +0 -132
  112. package/build/bdd-framework/snippets/snippetSyntax.js +0 -43
  113. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
  114. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  115. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -66
  116. package/build/bdd-framework/stepDefinitions/decorators/class.js +0 -68
  117. package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -99
  118. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
  119. package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
  120. package/build/bdd-framework/steps/createBdd.js +0 -78
  121. package/build/bdd-framework/steps/decorators/class.js +0 -68
  122. package/build/bdd-framework/steps/decorators/steps.js +0 -98
  123. package/build/bdd-framework/steps/defineStep.js +0 -62
  124. package/build/bdd-framework/steps/stepConfig.js +0 -24
  125. package/build/bdd-framework/utils/AutofillMap.js +0 -20
  126. package/build/bdd-framework/utils/exit.js +0 -62
  127. package/build/bdd-framework/utils/index.js +0 -93
  128. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  129. package/build/bdd-framework/utils/logger.js +0 -30
  130. package/build/bdd-framework/utils/stripAnsiEscapes.js +0 -20
  131. package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
  132. package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
  133. package/nobdd/uat/conf/default/actors/beta/custom-module.json +0 -24
  134. package/nobdd/uat/conf/default/actors/beta/index.js +0 -6
  135. package/nobdd/uat/conf/default/actors/beta/parent-child.json +0 -24
  136. package/npm-shrinkwrap.json +0 -6475
@@ -1,312 +0,0 @@
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;
@@ -1,205 +0,0 @@
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;
@@ -1,20 +0,0 @@
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;
@@ -1,82 +0,0 @@
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 _pwStepUtils = require("./pwStepUtils");
9
- var _stripAnsiEscapes = require("../../../utils/stripAnsiEscapes");
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, _pwStepUtils.collectStepsWithCategory)(this.result, 'attach');
24
- attachmentSteps.forEach(attachmentStep => {
25
- this.mapAttachment(attachmentStep, allAttachments);
26
- });
27
- this.unusedAttachments.push(...allAttachments);
28
- this.mapUnusedAttachments();
29
- this.mapStdoutAttachments('stdout');
30
- this.mapStdoutAttachments('stderr');
31
- }
32
- mapAttachment(attachmentStep, allAttachments) {
33
- const index = allAttachments.findIndex(a => getAttachmentStepTitle(a.name) === attachmentStep.title);
34
- if (index === -1) {
35
- throw new Error(`Attachment not found for step: ${attachmentStep.title}`);
36
- }
37
- const [foundAttachment] = allAttachments.splice(index, 1);
38
- const parentStep = attachmentStep.parent;
39
- // step.parent is empty:
40
- // - in PW = 1.34 for screenshot attachment
41
- // - in PW <= 1.40 when testInfo.attach() promise
42
- // is awaited in the next async tick: 'attach' steps are on the top level
43
- const stepAttachments = parentStep ? this.stepAttachments.getOrCreate(parentStep, () => []) : this.unusedAttachments;
44
- stepAttachments.push(foundAttachment);
45
- }
46
- mapUnusedAttachments() {
47
- if (!this.unusedAttachments.length) {
48
- return;
49
- }
50
- // map unused attachments to the 'After Hooks' step
51
- const afterHooksRoot = this.getAfterHooksRoot();
52
- const stepAttachments = this.stepAttachments.getOrCreate(afterHooksRoot, () => []);
53
- stepAttachments.push(...this.unusedAttachments);
54
- }
55
- mapStdoutAttachments(name) {
56
- var _this$result$name;
57
- // map stdout / stderr to the 'After Hooks' step
58
- if (!((_this$result$name = this.result[name]) !== null && _this$result$name !== void 0 && _this$result$name.length)) {
59
- return;
60
- }
61
- const body = this.result[name].map(s => typeof s === 'string' ? (0, _stripAnsiEscapes.stripAnsiEscapes)(s) : s).join('');
62
- const afterHooksRoot = this.getAfterHooksRoot();
63
- const stepAttachments = this.stepAttachments.getOrCreate(afterHooksRoot, () => []);
64
- stepAttachments.push({
65
- name,
66
- contentType: 'text/plain',
67
- body: Buffer.from(body)
68
- });
69
- }
70
- getAfterHooksRoot() {
71
- const afterHooksRoot = (0, _pwStepUtils.getHooksRootPwStep)(this.result, 'after');
72
- if (!afterHooksRoot) {
73
- throw new Error(`Can not find after hooks root.`);
74
- }
75
- return afterHooksRoot;
76
- }
77
- }
78
- // See: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/worker/testInfo.ts#L413
79
- exports.AttachmentMapper = AttachmentMapper;
80
- function getAttachmentStepTitle(attachmentName) {
81
- return `attach "${attachmentName}"`;
82
- }