@zohodesk/testinglibrary 0.4.6-experimental → 2.9.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 (127) hide show
  1. package/README.md +4 -19
  2. package/build/bdd-framework/cli/commands/env.js +42 -0
  3. package/build/bdd-framework/cli/commands/export.js +62 -0
  4. package/build/bdd-framework/cli/commands/test.js +64 -0
  5. package/build/bdd-framework/cli/index.js +11 -0
  6. package/build/bdd-framework/cli/options.js +19 -0
  7. package/build/bdd-framework/cli/worker.js +13 -0
  8. package/build/bdd-framework/config/configDir.js +35 -0
  9. package/build/bdd-framework/config/enrichReporterData.js +23 -0
  10. package/build/bdd-framework/config/env.js +50 -0
  11. package/build/bdd-framework/config/index.js +94 -0
  12. package/build/bdd-framework/config/lang.js +14 -0
  13. package/build/bdd-framework/cucumber/buildStepDefinition.js +43 -0
  14. package/build/bdd-framework/cucumber/createTestStep.js +43 -0
  15. package/build/bdd-framework/cucumber/formatter/EventDataCollector.js +126 -0
  16. package/build/bdd-framework/cucumber/formatter/GherkinDocumentParser.js +72 -0
  17. package/build/bdd-framework/cucumber/formatter/PickleParser.js +25 -0
  18. package/build/bdd-framework/cucumber/formatter/durationHelpers.js +13 -0
  19. package/build/bdd-framework/cucumber/formatter/getColorFns.js +57 -0
  20. package/build/bdd-framework/cucumber/formatter/index.js +16 -0
  21. package/build/bdd-framework/cucumber/formatter/locationHelpers.js +16 -0
  22. package/build/bdd-framework/cucumber/loadConfig.js +17 -0
  23. package/build/bdd-framework/cucumber/loadFeatures.js +70 -0
  24. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
  25. package/build/bdd-framework/cucumber/loadSteps.js +47 -0
  26. package/build/bdd-framework/cucumber/resolveFeaturePaths.js +62 -0
  27. package/build/bdd-framework/cucumber/stepArguments.js +21 -0
  28. package/build/bdd-framework/cucumber/types.js +5 -0
  29. package/build/bdd-framework/cucumber/valueChecker.js +23 -0
  30. package/build/bdd-framework/decorators.js +18 -0
  31. package/build/bdd-framework/gen/fixtures.js +48 -0
  32. package/build/bdd-framework/gen/formatter.js +167 -0
  33. package/build/bdd-framework/gen/i18n.js +39 -0
  34. package/build/bdd-framework/gen/index.js +197 -0
  35. package/build/bdd-framework/gen/specialTags.js +70 -0
  36. package/build/bdd-framework/gen/testFile.js +470 -0
  37. package/build/bdd-framework/gen/testMeta.js +60 -0
  38. package/build/bdd-framework/gen/testNode.js +35 -0
  39. package/build/bdd-framework/gen/testPoms.js +133 -0
  40. package/build/bdd-framework/hooks/scenario.js +130 -0
  41. package/build/bdd-framework/hooks/worker.js +89 -0
  42. package/build/bdd-framework/index.js +52 -0
  43. package/build/bdd-framework/playwright/fixtureParameterNames.js +93 -0
  44. package/build/bdd-framework/playwright/getLocationInFile.js +79 -0
  45. package/build/bdd-framework/playwright/loadConfig.js +42 -0
  46. package/build/bdd-framework/playwright/loadUtils.js +33 -0
  47. package/build/bdd-framework/playwright/testTypeImpl.js +79 -0
  48. package/build/bdd-framework/playwright/transform.js +88 -0
  49. package/build/bdd-framework/playwright/types.js +12 -0
  50. package/build/bdd-framework/playwright/utils.js +56 -0
  51. package/build/bdd-framework/reporter/cucumber/base.js +52 -0
  52. package/build/bdd-framework/reporter/cucumber/custom.js +73 -0
  53. package/build/bdd-framework/reporter/cucumber/helper.js +12 -0
  54. package/build/bdd-framework/reporter/cucumber/html.js +40 -0
  55. package/build/bdd-framework/reporter/cucumber/index.js +74 -0
  56. package/build/bdd-framework/reporter/cucumber/json.js +312 -0
  57. package/build/bdd-framework/reporter/cucumber/junit.js +205 -0
  58. package/build/bdd-framework/reporter/cucumber/message.js +20 -0
  59. package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +82 -0
  60. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +197 -0
  61. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocument.js +43 -0
  62. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocumentClone.js +52 -0
  63. package/build/bdd-framework/reporter/cucumber/messagesBuilder/GherkinDocuments.js +105 -0
  64. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +70 -0
  65. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Meta.js +45 -0
  66. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Pickles.js +27 -0
  67. package/build/bdd-framework/reporter/cucumber/messagesBuilder/Projects.js +38 -0
  68. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCase.js +128 -0
  69. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +154 -0
  70. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +123 -0
  71. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +67 -0
  72. package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +114 -0
  73. package/build/bdd-framework/reporter/cucumber/messagesBuilder/index.js +30 -0
  74. package/build/bdd-framework/reporter/cucumber/messagesBuilder/pwStepUtils.js +70 -0
  75. package/build/bdd-framework/reporter/cucumber/messagesBuilder/timing.js +35 -0
  76. package/build/bdd-framework/reporter/cucumber/messagesBuilder/types.js +5 -0
  77. package/build/bdd-framework/run/StepInvoker.js +69 -0
  78. package/build/bdd-framework/run/bddData/index.js +59 -0
  79. package/build/bdd-framework/run/bddData/types.js +5 -0
  80. package/build/bdd-framework/run/bddFixtures.js +192 -0
  81. package/build/bdd-framework/run/bddWorld.js +79 -0
  82. package/build/bdd-framework/run/bddWorldInternal.js +11 -0
  83. package/build/bdd-framework/snippets/index.js +132 -0
  84. package/build/bdd-framework/snippets/snippetSyntax.js +43 -0
  85. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +26 -0
  86. package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
  87. package/build/bdd-framework/stepDefinitions/createBdd.js +66 -0
  88. package/build/bdd-framework/stepDefinitions/decorators/class.js +68 -0
  89. package/build/bdd-framework/stepDefinitions/decorators/steps.js +99 -0
  90. package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
  91. package/build/bdd-framework/stepDefinitions/stepConfig.js +24 -0
  92. package/build/bdd-framework/steps/createBdd.js +78 -0
  93. package/build/bdd-framework/steps/decorators/class.js +68 -0
  94. package/build/bdd-framework/steps/decorators/steps.js +98 -0
  95. package/build/bdd-framework/steps/defineStep.js +62 -0
  96. package/build/bdd-framework/steps/stepConfig.js +24 -0
  97. package/build/bdd-framework/utils/AutofillMap.js +20 -0
  98. package/build/bdd-framework/utils/exit.js +62 -0
  99. package/build/bdd-framework/utils/index.js +93 -0
  100. package/build/bdd-framework/utils/jsStringWrap.js +44 -0
  101. package/build/bdd-framework/utils/logger.js +30 -0
  102. package/build/bdd-framework/utils/stripAnsiEscapes.js +20 -0
  103. package/build/core/playwright/helpers/auth/getUsers.js +12 -25
  104. package/build/core/playwright/index.js +23 -10
  105. package/build/core/playwright/setup/config-creator.js +3 -3
  106. package/build/core/playwright/setup/config-utils.js +25 -8
  107. package/build/core/playwright/tagProcessor.js +79 -0
  108. package/build/core/playwright/test-runner.js +4 -3
  109. package/build/core/playwright/validateFeature.js +3 -33
  110. package/build/decorators.d.ts +1 -1
  111. package/build/decorators.js +1 -1
  112. package/build/setup-folder-structure/samples/auth-setup-sample.js +66 -14
  113. package/build/setup-folder-structure/samples/authUsers-sample.json +9 -0
  114. package/build/setup-folder-structure/samples/env-config-sample.json +21 -0
  115. package/build/setup-folder-structure/setupProject.js +5 -18
  116. package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
  117. package/build/test/core/playwright/__tests__/validateFeature.test.js +10 -5
  118. package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
  119. package/nobdd/src/App.js +7 -0
  120. package/npm-shrinkwrap.json +2175 -5825
  121. package/package.json +7 -7
  122. package/build/core/playwright/fixtures.js +0 -24
  123. package/build/core/playwright/tag-processor.js +0 -68
  124. package/build/setup-folder-structure/samples/actors-index.js +0 -3
  125. package/build/setup-folder-structure/samples/editions-index.js +0 -3
  126. package/build/setup-folder-structure/samples/free-sample.json +0 -25
  127. package/build/setup-folder-structure/samples/settings.json +0 -7
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.TestStepAttachments = void 0;
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var messages = _interopRequireWildcard(require("@cucumber/messages"));
10
+ var _path = _interopRequireDefault(require("path"));
11
+ 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); }
12
+ 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; }
13
+ /**
14
+ * Class for getting attachment messages for a particular step.
15
+ */
16
+
17
+ class TestStepAttachments {
18
+ testCaseRun;
19
+ testStep;
20
+ pwStep;
21
+ constructor(testCaseRun, testStep, pwStep) {
22
+ this.testCaseRun = testCaseRun;
23
+ this.testStep = testStep;
24
+ this.pwStep = pwStep;
25
+ }
26
+ buildMessages() {
27
+ if (!this.pwStep) {
28
+ return [];
29
+ }
30
+ return this.testCaseRun.attachmentMapper.getStepAttachments(this.pwStep).map(pwAttachment => this.buildAttachmentMessage(pwAttachment));
31
+ }
32
+ buildAttachmentMessage(pwAttachment) {
33
+ const attachment = {
34
+ testCaseStartedId: this.testCaseRun.id,
35
+ testStepId: this.testStep.id,
36
+ // for now always attach as base64
37
+ // todo: for text/plain and application/json use raw to save some bytes
38
+ body: this.getAttachmentBodyBase64(pwAttachment),
39
+ contentEncoding: messages.AttachmentContentEncoding.BASE64,
40
+ mediaType: pwAttachment.contentType,
41
+ fileName: pwAttachment.name
42
+ };
43
+ return {
44
+ attachment
45
+ };
46
+ }
47
+ getAttachmentBodyBase64(pwAttachment) {
48
+ if (pwAttachment.path) {
49
+ if (_fs.default.existsSync(pwAttachment.path)) {
50
+ return _fs.default.readFileSync(pwAttachment.path, 'base64');
51
+ }
52
+ throw createMissingAttachmentError(pwAttachment.path);
53
+ }
54
+ if (pwAttachment.body) {
55
+ return pwAttachment.body.toString('base64');
56
+ }
57
+ throw new Error(`Playwright attachment without path and body`);
58
+ }
59
+ }
60
+ exports.TestStepAttachments = TestStepAttachments;
61
+ function createMissingAttachmentError(attachmentPath) {
62
+ const attachmentDir = _path.default.join(_path.default.dirname(attachmentPath));
63
+ const attachmentDirExists = _fs.default.existsSync(attachmentDir);
64
+ const files = attachmentDirExists ? _fs.default.readdirSync(attachmentDir) : [];
65
+ const errorMsg = [`Attachment file is not found:`, attachmentPath, `Attachment dir ${attachmentDirExists ? 'exists' : 'does not exist'}.`, ...(attachmentDirExists ? [`Available files (${files.length}):`, ...files] : []), ''].join('\n');
66
+ return new Error(errorMsg);
67
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TestStepRun = void 0;
7
+ var messages = _interopRequireWildcard(require("@cucumber/messages"));
8
+ var _stripAnsiEscapes = require("../../../utils/stripAnsiEscapes");
9
+ var _timing = require("./timing");
10
+ var _TestStepAttachments = require("./TestStepAttachments");
11
+ 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); }
12
+ 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; }
13
+ class TestStepRun {
14
+ testCaseRun;
15
+ testStep;
16
+ pwStep;
17
+ constructor(testCaseRun, testStep, pwStep) {
18
+ this.testCaseRun = testCaseRun;
19
+ this.testStep = testStep;
20
+ this.pwStep = pwStep;
21
+ }
22
+ buildMessages() {
23
+ const stepAttachments = new _TestStepAttachments.TestStepAttachments(this.testCaseRun, this.testStep, this.pwStep);
24
+ return [this.buildTestStepStarted(),
25
+ // prettier-ignore
26
+ ...stepAttachments.buildMessages(), this.buildTestStepFinished()];
27
+ }
28
+ isHook() {
29
+ return Boolean(this.testStep.hookId);
30
+ }
31
+ wasExecuted() {
32
+ return Boolean(this.pwStep);
33
+ }
34
+ get startTime() {
35
+ return this.wasExecuted() ? this.pwStep.startTime : this.testCaseRun.result.startTime;
36
+ }
37
+ get duration() {
38
+ return this.wasExecuted() ? this.pwStep.duration : 0;
39
+ }
40
+ buildTestStepStarted() {
41
+ const testStepStarted = {
42
+ testCaseStartedId: this.testCaseRun.id,
43
+ testStepId: this.testStep.id,
44
+ timestamp: (0, _timing.toCucumberTimestamp)(this.startTime.getTime())
45
+ };
46
+ return {
47
+ testStepStarted
48
+ };
49
+ }
50
+ buildTestStepFinished() {
51
+ const error = this.getStepError();
52
+ const testStepFinished = {
53
+ testCaseStartedId: this.testCaseRun.id,
54
+ testStepId: this.testStep.id,
55
+ testStepResult: {
56
+ duration: messages.TimeConversion.millisecondsToDuration(this.duration),
57
+ status: this.getStatus(error),
58
+ // 'message' is deprecated since cucumber 10.4 in favor of 'exception' field
59
+ // See: https://github.com/cucumber/react-components/pull/345
60
+ message: error ? buildErrorMessage(error) : undefined,
61
+ exception: error ? buildException(error) : undefined
62
+ },
63
+ timestamp: (0, _timing.toCucumberTimestamp)(this.startTime.getTime() + this.duration)
64
+ };
65
+ return {
66
+ testStepFinished
67
+ };
68
+ }
69
+ getStatus(error) {
70
+ switch (true) {
71
+ case Boolean(error):
72
+ return messages.TestStepResultStatus.FAILED;
73
+ // For hooks that were not executted we return PASSED, not SKIPPED.
74
+ // Because these hooks can be from another run attempt of this testCase.
75
+ // If marked as skipped, the whole run is marked as skipped in reporter.
76
+ case !this.isHook() && !this.wasExecuted():
77
+ return messages.TestStepResultStatus.SKIPPED;
78
+ default:
79
+ return messages.TestStepResultStatus.PASSED;
80
+ }
81
+ }
82
+ // eslint-disable-next-line complexity
83
+ getStepError() {
84
+ if (!this.pwStep) {
85
+ return;
86
+ }
87
+ if (this.testCaseRun.errorSteps.has(this.pwStep)) {
88
+ return this.pwStep.error;
89
+ }
90
+ if (this.testCaseRun.isTimeouted() && this.pwStep === this.testCaseRun.timeoutedStep) {
91
+ var _this$testCaseRun$res;
92
+ return {
93
+ message: (_this$testCaseRun$res = this.testCaseRun.result.errors) === null || _this$testCaseRun$res === void 0 ? void 0 : _this$testCaseRun$res.map(e => e.message).join('\n\n')
94
+ };
95
+ }
96
+ }
97
+ }
98
+ exports.TestStepRun = TestStepRun;
99
+ function buildErrorMessage(error) {
100
+ return (0, _stripAnsiEscapes.stripAnsiEscapes)([error.message, error.snippet].filter(Boolean).join('\n'));
101
+ }
102
+ function buildException(error) {
103
+ return {
104
+ type: 'Error',
105
+ message: buildErrorMessage(error),
106
+ // todo: extract only trace?
107
+ stackTrace: error.stack ? extractStackTrace((0, _stripAnsiEscapes.stripAnsiEscapes)(error.stack)) : undefined
108
+ // Use type casting b/c older versions of @cucumber/messages don't have 'stackTrace' field
109
+ // todo: add direct dependency on @cucumber/messages
110
+ };
111
+ }
112
+ function extractStackTrace(errorStack) {
113
+ return errorStack.split('\n').filter(line => line.match(/^\s+at .*/)).join('\n');
114
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getMessagesBuilderRef = getMessagesBuilderRef;
7
+ var _Builder = require("./Builder");
8
+ /**
9
+ * Returns reference to a messagesBuilder singleton.
10
+ * We pass onTestEnd and onEnd calls only for the first reference (reporter),
11
+ * otherwise all events will be duplicated.
12
+ */
13
+
14
+ let instance;
15
+ let referenceCount = 0;
16
+ function getMessagesBuilderRef() {
17
+ if (!instance) {
18
+ instance = new _Builder.MessagesBuilder();
19
+ }
20
+ const isFirstRef = ++referenceCount === 1;
21
+ return {
22
+ builder: instance,
23
+ onTestEnd(test, result) {
24
+ isFirstRef && this.builder.onTestEnd(test, result);
25
+ },
26
+ onEnd(fullResult) {
27
+ isFirstRef && this.builder.onEnd(fullResult);
28
+ }
29
+ };
30
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectStepsDfs = collectStepsDfs;
7
+ exports.collectStepsWithCategory = collectStepsWithCategory;
8
+ exports.findDeepestStepWithError = findDeepestStepWithError;
9
+ exports.findDeepestStepWithUnknownDuration = findDeepestStepWithUnknownDuration;
10
+ exports.getHooksRootPwStep = getHooksRootPwStep;
11
+ exports.isUnknownDuration = isUnknownDuration;
12
+ /**
13
+ * Utility functions for filtering Playwright steps.
14
+ */
15
+ // Playwright step categoires, that can be mapped to testStep / hook in Cucumber messages
16
+ const MEANINGFUL_STEP_CATEGORIES = ['hook', 'fixture', 'test.step'];
17
+ function collectStepsWithCategory(parent, category) {
18
+ const categories = Array.isArray(category) ? category : [category];
19
+ const steps = collectStepsDfs(parent);
20
+ return steps.filter(step => categories.includes(step.category));
21
+ }
22
+ function getHooksRootPwStep(result, type) {
23
+ const rootStepTitle = type === 'before' ? 'Before Hooks' : 'After Hooks';
24
+ return result.steps.find(step => step.category === 'hook' && step.title === rootStepTitle);
25
+ }
26
+ function findDeepestStepWithError(root) {
27
+ if (!root) {
28
+ return;
29
+ }
30
+ return findDeepestStepWith(root, pwStep => {
31
+ return Boolean(pwStep.error) && MEANINGFUL_STEP_CATEGORIES.includes(pwStep.category);
32
+ });
33
+ }
34
+ function findDeepestStepWithUnknownDuration(root) {
35
+ if (!root) {
36
+ return;
37
+ }
38
+ return findDeepestStepWith(root, pwStep => {
39
+ return isUnknownDuration(pwStep) && MEANINGFUL_STEP_CATEGORIES.includes(pwStep.category);
40
+ });
41
+ }
42
+ /**
43
+ * Finds the deepest step that satisfies predicate function.
44
+ */
45
+ function findDeepestStepWith(root, predicate) {
46
+ let currentStep = predicate(root) ? root : undefined;
47
+ while (currentStep) {
48
+ const nextStep = currentStep.steps.find(pwStep => predicate(pwStep));
49
+ if (!nextStep) {
50
+ break;
51
+ }
52
+ currentStep = nextStep;
53
+ }
54
+ return currentStep;
55
+ }
56
+ /**
57
+ * Returns all steps in DFS order.
58
+ * See: https://en.wikipedia.org/wiki/Depth-first_search
59
+ */
60
+ function collectStepsDfs(parent) {
61
+ var _parent$steps;
62
+ return (parent === null || parent === void 0 || (_parent$steps = parent.steps) === null || _parent$steps === void 0 ? void 0 : _parent$steps.reduce((res, step) => {
63
+ res.push(step);
64
+ res.push(...collectStepsDfs(step));
65
+ return res;
66
+ }, [])) || [];
67
+ }
68
+ function isUnknownDuration(pwStep) {
69
+ return pwStep.duration === -1;
70
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.calcMinMaxByArray = calcMinMaxByArray;
7
+ exports.toCucumberTimestamp = toCucumberTimestamp;
8
+ var _messages = require("@cucumber/messages");
9
+ /**
10
+ * Timing utils.
11
+ */
12
+
13
+ function toCucumberTimestamp(time) {
14
+ return _messages.TimeConversion.millisecondsSinceEpochToTimestamp(time);
15
+ }
16
+ function calcMinMaxByArray(items) {
17
+ let startTime = items.length > 0 ? items[0].startTime : new Date();
18
+ let endTime = items.length > 0 ? getEndTime(items[0]) : new Date();
19
+ items.forEach(item => {
20
+ const resultEndTime = getEndTime(item);
21
+ if (item.startTime < startTime) {
22
+ startTime = item.startTime;
23
+ }
24
+ if (resultEndTime > endTime) {
25
+ endTime = resultEndTime;
26
+ }
27
+ });
28
+ return {
29
+ startTime,
30
+ duration: endTime.getTime() - startTime.getTime()
31
+ };
32
+ }
33
+ function getEndTime(entity) {
34
+ return new Date(entity.startTime.getTime() + entity.duration);
35
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StepInvoker = void 0;
7
+ var _loadSteps = require("../cucumber/loadSteps");
8
+ var _getLocationInFile = require("../playwright/getLocationInFile");
9
+ var _testTypeImpl = require("../playwright/testTypeImpl");
10
+ var _defineStep = require("../steps/defineStep");
11
+ var _lang = require("../config/lang");
12
+ /**
13
+ * Class to invoke step in playwright runner.
14
+ */
15
+
16
+ class StepInvoker {
17
+ world;
18
+ keyword;
19
+ constructor(world, keyword) {
20
+ this.world = world;
21
+ this.keyword = keyword;
22
+ this.invoke = this.invoke.bind(this);
23
+ }
24
+ /**
25
+ * Invokes particular step.
26
+ * See: https://github.com/cucumber/cucumber-js/blob/main/src/runtime/test_case_runner.ts#L299
27
+ */
28
+ async invoke(stepText, argument, stepFixtures) {
29
+ var _this$world$$internal;
30
+ this.world.$internal.currentStepFixtures = stepFixtures || {};
31
+ const stepDefinition = this.getStepDefinition(stepText);
32
+ // Get location of step call in generated test file.
33
+ // This call must be exactly here to have correct call stack (before async calls)
34
+ const location = (0, _getLocationInFile.getLocationInFile)(this.world.testInfo.file);
35
+ const stepTitle = this.getStepTitle(stepText);
36
+ const code = (0, _defineStep.getStepCode)(stepDefinition);
37
+ const parameters = await this.getStepParameters(stepDefinition, stepText, argument || undefined);
38
+ (_this$world$$internal = this.world.$internal.bddDataManager) === null || _this$world$$internal === void 0 || _this$world$$internal.registerStep(stepDefinition, stepText, location);
39
+ await (0, _testTypeImpl.runStepWithCustomLocation)(this.world.test, stepTitle, location, () => code.apply(this.world, parameters));
40
+ }
41
+ getStepDefinition(text) {
42
+ const stepDefinition = (0, _loadSteps.findStepDefinition)(this.world.options.supportCodeLibrary, text, this.world.testInfo.file);
43
+ if (!stepDefinition) {
44
+ throw new Error(`Undefined step: "${text}"`);
45
+ }
46
+ return stepDefinition;
47
+ }
48
+ async getStepParameters(stepDefinition, text, argument) {
49
+ // see: https://github.com/cucumber/cucumber-js/blob/main/src/models/step_definition.ts#L25
50
+ const {
51
+ parameters
52
+ } = await stepDefinition.getInvocationParameters({
53
+ hookParameter: {},
54
+ // only text and argument are needed
55
+ step: {
56
+ text,
57
+ argument
58
+ },
59
+ world: this.world
60
+ });
61
+ return parameters;
62
+ }
63
+ getStepTitle(text) {
64
+ // Currently prepend keyword only for English.
65
+ // For other langs it's more complex as we need to pass original keyword from step.
66
+ return (0, _lang.isEnglish)(this.world.options.lang) ? `${this.keyword} ${text}` : text;
67
+ }
68
+ }
69
+ exports.StepInvoker = StepInvoker;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BddDataManager = void 0;
7
+ exports.getBddDataFromTest = getBddDataFromTest;
8
+ var _createTestStep = require("../../cucumber/createTestStep");
9
+ var _utils = require("../../utils");
10
+ var _utils2 = require("../../playwright/utils");
11
+ const BDD_DATA_ANNOTATION_NAME = '__bddData';
12
+ class BddDataManager {
13
+ testInfo;
14
+ data;
15
+ constructor(testInfo, testMeta, uri) {
16
+ this.testInfo = testInfo;
17
+ this.data = {
18
+ uri,
19
+ pickleLocation: testMeta.pickleLocation,
20
+ steps: []
21
+ };
22
+ this.save({
23
+ create: true
24
+ });
25
+ }
26
+ registerStep(stepDefinition, stepText, pwStepLocation) {
27
+ const step = (0, _createTestStep.createTestStep)(stepDefinition, stepText);
28
+ this.data.steps.push({
29
+ pwStepLocation: (0, _utils.stringifyLocation)(pwStepLocation),
30
+ stepMatchArgumentsLists: step.stepMatchArgumentsLists || []
31
+ });
32
+ this.save();
33
+ }
34
+ save({
35
+ create = false
36
+ } = {}) {
37
+ (0, _utils2.updateAnnotation)(this.testInfo, {
38
+ type: BDD_DATA_ANNOTATION_NAME,
39
+ description: JSON.stringify(this.data)
40
+ }, {
41
+ create
42
+ });
43
+ }
44
+ }
45
+ exports.BddDataManager = BddDataManager;
46
+ function getBddDataFromTest({
47
+ annotations
48
+ }) {
49
+ const annotationIndex = annotations.findIndex(isBddDataAnnotation);
50
+ const annotation = annotations[annotationIndex];
51
+ const bddData = annotation !== null && annotation !== void 0 && annotation.description ? JSON.parse(annotation.description) : undefined;
52
+ return {
53
+ bddData,
54
+ annotationIndex
55
+ };
56
+ }
57
+ function isBddDataAnnotation(annotation) {
58
+ return annotation.type === BDD_DATA_ANNOTATION_NAME;
59
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isBddAutoInjectFixture = isBddAutoInjectFixture;
7
+ exports.test = void 0;
8
+ var _test = require("@playwright/test");
9
+ var _loadConfig = require("../cucumber/loadConfig");
10
+ var _loadSteps = require("../cucumber/loadSteps");
11
+ var _bddWorld = require("./bddWorld");
12
+ var _config = require("../config");
13
+ var _env = require("../config/env");
14
+ var _steps = require("../steps/decorators/steps");
15
+ var _configDir = require("../config/configDir");
16
+ var _scenario = require("../hooks/scenario");
17
+ var _worker = require("../hooks/worker");
18
+ var _StepInvoker = require("./StepInvoker");
19
+ var _testMeta = require("../gen/testMeta");
20
+ var _logger = require("../utils/logger");
21
+ var _enrichReporterData = require("../config/enrichReporterData");
22
+ var _bddData = require("./bddData");
23
+ const test = exports.test = _test.test.extend({
24
+ // load cucumber once per worker (auto-fixture)
25
+ // todo: maybe remove caching in cucumber/loadConfig.ts and cucumber/loadSteps.ts
26
+ // as we call it once per worker. Check generation phase.
27
+ $cucumber: [async ({}, use, workerInfo) => {
28
+ const config = (0, _env.getConfigFromEnv)(workerInfo.project.testDir);
29
+ const environment = {
30
+ cwd: (0, _configDir.getPlaywrightConfigDir)()
31
+ };
32
+ const {
33
+ runConfiguration
34
+ } = await (0, _loadConfig.loadConfig)({
35
+ provided: (0, _config.extractCucumberConfig)(config)
36
+ }, environment);
37
+ const supportCodeLibrary = await (0, _loadSteps.loadSteps)(runConfiguration, environment);
38
+ (0, _steps.appendDecoratorSteps)(supportCodeLibrary);
39
+ const World = (0, _bddWorld.getWorldConstructor)(supportCodeLibrary);
40
+ await use({
41
+ runConfiguration,
42
+ supportCodeLibrary,
43
+ World,
44
+ config
45
+ });
46
+ }, {
47
+ auto: true,
48
+ scope: 'worker'
49
+ }],
50
+ // $lang fixture can be overwritten in test file
51
+ $lang: ({}, use) => use(''),
52
+ // init $bddWorldFixtures with empty object, will be owerwritten in test file for cucumber-style
53
+ $bddWorldFixtures: ({}, use) => use({}),
54
+ $bddWorld: async ({
55
+ $tags,
56
+ $test,
57
+ $bddWorldFixtures,
58
+ $cucumber,
59
+ $lang,
60
+ $testMeta,
61
+ $uri
62
+ }, use, testInfo) => {
63
+ const {
64
+ runConfiguration,
65
+ supportCodeLibrary,
66
+ World,
67
+ config
68
+ } = $cucumber;
69
+ const world = new World({
70
+ testInfo,
71
+ supportCodeLibrary,
72
+ $tags,
73
+ $test,
74
+ $bddWorldFixtures,
75
+ lang: $lang,
76
+ parameters: runConfiguration.runtime.worldParameters || {},
77
+ log: () => _logger.logger.warn(`world.log() is noop, please use world.testInfo.attach()`),
78
+ attach: async () => _logger.logger.warn(`world.attach() is noop, please use world.testInfo.attach()`)
79
+ });
80
+ if ((0, _enrichReporterData.getEnrichReporterData)(config)) {
81
+ world.$internal.bddDataManager = new _bddData.BddDataManager(testInfo, $testMeta, $uri);
82
+ }
83
+ await world.init();
84
+ await use(world);
85
+ await world.destroy();
86
+ },
87
+ Given: ({
88
+ $bddWorld
89
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Given').invoke),
90
+ When: ({
91
+ $bddWorld
92
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'When').invoke),
93
+ Then: ({
94
+ $bddWorld
95
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'Then').invoke),
96
+ And: ({
97
+ $bddWorld
98
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'And').invoke),
99
+ But: ({
100
+ $bddWorld
101
+ }, use) => use(new _StepInvoker.StepInvoker($bddWorld, 'But').invoke),
102
+ // init $testMetaMap with empty object, will be overwritten in each test file
103
+ $testMetaMap: ({}, use) => use({}),
104
+ // concrete test meta
105
+ $testMeta: ({
106
+ $testMetaMap
107
+ }, use, testInfo) => use((0, _testMeta.getTestMeta)($testMetaMap, testInfo)),
108
+ // concrete test tags
109
+ $tags: ({
110
+ $testMeta
111
+ }, use) => use($testMeta.tags || []),
112
+ // init $test with base test, but it will be overwritten in test file
113
+ $test: ({}, use) => use(_test.test),
114
+ // feature file uri, relative to configDir, will be overwritten in test file
115
+ $uri: ({}, use) => use(''),
116
+ // can be owerwritten in test file if there are scenario hooks
117
+ $scenarioHookFixtures: ({}, use) => use({}),
118
+ $before: [
119
+ // Unused dependencies are important:
120
+ // 1. $beforeAll / $afterAll: in pw < 1.39 worker-scoped auto-fixtures were called after test-scoped
121
+ // 2. $after: to call after hooks in case of errors in before hooks
122
+ async ({
123
+ $scenarioHookFixtures,
124
+ $bddWorld,
125
+ $tags,
126
+ $beforeAll,
127
+ $afterAll,
128
+ $after
129
+ }, use, $testInfo) => {
130
+ await (0, _scenario.runScenarioHooks)('before', {
131
+ $bddWorld,
132
+ $tags,
133
+ $testInfo,
134
+ ...$scenarioHookFixtures
135
+ });
136
+ await use();
137
+ }, {
138
+ auto: true
139
+ }],
140
+ $after: [async ({
141
+ $scenarioHookFixtures,
142
+ $bddWorld,
143
+ $tags
144
+ }, use, $testInfo) => {
145
+ await use();
146
+ await (0, _scenario.runScenarioHooks)('after', {
147
+ $bddWorld,
148
+ $tags,
149
+ $testInfo,
150
+ ...$scenarioHookFixtures
151
+ });
152
+ }, {
153
+ auto: true
154
+ }],
155
+ // can be owerwritten in test file if there are worker hooks
156
+ $workerHookFixtures: [({}, use) => use({}), {
157
+ scope: 'worker'
158
+ }],
159
+ $beforeAll: [
160
+ // Important unused dependencies:
161
+ // 1. $afterAll: in pw < 1.39 worker-scoped auto-fixtures are called in incorrect order
162
+ // 2. $cucumber: to load hooks before this fixtures
163
+ async ({
164
+ $workerHookFixtures,
165
+ $cucumber
166
+ }, use, $workerInfo) => {
167
+ await (0, _worker.runWorkerHooks)('beforeAll', {
168
+ $workerInfo,
169
+ ...$workerHookFixtures
170
+ });
171
+ await use();
172
+ }, {
173
+ auto: true,
174
+ scope: 'worker'
175
+ }],
176
+ $afterAll: [async ({
177
+ $workerHookFixtures
178
+ }, use, $workerInfo) => {
179
+ await use();
180
+ await (0, _worker.runWorkerHooks)('afterAll', {
181
+ $workerInfo,
182
+ ...$workerHookFixtures
183
+ });
184
+ }, {
185
+ auto: true,
186
+ scope: 'worker'
187
+ }]
188
+ });
189
+ const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
190
+ function isBddAutoInjectFixture(name) {
191
+ return BDD_AUTO_INJECT_FIXTURES.includes(name);
192
+ }