@zohodesk/testinglibrary 2.9.2 → 3.0.1

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 (125) hide show
  1. package/.gitlab-ci.yml +1 -1
  2. package/README.md +27 -1
  3. package/build/core/playwright/fixtures.js +24 -0
  4. package/build/core/playwright/helpers/fileMutex.js +10 -12
  5. package/build/core/playwright/index.js +10 -23
  6. package/build/core/playwright/setup/config-creator.js +3 -3
  7. package/build/core/playwright/setup/config-utils.js +8 -25
  8. package/build/core/playwright/tagProcessor.js +18 -28
  9. package/build/core/playwright/test-runner.js +1 -1
  10. package/build/decorators.d.ts +1 -1
  11. package/build/decorators.js +1 -1
  12. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  13. package/build/setup-folder-structure/samples/auth-setup-sample.js +14 -66
  14. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  15. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  16. package/build/setup-folder-structure/samples/settings.json +7 -0
  17. package/build/setup-folder-structure/setupProject.js +18 -5
  18. package/nobdd/uat/conf/nobdd/uat.config.js +1 -2
  19. package/nobdd/uat.config.js +1 -2
  20. package/package.json +7 -7
  21. package/build/bdd-framework/cli/commands/env.js +0 -42
  22. package/build/bdd-framework/cli/commands/export.js +0 -62
  23. package/build/bdd-framework/cli/commands/test.js +0 -64
  24. package/build/bdd-framework/cli/index.js +0 -11
  25. package/build/bdd-framework/cli/options.js +0 -19
  26. package/build/bdd-framework/cli/worker.js +0 -13
  27. package/build/bdd-framework/config/configDir.js +0 -35
  28. package/build/bdd-framework/config/enrichReporterData.js +0 -23
  29. package/build/bdd-framework/config/env.js +0 -50
  30. package/build/bdd-framework/config/index.js +0 -94
  31. package/build/bdd-framework/config/lang.js +0 -14
  32. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -43
  33. package/build/bdd-framework/cucumber/createTestStep.js +0 -43
  34. package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +0 -126
  35. package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +0 -72
  36. package/build/bdd-framework/cucumber/formatter/PickleParser.js +0 -25
  37. package/build/bdd-framework/cucumber/formatter/durationHelpers.js +0 -13
  38. package/build/bdd-framework/cucumber/formatter/getColorFns.js +0 -57
  39. package/build/bdd-framework/cucumber/formatter/index.js +0 -16
  40. package/build/bdd-framework/cucumber/formatter/locationHelpers.js +0 -16
  41. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  42. package/build/bdd-framework/cucumber/loadFeatures.js +0 -70
  43. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  44. package/build/bdd-framework/cucumber/loadSteps.js +0 -47
  45. package/build/bdd-framework/cucumber/resolveFeaturePaths.js +0 -62
  46. package/build/bdd-framework/cucumber/stepArguments.js +0 -21
  47. package/build/bdd-framework/cucumber/types.js +0 -5
  48. package/build/bdd-framework/cucumber/valueChecker.js +0 -23
  49. package/build/bdd-framework/decorators.js +0 -18
  50. package/build/bdd-framework/gen/fixtures.js +0 -48
  51. package/build/bdd-framework/gen/formatter.js +0 -167
  52. package/build/bdd-framework/gen/i18n.js +0 -39
  53. package/build/bdd-framework/gen/index.js +0 -197
  54. package/build/bdd-framework/gen/specialTags.js +0 -70
  55. package/build/bdd-framework/gen/testFile.js +0 -470
  56. package/build/bdd-framework/gen/testMeta.js +0 -60
  57. package/build/bdd-framework/gen/testNode.js +0 -35
  58. package/build/bdd-framework/gen/testPoms.js +0 -133
  59. package/build/bdd-framework/hooks/scenario.js +0 -130
  60. package/build/bdd-framework/hooks/worker.js +0 -89
  61. package/build/bdd-framework/index.js +0 -52
  62. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -93
  63. package/build/bdd-framework/playwright/getLocationInFile.js +0 -79
  64. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  65. package/build/bdd-framework/playwright/loadUtils.js +0 -33
  66. package/build/bdd-framework/playwright/testTypeImpl.js +0 -79
  67. package/build/bdd-framework/playwright/transform.js +0 -88
  68. package/build/bdd-framework/playwright/types.js +0 -12
  69. package/build/bdd-framework/playwright/utils.js +0 -56
  70. package/build/bdd-framework/reporter/cucumber/base.js +0 -52
  71. package/build/bdd-framework/reporter/cucumber/custom.js +0 -73
  72. package/build/bdd-framework/reporter/cucumber/helper.js +0 -12
  73. package/build/bdd-framework/reporter/cucumber/html.js +0 -40
  74. package/build/bdd-framework/reporter/cucumber/index.js +0 -74
  75. package/build/bdd-framework/reporter/cucumber/json.js +0 -312
  76. package/build/bdd-framework/reporter/cucumber/junit.js +0 -205
  77. package/build/bdd-framework/reporter/cucumber/message.js +0 -20
  78. package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +0 -82
  79. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +0 -197
  80. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +0 -43
  81. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +0 -52
  82. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +0 -105
  83. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +0 -70
  84. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +0 -45
  85. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +0 -27
  86. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +0 -38
  87. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +0 -128
  88. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +0 -154
  89. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +0 -123
  90. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +0 -67
  91. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +0 -114
  92. package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +0 -30
  93. package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +0 -70
  94. package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +0 -35
  95. package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +0 -5
  96. package/build/bdd-framework/run/StepInvoker.js +0 -69
  97. package/build/bdd-framework/run/bddData/index.js +0 -59
  98. package/build/bdd-framework/run/bddData/types.js +0 -5
  99. package/build/bdd-framework/run/bddFixtures.js +0 -192
  100. package/build/bdd-framework/run/bddWorld.js +0 -79
  101. package/build/bdd-framework/run/bddWorldInternal.js +0 -11
  102. package/build/bdd-framework/snippets/index.js +0 -132
  103. package/build/bdd-framework/snippets/snippetSyntax.js +0 -43
  104. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -26
  105. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  106. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -66
  107. package/build/bdd-framework/stepDefinitions/decorators/class.js +0 -68
  108. package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -99
  109. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
  110. package/build/bdd-framework/stepDefinitions/stepConfig.js +0 -24
  111. package/build/bdd-framework/steps/createBdd.js +0 -78
  112. package/build/bdd-framework/steps/decorators/class.js +0 -68
  113. package/build/bdd-framework/steps/decorators/steps.js +0 -98
  114. package/build/bdd-framework/steps/defineStep.js +0 -62
  115. package/build/bdd-framework/steps/stepConfig.js +0 -24
  116. package/build/bdd-framework/utils/AutofillMap.js +0 -20
  117. package/build/bdd-framework/utils/exit.js +0 -62
  118. package/build/bdd-framework/utils/index.js +0 -93
  119. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  120. package/build/bdd-framework/utils/logger.js +0 -30
  121. package/build/bdd-framework/utils/stripAnsiEscapes.js +0 -20
  122. package/build/setup-folder-structure/samples/authUsers-sample.json +0 -9
  123. package/build/setup-folder-structure/samples/env-config-sample.json +0 -21
  124. package/nobdd/src/App.js +0 -7
  125. package/npm-shrinkwrap.json +0 -6475
@@ -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
- }
@@ -1,197 +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.MessagesBuilder = void 0;
8
- var _TestCaseRun = require("./TestCaseRun");
9
- var _TestCase = require("./TestCase");
10
- var _Meta = require("./Meta");
11
- var _timing = require("./timing");
12
- var _events = _interopRequireDefault(require("events"));
13
- var _EventDataCollector = _interopRequireDefault(require("../../../cucumber/formatter/EventDataCollector"));
14
- var _AutofillMap = require("../../../utils/AutofillMap");
15
- var _GherkinDocuments = require("./GherkinDocuments");
16
- var _Pickles = require("./Pickles");
17
- class MessagesBuilder {
18
- report = {
19
- meta: null,
20
- source: [],
21
- gherkinDocument: [],
22
- pickle: [],
23
- stepDefinition: [],
24
- hook: [],
25
- testRunStarted: null,
26
- testCase: [],
27
- testCaseRuns: [],
28
- testRunFinished: null
29
- };
30
- fullResult;
31
- onTestEnds = [];
32
- testCaseRuns = [];
33
- testCases = new _AutofillMap.AutofillMap();
34
- hooks = new _AutofillMap.AutofillMap();
35
- gherkinDocuments = new _GherkinDocuments.GherkinDocuments();
36
- fullResultTiming;
37
- onEndPromise;
38
- onEndPromiseResolve = () => {};
39
- buildMessagesPromise;
40
- eventDataCollectorEmitter = new _events.default();
41
- eventDataCollector = new _EventDataCollector.default(this.eventDataCollectorEmitter);
42
- constructor() {
43
- this.onEndPromise = new Promise(resolve => this.onEndPromiseResolve = resolve);
44
- }
45
- onTestEnd(test, result) {
46
- // For skipped tests Playwright doesn't run fixtures
47
- // and we don't have bddData attachment -> don't know feature uri.
48
- // Don't add such test run to report.
49
- if (test.expectedStatus === 'skipped') {
50
- return;
51
- }
52
- // Important to create TestCaseRun here,
53
- // b/c test properties can change after retries (e.g. annotations)
54
- const testCaseRun = new _TestCaseRun.TestCaseRun(test, result, this.hooks);
55
- this.testCaseRuns.push(testCaseRun);
56
- }
57
- onEnd(fullResult) {
58
- this.fullResult = fullResult;
59
- this.onEndPromiseResolve();
60
- }
61
- /**
62
- * Builds Cucumber messages.
63
- * Note: wrapped into promise to build messages once for all reporters.
64
- */
65
- async buildMessages() {
66
- if (!this.buildMessagesPromise) {
67
- this.buildMessagesPromise = this.doBuildMessages();
68
- }
69
- return this.buildMessagesPromise;
70
- }
71
- // eslint-disable-next-line max-statements
72
- async doBuildMessages() {
73
- await this.onEndPromise;
74
- // order here is important
75
- // this.createTestCaseRuns();
76
- await this.loadFeatures();
77
- this.createTestCases();
78
- this.addMeta();
79
- this.addSourcesAndDocuments();
80
- this.addPickles();
81
- this.addHooks();
82
- this.addTestRunStarted();
83
- this.addTestCases();
84
- this.addTestCaseRuns();
85
- this.addTestRunFinished();
86
- this.buildEventDataCollector();
87
- }
88
- emitMessages(eventBroadcaster) {
89
- Object.values(this.report).forEach(value => {
90
- if (!value) {
91
- return;
92
- }
93
- const messages = Array.isArray(value) ? value : [value];
94
- messages.forEach(message => eventBroadcaster.emit('envelope', message));
95
- });
96
- }
97
- createTestCases() {
98
- this.testCaseRuns.forEach(testCaseRun => {
99
- const testId = testCaseRun.test.id;
100
- const gherkinDocsForProject = this.gherkinDocuments.getDocumentsForProject(testCaseRun.projectInfo);
101
- const testCase = this.testCases.getOrCreate(testId, () => new _TestCase.TestCase(testId, gherkinDocsForProject));
102
- testCase.addRun(testCaseRun);
103
- testCaseRun.testCase = testCase;
104
- });
105
- }
106
- async loadFeatures() {
107
- await this.gherkinDocuments.load(this.testCaseRuns);
108
- }
109
- // private createTestCaseRuns() {
110
- // this.onTestEnds.forEach(({ test, result }) => {
111
- // // For skipped tests Playwright doesn't run fixtures
112
- // // and we don't have bddData attachment -> don't know feature uri.
113
- // // Don't add such test run to report.
114
- // if (test.expectedStatus === 'skipped') return;
115
- // const testCaseRun = new TestCaseRun(test, result, this.hooks);
116
- // this.testCaseRuns.push(testCaseRun);
117
- // });
118
- // }
119
- addMeta() {
120
- this.report.meta = new _Meta.Meta().buildMessage();
121
- }
122
- addSourcesAndDocuments() {
123
- const {
124
- sources,
125
- gherkinDocuments
126
- } = this.gherkinDocuments.buildMessages();
127
- this.report.source = sources;
128
- this.report.gherkinDocument = gherkinDocuments;
129
- }
130
- addPickles() {
131
- this.report.pickle = new _Pickles.Pickles().buildMessages(this.testCases);
132
- }
133
- addHooks() {
134
- this.hooks.forEach(hook => {
135
- const message = hook.buildMessage();
136
- this.report.hook.push(message);
137
- });
138
- }
139
- addTestCases() {
140
- this.testCases.forEach(testCase => {
141
- const message = testCase.buildMessage();
142
- this.report.testCase.push(message);
143
- });
144
- }
145
- addTestCaseRuns() {
146
- this.testCaseRuns.map(testCaseRun => {
147
- const messages = testCaseRun.buildMessages();
148
- this.report.testCaseRuns.push(...messages);
149
- });
150
- }
151
- addTestRunStarted() {
152
- const {
153
- startTime
154
- } = this.getFullResultTiming();
155
- const testRunStarted = {
156
- timestamp: (0, _timing.toCucumberTimestamp)(startTime.getTime())
157
- };
158
- this.report.testRunStarted = {
159
- testRunStarted
160
- };
161
- }
162
- addTestRunFinished() {
163
- const {
164
- startTime,
165
- duration
166
- } = this.getFullResultTiming();
167
- const testRunFinished = {
168
- success: this.fullResult.status === 'passed',
169
- timestamp: (0, _timing.toCucumberTimestamp)(startTime.getTime() + duration)
170
- };
171
- this.report.testRunFinished = {
172
- testRunFinished
173
- };
174
- }
175
- buildEventDataCollector() {
176
- this.emitMessages(this.eventDataCollectorEmitter);
177
- }
178
- getFullResultTiming() {
179
- if (this.fullResultTiming) {
180
- return this.fullResultTiming;
181
- }
182
- // result.startTime and result.duration were added in pw 1.37
183
- // see: https://github.com/microsoft/playwright/pull/26760
184
- if ('startTime' in this.fullResult && 'duration' in this.fullResult) {
185
- this.fullResultTiming = {
186
- startTime: this.fullResult.startTime,
187
- duration: this.fullResult.duration
188
- };
189
- } else {
190
- // Calculate overall startTime and duration based on test timings
191
- const items = this.testCaseRuns.map(t => t.result);
192
- this.fullResultTiming = (0, _timing.calcMinMaxByArray)(items);
193
- }
194
- return this.fullResultTiming;
195
- }
196
- }
197
- exports.MessagesBuilder = MessagesBuilder;
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.GherkinDocumentMessage = void 0;
7
- var _utils = require("../../../utils");
8
- var _Projects = require("./Projects");
9
- const gherkinDocumentMetaSymbol = Symbol('gherkinDocumentMeta');
10
- class GherkinDocumentMessage {
11
- projectInfo;
12
- gherkinDocument;
13
- static extractMeta(gherkinDocument) {
14
- return gherkinDocument[gherkinDocumentMetaSymbol];
15
- }
16
- constructor(projectInfo, gherkinDocument) {
17
- this.projectInfo = projectInfo;
18
- this.gherkinDocument = gherkinDocument;
19
- }
20
- build() {
21
- const gherkinDocument = this.copyDocumentWithoutPickles();
22
- this.setUriWithProject(gherkinDocument);
23
- this.setMeta(gherkinDocument);
24
- return {
25
- gherkinDocument
26
- };
27
- }
28
- copyDocumentWithoutPickles() {
29
- return (0, _utils.omit)(this.gherkinDocument, 'pickles');
30
- }
31
- setUriWithProject(gherkinDocument) {
32
- gherkinDocument.uri = (0, _Projects.getFeatureUriWithProject)(this.projectInfo, this.gherkinDocument.uri);
33
- }
34
- setMeta(gherkinDocument) {
35
- var _this$projectInfo, _this$projectInfo2;
36
- gherkinDocument[gherkinDocumentMetaSymbol] = {
37
- originalUri: this.gherkinDocument.uri || '',
38
- projectName: (_this$projectInfo = this.projectInfo) === null || _this$projectInfo === void 0 ? void 0 : _this$projectInfo.projectName,
39
- browserName: (_this$projectInfo2 = this.projectInfo) === null || _this$projectInfo2 === void 0 ? void 0 : _this$projectInfo2.browserName
40
- };
41
- }
42
- }
43
- exports.GherkinDocumentMessage = GherkinDocumentMessage;
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.GherkinDocumentClone = void 0;
7
- var _crypto = require("crypto");
8
- var _AutofillMap = require("../../../utils/AutofillMap");
9
- /**
10
- * Creates gherkin document copy with re-generated ast node IDs,
11
- * pickle IDs and pickle steps IDs.
12
- */
13
-
14
- class GherkinDocumentClone {
15
- gherkinDocument;
16
- oldNewIds = new _AutofillMap.AutofillMap();
17
- constructor(gherkinDocument) {
18
- this.gherkinDocument = gherkinDocument;
19
- }
20
- getClone() {
21
- const copiedDoc = this.getDocumentCopyWithNewIds();
22
- this.remapPickleAstNodeIds(copiedDoc);
23
- return copiedDoc;
24
- }
25
- getDocumentCopyWithNewIds() {
26
- return JSON.parse(JSON.stringify(this.gherkinDocument, (key, value) => {
27
- return key === 'id' ? this.getOrGenerateNewId(value) : value;
28
- }));
29
- }
30
- remapPickleAstNodeIds(copiedDoc) {
31
- copiedDoc.pickles.forEach(pickle => {
32
- pickle.astNodeIds = pickle.astNodeIds.map(oldId => this.getNewId(oldId));
33
- this.remapPickleStepsAstNodeIds(pickle);
34
- });
35
- }
36
- remapPickleStepsAstNodeIds(pickle) {
37
- pickle.steps.forEach(step => {
38
- step.astNodeIds = step.astNodeIds.map(oldId => this.getNewId(oldId));
39
- });
40
- }
41
- getOrGenerateNewId(oldId) {
42
- return this.oldNewIds.getOrCreate(oldId, () => (0, _crypto.randomUUID)());
43
- }
44
- getNewId(oldId) {
45
- const newId = this.oldNewIds.get(oldId);
46
- if (!newId) {
47
- throw new Error(`New ID is not found for old ID: ${oldId}`);
48
- }
49
- return newId;
50
- }
51
- }
52
- exports.GherkinDocumentClone = GherkinDocumentClone;