@cucumber/cucumber 7.1.0 → 7.3.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 (124) hide show
  1. package/CHANGELOG.md +56 -1
  2. package/README.md +2 -1
  3. package/lib/cli/configuration_builder.js +4 -3
  4. package/lib/cli/configuration_builder.js.map +1 -1
  5. package/lib/cli/helpers.js +40 -18
  6. package/lib/cli/helpers.js.map +1 -1
  7. package/lib/cli/index.js +23 -15
  8. package/lib/cli/index.js.map +1 -1
  9. package/lib/cli/profile_loader.d.ts +1 -2
  10. package/lib/cli/profile_loader.js.map +1 -1
  11. package/lib/cli/publish_banner.js +1 -1
  12. package/lib/cli/publish_banner.js.map +1 -1
  13. package/lib/formatter/get_color_fns.d.ts +6 -2
  14. package/lib/formatter/get_color_fns.js +18 -12
  15. package/lib/formatter/get_color_fns.js.map +1 -1
  16. package/lib/formatter/helpers/event_data_collector.d.ts +14 -17
  17. package/lib/formatter/helpers/event_data_collector.js +14 -8
  18. package/lib/formatter/helpers/event_data_collector.js.map +1 -1
  19. package/lib/formatter/helpers/gherkin_document_parser.d.ts +5 -6
  20. package/lib/formatter/helpers/gherkin_document_parser.js +1 -4
  21. package/lib/formatter/helpers/gherkin_document_parser.js.map +1 -1
  22. package/lib/formatter/helpers/issue_helpers.d.ts +6 -6
  23. package/lib/formatter/helpers/issue_helpers.js +5 -6
  24. package/lib/formatter/helpers/issue_helpers.js.map +1 -1
  25. package/lib/formatter/helpers/pickle_parser.d.ts +9 -10
  26. package/lib/formatter/helpers/pickle_parser.js.map +1 -1
  27. package/lib/formatter/helpers/step_argument_formatter.d.ts +2 -2
  28. package/lib/formatter/helpers/step_argument_formatter.js.map +1 -1
  29. package/lib/formatter/helpers/summary_helpers.d.ts +2 -2
  30. package/lib/formatter/helpers/summary_helpers.js +32 -14
  31. package/lib/formatter/helpers/summary_helpers.js.map +1 -1
  32. package/lib/formatter/helpers/test_case_attempt_formatter.js +33 -14
  33. package/lib/formatter/helpers/test_case_attempt_formatter.js.map +1 -1
  34. package/lib/formatter/helpers/test_case_attempt_parser.d.ts +5 -5
  35. package/lib/formatter/helpers/test_case_attempt_parser.js +27 -9
  36. package/lib/formatter/helpers/test_case_attempt_parser.js.map +1 -1
  37. package/lib/formatter/helpers/usage_helpers/index.d.ts +3 -3
  38. package/lib/formatter/helpers/usage_helpers/index.js +30 -13
  39. package/lib/formatter/helpers/usage_helpers/index.js.map +1 -1
  40. package/lib/formatter/html_formatter.js +1 -1
  41. package/lib/formatter/html_formatter.js.map +1 -1
  42. package/lib/formatter/json_formatter.d.ts +21 -27
  43. package/lib/formatter/json_formatter.js +50 -23
  44. package/lib/formatter/json_formatter.js.map +1 -1
  45. package/lib/formatter/message_formatter.js +1 -1
  46. package/lib/formatter/message_formatter.js.map +1 -1
  47. package/lib/formatter/progress_bar_formatter.d.ts +6 -6
  48. package/lib/formatter/progress_bar_formatter.js +3 -3
  49. package/lib/formatter/progress_bar_formatter.js.map +1 -1
  50. package/lib/formatter/progress_formatter.d.ts +2 -2
  51. package/lib/formatter/progress_formatter.js +29 -10
  52. package/lib/formatter/progress_formatter.js.map +1 -1
  53. package/lib/formatter/rerun_formatter.js +22 -4
  54. package/lib/formatter/rerun_formatter.js.map +1 -1
  55. package/lib/formatter/snippets_formatter.js +21 -2
  56. package/lib/formatter/snippets_formatter.js.map +1 -1
  57. package/lib/formatter/step_definition_snippet_builder/index.d.ts +3 -3
  58. package/lib/formatter/step_definition_snippet_builder/index.js.map +1 -1
  59. package/lib/formatter/step_definition_snippet_builder/javascript_snippet_syntax.js.map +1 -1
  60. package/lib/formatter/summary_formatter.d.ts +2 -2
  61. package/lib/formatter/summary_formatter.js.map +1 -1
  62. package/lib/formatter/usage_formatter.js +22 -3
  63. package/lib/formatter/usage_formatter.js.map +1 -1
  64. package/lib/formatter/usage_json_formatter.js.map +1 -1
  65. package/lib/index.d.ts +14 -12
  66. package/lib/index.js +3 -3
  67. package/lib/index.js.map +1 -1
  68. package/lib/models/data_table.d.ts +3 -4
  69. package/lib/models/data_table.js.map +1 -1
  70. package/lib/models/definition.d.ts +2 -2
  71. package/lib/models/definition.js.map +1 -1
  72. package/lib/models/test_case_hook_definition.d.ts +2 -2
  73. package/lib/models/test_case_hook_definition.js.map +1 -1
  74. package/lib/models/test_step_hook_definition.d.ts +2 -2
  75. package/lib/models/test_step_hook_definition.js.map +1 -1
  76. package/lib/pickle_filter.d.ts +9 -11
  77. package/lib/pickle_filter.js +4 -4
  78. package/lib/pickle_filter.js.map +1 -1
  79. package/lib/runtime/assemble_test_cases.d.ts +13 -0
  80. package/lib/runtime/assemble_test_cases.js +88 -0
  81. package/lib/runtime/assemble_test_cases.js.map +1 -0
  82. package/lib/runtime/attachment_manager/index.d.ts +2 -2
  83. package/lib/runtime/attachment_manager/index.js +23 -4
  84. package/lib/runtime/attachment_manager/index.js.map +1 -1
  85. package/lib/runtime/helpers.d.ts +2 -2
  86. package/lib/runtime/helpers.js.map +1 -1
  87. package/lib/runtime/index.d.ts +4 -3
  88. package/lib/runtime/index.js +31 -13
  89. package/lib/runtime/index.js.map +1 -1
  90. package/lib/runtime/parallel/command_types.d.ts +10 -9
  91. package/lib/runtime/parallel/command_types.js.map +1 -1
  92. package/lib/runtime/parallel/coordinator.d.ts +10 -9
  93. package/lib/runtime/parallel/coordinator.js +54 -43
  94. package/lib/runtime/parallel/coordinator.js.map +1 -1
  95. package/lib/runtime/parallel/worker.d.ts +2 -2
  96. package/lib/runtime/parallel/worker.js +8 -14
  97. package/lib/runtime/parallel/worker.js.map +1 -1
  98. package/lib/runtime/step_runner.d.ts +3 -3
  99. package/lib/runtime/step_runner.js +16 -12
  100. package/lib/runtime/step_runner.js.map +1 -1
  101. package/lib/runtime/stopwatch.d.ts +4 -4
  102. package/lib/runtime/stopwatch.js +21 -2
  103. package/lib/runtime/stopwatch.js.map +1 -1
  104. package/lib/runtime/{pickle_runner.d.ts → test_case_runner.d.ts} +16 -32
  105. package/lib/runtime/{pickle_runner.js → test_case_runner.js} +104 -147
  106. package/lib/runtime/test_case_runner.js.map +1 -0
  107. package/lib/step_arguments.d.ts +4 -4
  108. package/lib/step_arguments.js.map +1 -1
  109. package/lib/support_code_library_builder/index.d.ts +9 -7
  110. package/lib/support_code_library_builder/index.js +11 -10
  111. package/lib/support_code_library_builder/index.js.map +1 -1
  112. package/lib/support_code_library_builder/types.d.ts +21 -23
  113. package/lib/support_code_library_builder/types.js.map +1 -1
  114. package/lib/support_code_library_builder/validate_arguments.js.map +1 -1
  115. package/lib/support_code_library_builder/world.d.ts +7 -1
  116. package/lib/support_code_library_builder/world.js.map +1 -1
  117. package/lib/time.d.ts +2 -10
  118. package/lib/time.js +24 -48
  119. package/lib/time.js.map +1 -1
  120. package/package.json +33 -33
  121. package/lib/runtime/pickle_runner.js.map +0 -1
  122. package/lib/status.d.ts +0 -3
  123. package/lib/status.js +0 -5
  124. package/lib/status.js.map +0 -1
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
23
  };
@@ -8,17 +27,15 @@ const helpers_1 = require("./helpers");
8
27
  const attachment_manager_1 = __importDefault(require("./attachment_manager"));
9
28
  const step_runner_1 = __importDefault(require("./step_runner"));
10
29
  const messages_1 = require("@cucumber/messages");
11
- const time_1 = require("../time");
30
+ const messages = __importStar(require("@cucumber/messages"));
12
31
  const value_checker_1 = require("../value_checker");
13
- const query_1 = require("@cucumber/query");
14
- const { Status } = messages_1.messages.TestStepFinished.TestStepResult;
15
- class PickleRunner {
16
- constructor({ eventBroadcaster, stopwatch, gherkinDocument, newId, pickle, retries = 0, skip, supportCodeLibrary, worldParameters, }) {
32
+ class TestCaseRunner {
33
+ constructor({ eventBroadcaster, stopwatch, gherkinDocument, newId, pickle, testCase, retries = 0, skip, supportCodeLibrary, worldParameters, }) {
17
34
  this.attachmentManager = new attachment_manager_1.default(({ data, media }) => {
18
35
  if (value_checker_1.doesNotHaveValue(this.currentTestStepId)) {
19
36
  throw new Error('Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.');
20
37
  }
21
- this.eventBroadcaster.emit('envelope', messages_1.messages.Envelope.fromObject({
38
+ const attachment = {
22
39
  attachment: {
23
40
  body: data,
24
41
  contentEncoding: media.encoding,
@@ -26,7 +43,8 @@ class PickleRunner {
26
43
  testCaseStartedId: this.currentTestCaseStartedId,
27
44
  testStepId: this.currentTestStepId,
28
45
  },
29
- }));
46
+ };
47
+ this.eventBroadcaster.emit('envelope', attachment);
30
48
  });
31
49
  this.eventBroadcaster = eventBroadcaster;
32
50
  this.stopwatch = stopwatch;
@@ -34,11 +52,10 @@ class PickleRunner {
34
52
  this.maxAttempts = 1 + (skip ? 0 : retries);
35
53
  this.newId = newId;
36
54
  this.pickle = pickle;
55
+ this.testCase = testCase;
37
56
  this.skip = skip;
38
57
  this.supportCodeLibrary = supportCodeLibrary;
39
58
  this.worldParameters = worldParameters;
40
- this.testCaseId = this.newId();
41
- this.testSteps = this.buildTestSteps();
42
59
  this.resetTestProgressData();
43
60
  }
44
61
  resetTestProgressData() {
@@ -49,84 +66,6 @@ class PickleRunner {
49
66
  });
50
67
  this.testStepResults = [];
51
68
  }
52
- buildTestSteps() {
53
- const testSteps = [];
54
- this.getBeforeHookDefinitions().forEach((hookDefinition) => {
55
- testSteps.push({
56
- id: this.newId(),
57
- hookDefinition,
58
- isHook: true,
59
- isBeforeHook: true,
60
- });
61
- });
62
- this.pickle.steps.forEach((pickleStep) => {
63
- const stepDefinitions = this.getStepDefinitions(pickleStep);
64
- testSteps.push({
65
- id: this.newId(),
66
- pickleStep,
67
- stepDefinitions,
68
- isHook: false,
69
- });
70
- });
71
- this.getAfterHookDefinitions().forEach((hookDefinition) => {
72
- testSteps.push({
73
- id: this.newId(),
74
- hookDefinition,
75
- isHook: true,
76
- });
77
- });
78
- return testSteps;
79
- }
80
- emitTestCase() {
81
- const testCase = {
82
- pickleId: this.pickle.id,
83
- id: this.testCaseId,
84
- testSteps: this.testSteps.map((testStep) => {
85
- if (testStep.isHook) {
86
- return {
87
- id: testStep.id,
88
- hookId: testStep.hookDefinition.id,
89
- };
90
- }
91
- else {
92
- return {
93
- id: testStep.id,
94
- pickleStepId: testStep.pickleStep.id,
95
- stepDefinitionIds: testStep.stepDefinitions.map((x) => x.id),
96
- stepMatchArgumentsLists: testStep.stepDefinitions.map((x) => {
97
- const result = x.expression.match(testStep.pickleStep.text);
98
- return {
99
- stepMatchArguments: result.map((arg) => {
100
- return {
101
- group: this.mapArgumentGroup(arg.group),
102
- parameterTypeName: arg.parameterType.name,
103
- };
104
- }),
105
- };
106
- }),
107
- };
108
- }
109
- }),
110
- };
111
- this.eventBroadcaster.emit('envelope', messages_1.messages.Envelope.fromObject({ testCase }));
112
- }
113
- mapArgumentGroup(group) {
114
- return {
115
- start: group.start,
116
- value: group.value,
117
- children: value_checker_1.doesHaveValue(group.children)
118
- ? group.children.map((child) => this.mapArgumentGroup(child))
119
- : undefined,
120
- };
121
- }
122
- getAfterHookDefinitions() {
123
- return lodash_1.clone(this.supportCodeLibrary.afterTestCaseHookDefinitions)
124
- .reverse()
125
- .filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle));
126
- }
127
- getBeforeHookDefinitions() {
128
- return this.supportCodeLibrary.beforeTestCaseHookDefinitions.filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle));
129
- }
130
69
  getBeforeStepHookDefinitions() {
131
70
  return this.supportCodeLibrary.beforeTestStepHookDefinitions.filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle));
132
71
  }
@@ -135,16 +74,17 @@ class PickleRunner {
135
74
  .reverse()
136
75
  .filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle));
137
76
  }
138
- getStepDefinitions(pickleStep) {
139
- return this.supportCodeLibrary.stepDefinitions.filter((stepDefinition) => stepDefinition.matchesStepName(pickleStep.text));
140
- }
141
77
  getWorstStepResult() {
142
78
  if (this.testStepResults.length === 0) {
143
- return messages_1.messages.TestStepFinished.TestStepResult.fromObject({
144
- status: this.skip ? Status.SKIPPED : Status.PASSED,
145
- });
79
+ return {
80
+ status: this.skip
81
+ ? messages.TestStepResultStatus.SKIPPED
82
+ : messages.TestStepResultStatus.PASSED,
83
+ willBeRetried: false,
84
+ duration: messages.TimeConversion.millisecondsToDuration(0),
85
+ };
146
86
  }
147
- return new query_1.Query().getWorstTestStepResult(this.testStepResults);
87
+ return messages_1.getWorstTestStepResult(this.testStepResults);
148
88
  }
149
89
  async invokeStep(step, stepDefinition, hookParameter) {
150
90
  return await step_runner_1.default.run({
@@ -156,24 +96,25 @@ class PickleRunner {
156
96
  });
157
97
  }
158
98
  isSkippingSteps() {
159
- return this.getWorstStepResult().status !== Status.PASSED;
99
+ return (this.getWorstStepResult().status !== messages.TestStepResultStatus.PASSED);
160
100
  }
161
101
  shouldSkipHook(isBeforeHook) {
162
102
  return this.skip || (this.isSkippingSteps() && isBeforeHook);
163
103
  }
164
104
  async aroundTestStep(testStepId, attempt, runStepFn) {
165
- this.eventBroadcaster.emit('envelope', messages_1.messages.Envelope.fromObject({
105
+ const testStepStarted = {
166
106
  testStepStarted: {
167
107
  testCaseStartedId: this.currentTestCaseStartedId,
168
108
  testStepId,
169
109
  timestamp: this.stopwatch.timestamp(),
170
110
  },
171
- }));
111
+ };
112
+ this.eventBroadcaster.emit('envelope', testStepStarted);
172
113
  this.currentTestStepId = testStepId;
173
114
  const testStepResult = await runStepFn();
174
115
  this.currentTestStepId = null;
175
116
  this.testStepResults.push(testStepResult);
176
- if (testStepResult.status === Status.FAILED &&
117
+ if (testStepResult.status === messages.TestStepResultStatus.FAILED &&
177
118
  attempt + 1 < this.maxAttempts) {
178
119
  /*
179
120
  TODO dont rely on `testStepResult.willBeRetried`, it will be moved or removed
@@ -181,51 +122,58 @@ class PickleRunner {
181
122
  */
182
123
  testStepResult.willBeRetried = true;
183
124
  }
184
- this.eventBroadcaster.emit('envelope', messages_1.messages.Envelope.fromObject({
125
+ const testStepFinished = {
185
126
  testStepFinished: {
186
127
  testCaseStartedId: this.currentTestCaseStartedId,
187
128
  testStepId,
188
129
  testStepResult,
189
130
  timestamp: this.stopwatch.timestamp(),
190
131
  },
191
- }));
132
+ };
133
+ this.eventBroadcaster.emit('envelope', testStepFinished);
192
134
  }
193
135
  async run() {
194
- this.emitTestCase();
195
136
  for (let attempt = 0; attempt < this.maxAttempts; attempt++) {
196
137
  this.currentTestCaseStartedId = this.newId();
197
- this.eventBroadcaster.emit('envelope', messages_1.messages.Envelope.fromObject({
138
+ const testCaseStarted = {
198
139
  testCaseStarted: {
199
140
  attempt,
200
- testCaseId: this.testCaseId,
141
+ testCaseId: this.testCase.id,
201
142
  id: this.currentTestCaseStartedId,
202
143
  timestamp: this.stopwatch.timestamp(),
203
144
  },
204
- }));
205
- for (const testStep of this.testSteps) {
145
+ };
146
+ this.eventBroadcaster.emit('envelope', testCaseStarted);
147
+ // used to determine whether a hook is a Before or After
148
+ let didWeRunStepsYet = false;
149
+ for (const testStep of this.testCase.testSteps) {
206
150
  await this.aroundTestStep(testStep.id, attempt, async () => {
207
- if (testStep.isHook) {
151
+ if (value_checker_1.doesHaveValue(testStep.hookId)) {
208
152
  const hookParameter = {
209
153
  gherkinDocument: this.gherkinDocument,
210
154
  pickle: this.pickle,
211
155
  testCaseStartedId: this.currentTestCaseStartedId,
212
156
  };
213
- if (!testStep.isBeforeHook) {
157
+ if (didWeRunStepsYet) {
214
158
  hookParameter.result = this.getWorstStepResult();
215
159
  }
216
- return await this.runHook(testStep.hookDefinition, hookParameter, testStep.isBeforeHook);
160
+ return await this.runHook(findHookDefinition(testStep.hookId, this.supportCodeLibrary), hookParameter, !didWeRunStepsYet);
217
161
  }
218
162
  else {
219
- return await this.runStep(testStep);
163
+ const pickleStep = this.pickle.steps.find((pickleStep) => pickleStep.id === testStep.pickleStepId);
164
+ const testStepResult = await this.runStep(pickleStep, testStep);
165
+ didWeRunStepsYet = true;
166
+ return testStepResult;
220
167
  }
221
168
  });
222
169
  }
223
- this.eventBroadcaster.emit('envelope', messages_1.messages.Envelope.fromObject({
170
+ const testCaseFinished = {
224
171
  testCaseFinished: {
225
172
  testCaseStartedId: this.currentTestCaseStartedId,
226
173
  timestamp: this.stopwatch.timestamp(),
227
174
  },
228
- }));
175
+ };
176
+ this.eventBroadcaster.emit('envelope', testCaseFinished);
229
177
  if (!this.getWorstStepResult().willBeRetried) {
230
178
  break;
231
179
  }
@@ -235,9 +183,11 @@ class PickleRunner {
235
183
  }
236
184
  async runHook(hookDefinition, hookParameter, isBeforeHook) {
237
185
  if (this.shouldSkipHook(isBeforeHook)) {
238
- return messages_1.messages.TestStepFinished.TestStepResult.fromObject({
239
- status: Status.SKIPPED,
240
- });
186
+ return {
187
+ status: messages.TestStepResultStatus.SKIPPED,
188
+ duration: messages.TimeConversion.millisecondsToDuration(0),
189
+ willBeRetried: false,
190
+ };
241
191
  }
242
192
  return await this.invokeStep(null, hookDefinition, hookParameter);
243
193
  }
@@ -255,51 +205,58 @@ class PickleRunner {
255
205
  }
256
206
  return stepHooksResult;
257
207
  }
258
- async runStep(testStep) {
259
- if (testStep.stepDefinitions.length === 0) {
260
- return messages_1.messages.TestStepFinished.TestStepResult.fromObject({
261
- status: Status.UNDEFINED,
262
- duration: {
263
- seconds: '0',
264
- nanos: 0,
265
- },
266
- });
208
+ async runStep(pickleStep, testStep) {
209
+ const stepDefinitions = testStep.stepDefinitionIds.map((stepDefinitionId) => {
210
+ return findStepDefinition(stepDefinitionId, this.supportCodeLibrary);
211
+ });
212
+ if (stepDefinitions.length === 0) {
213
+ return {
214
+ status: messages.TestStepResultStatus.UNDEFINED,
215
+ duration: messages.TimeConversion.millisecondsToDuration(0),
216
+ willBeRetried: false,
217
+ };
267
218
  }
268
- else if (testStep.stepDefinitions.length > 1) {
269
- return messages_1.messages.TestStepFinished.TestStepResult.fromObject({
270
- message: helpers_1.getAmbiguousStepException(testStep.stepDefinitions),
271
- status: Status.AMBIGUOUS,
272
- duration: {
273
- seconds: '0',
274
- nanos: 0,
275
- },
276
- });
219
+ else if (stepDefinitions.length > 1) {
220
+ return {
221
+ message: helpers_1.getAmbiguousStepException(stepDefinitions),
222
+ status: messages.TestStepResultStatus.AMBIGUOUS,
223
+ duration: messages.TimeConversion.millisecondsToDuration(0),
224
+ willBeRetried: false,
225
+ };
277
226
  }
278
227
  else if (this.isSkippingSteps()) {
279
- return messages_1.messages.TestStepFinished.TestStepResult.fromObject({
280
- status: Status.SKIPPED,
281
- duration: {
282
- seconds: '0',
283
- nanos: 0,
284
- },
285
- });
228
+ return {
229
+ status: messages.TestStepResultStatus.SKIPPED,
230
+ duration: messages.TimeConversion.millisecondsToDuration(0),
231
+ willBeRetried: false,
232
+ };
286
233
  }
287
234
  let stepResult;
288
- let stepResults = await this.runStepHooks(this.getBeforeStepHookDefinitions(), stepResult);
289
- if (new query_1.Query().getWorstTestStepResult(stepResults).status !== Status.FAILED) {
290
- stepResult = await this.invokeStep(testStep.pickleStep, testStep.stepDefinitions[0]);
235
+ let stepResults = await this.runStepHooks(this.getBeforeStepHookDefinitions());
236
+ if (messages_1.getWorstTestStepResult(stepResults).status !==
237
+ messages.TestStepResultStatus.FAILED) {
238
+ stepResult = await this.invokeStep(pickleStep, stepDefinitions[0]);
291
239
  stepResults.push(stepResult);
292
240
  }
293
241
  const afterStepHookResults = await this.runStepHooks(this.getAfterStepHookDefinitions(), stepResult);
294
242
  stepResults = stepResults.concat(afterStepHookResults);
295
- const finalStepResult = new query_1.Query().getWorstTestStepResult(stepResults);
296
- let finalDuration = time_1.getZeroDuration();
243
+ const finalStepResult = messages_1.getWorstTestStepResult(stepResults);
244
+ let finalDuration = messages.TimeConversion.millisecondsToDuration(0);
297
245
  for (const result of stepResults) {
298
- finalDuration = time_1.addDurations(finalDuration, result.duration);
246
+ finalDuration = messages.TimeConversion.addDurations(finalDuration, result.duration);
299
247
  }
300
248
  finalStepResult.duration = finalDuration;
301
249
  return finalStepResult;
302
250
  }
303
251
  }
304
- exports.default = PickleRunner;
305
- //# sourceMappingURL=pickle_runner.js.map
252
+ exports.default = TestCaseRunner;
253
+ function findHookDefinition(id, supportCodeLibrary) {
254
+ return [
255
+ ...supportCodeLibrary.beforeTestCaseHookDefinitions,
256
+ ...supportCodeLibrary.afterTestCaseHookDefinitions,
257
+ ].find((definition) => definition.id === id);
258
+ }
259
+ function findStepDefinition(id, supportCodeLibrary) {
260
+ return supportCodeLibrary.stepDefinitions.find((definition) => definition.id === id);
261
+ }
262
+ //# sourceMappingURL=test_case_runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_case_runner.js","sourceRoot":"","sources":["../../src/runtime/test_case_runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA8B;AAC9B,uCAAqD;AACrD,8EAAoD;AACpD,gEAAsC;AACtC,iDAAwE;AACxE,6DAA8C;AAU9C,oDAAkE;AAiBlE,MAAqB,cAAc;IAiBjC,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,KAAK,EACL,MAAM,EACN,QAAQ,EACR,OAAO,GAA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AAkB,CAAC,6BAA6B;QACnD,GAAG,kBAAkB,CAAC,4BAA4B;KACnD,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC;AAED,SAAS,kBAAkB,CACzB,EAAU,EACV,kBAAuC;IAEvC,OAAO,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAC5C,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CACrC,CAAA;AACH,CAAC","sourcesContent":["import { clone } from 'lodash'\nimport { getAmbiguousStepException } from './helpers'\nimport AttachmentManager from './attachment_manager'\nimport StepRunner from './step_runner'\nimport { IdGenerator, getWorstTestStepResult } from '@cucumber/messages'\nimport * as messages from '@cucumber/messages'\nimport { EventEmitter } from 'events'\nimport {\n ISupportCodeLibrary,\n ITestCaseHookParameter,\n ITestStepHookParameter,\n} from '../support_code_library_builder/types'\nimport TestCaseHookDefinition from '../models/test_case_hook_definition'\nimport TestStepHookDefinition from '../models/test_step_hook_definition'\nimport { IDefinition } from '../models/definition'\nimport { doesHaveValue, doesNotHaveValue } from '../value_checker'\nimport { ITestRunStopwatch } from './stopwatch'\nimport StepDefinition from '../models/step_definition'\n\nexport interface INewTestCaseRunnerOptions {\n eventBroadcaster: EventEmitter\n stopwatch: ITestRunStopwatch\n gherkinDocument: messages.GherkinDocument\n newId: IdGenerator.NewId\n pickle: messages.Pickle\n testCase: messages.TestCase\n retries: number\n skip: boolean\n supportCodeLibrary: ISupportCodeLibrary\n worldParameters: any\n}\n\nexport default class TestCaseRunner {\n private readonly attachmentManager: AttachmentManager\n private currentTestCaseStartedId: string\n private currentTestStepId: string\n private readonly eventBroadcaster: EventEmitter\n private readonly stopwatch: ITestRunStopwatch\n private readonly gherkinDocument: messages.GherkinDocument\n private readonly newId: IdGenerator.NewId\n private readonly pickle: messages.Pickle\n private readonly testCase: messages.TestCase\n private readonly maxAttempts: number\n private readonly skip: boolean\n private readonly supportCodeLibrary: ISupportCodeLibrary\n private testStepResults: messages.TestStepResult[]\n private world: any\n private readonly worldParameters: any\n\n constructor({\n eventBroadcaster,\n stopwatch,\n gherkinDocument,\n newId,\n pickle,\n testCase,\n retries = 0,\n skip,\n supportCodeLibrary,\n worldParameters,\n }: INewTestCaseRunnerOptions) {\n this.attachmentManager = new AttachmentManager(({ data, media }) => {\n if (doesNotHaveValue(this.currentTestStepId)) {\n throw new Error(\n 'Cannot attach when a step/hook is not running. Ensure your step/hook waits for the attach to finish.'\n )\n }\n const attachment: messages.Envelope = {\n attachment: {\n body: data,\n contentEncoding: media.encoding,\n mediaType: media.contentType,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n },\n }\n this.eventBroadcaster.emit('envelope', attachment)\n })\n this.eventBroadcaster = eventBroadcaster\n this.stopwatch = stopwatch\n this.gherkinDocument = gherkinDocument\n this.maxAttempts = 1 + (skip ? 0 : retries)\n this.newId = newId\n this.pickle = pickle\n this.testCase = testCase\n this.skip = skip\n this.supportCodeLibrary = supportCodeLibrary\n this.worldParameters = worldParameters\n this.resetTestProgressData()\n }\n\n resetTestProgressData(): void {\n this.world = new this.supportCodeLibrary.World({\n attach: this.attachmentManager.create.bind(this.attachmentManager),\n log: this.attachmentManager.log.bind(this.attachmentManager),\n parameters: this.worldParameters,\n })\n this.testStepResults = []\n }\n\n getBeforeStepHookDefinitions(): TestStepHookDefinition[] {\n return this.supportCodeLibrary.beforeTestStepHookDefinitions.filter(\n (hookDefinition) => hookDefinition.appliesToTestCase(this.pickle)\n )\n }\n\n getAfterStepHookDefinitions(): TestStepHookDefinition[] {\n return clone(this.supportCodeLibrary.afterTestStepHookDefinitions)\n .reverse()\n .filter((hookDefinition) => hookDefinition.appliesToTestCase(this.pickle))\n }\n\n getWorstStepResult(): messages.TestStepResult {\n if (this.testStepResults.length === 0) {\n return {\n status: this.skip\n ? messages.TestStepResultStatus.SKIPPED\n : messages.TestStepResultStatus.PASSED,\n willBeRetried: false,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n }\n }\n return getWorstTestStepResult(this.testStepResults)\n }\n\n async invokeStep(\n step: messages.PickleStep,\n stepDefinition: IDefinition,\n hookParameter?: any\n ): Promise<messages.TestStepResult> {\n return await StepRunner.run({\n defaultTimeout: this.supportCodeLibrary.defaultTimeout,\n hookParameter,\n step,\n stepDefinition,\n world: this.world,\n })\n }\n\n isSkippingSteps(): boolean {\n return (\n this.getWorstStepResult().status !== messages.TestStepResultStatus.PASSED\n )\n }\n\n shouldSkipHook(isBeforeHook: boolean): boolean {\n return this.skip || (this.isSkippingSteps() && isBeforeHook)\n }\n\n async aroundTestStep(\n testStepId: string,\n attempt: number,\n runStepFn: () => Promise<messages.TestStepResult>\n ): Promise<void> {\n const testStepStarted: messages.Envelope = {\n testStepStarted: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepStarted)\n this.currentTestStepId = testStepId\n const testStepResult = await runStepFn()\n this.currentTestStepId = null\n this.testStepResults.push(testStepResult)\n if (\n testStepResult.status === messages.TestStepResultStatus.FAILED &&\n attempt + 1 < this.maxAttempts\n ) {\n /*\n TODO dont rely on `testStepResult.willBeRetried`, it will be moved or removed\n see https://github.com/cucumber/cucumber/issues/902\n */\n testStepResult.willBeRetried = true\n }\n const testStepFinished: messages.Envelope = {\n testStepFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId,\n testStepResult,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testStepFinished)\n }\n\n async run(): Promise<messages.TestStepResultStatus> {\n for (let attempt = 0; attempt < this.maxAttempts; attempt++) {\n this.currentTestCaseStartedId = this.newId()\n const testCaseStarted: messages.Envelope = {\n testCaseStarted: {\n attempt,\n testCaseId: this.testCase.id,\n id: this.currentTestCaseStartedId,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testCaseStarted)\n // used to determine whether a hook is a Before or After\n let didWeRunStepsYet = false\n for (const testStep of this.testCase.testSteps) {\n await this.aroundTestStep(testStep.id, attempt, async () => {\n if (doesHaveValue(testStep.hookId)) {\n const hookParameter: ITestCaseHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n testCaseStartedId: this.currentTestCaseStartedId,\n }\n if (didWeRunStepsYet) {\n hookParameter.result = this.getWorstStepResult()\n }\n return await this.runHook(\n findHookDefinition(testStep.hookId, this.supportCodeLibrary),\n hookParameter,\n !didWeRunStepsYet\n )\n } else {\n const pickleStep = this.pickle.steps.find(\n (pickleStep) => pickleStep.id === testStep.pickleStepId\n )\n const testStepResult = await this.runStep(pickleStep, testStep)\n didWeRunStepsYet = true\n return testStepResult\n }\n })\n }\n const testCaseFinished: messages.Envelope = {\n testCaseFinished: {\n testCaseStartedId: this.currentTestCaseStartedId,\n timestamp: this.stopwatch.timestamp(),\n },\n }\n this.eventBroadcaster.emit('envelope', testCaseFinished)\n if (!this.getWorstStepResult().willBeRetried) {\n break\n }\n this.resetTestProgressData()\n }\n return this.getWorstStepResult().status\n }\n\n async runHook(\n hookDefinition: TestCaseHookDefinition,\n hookParameter: ITestCaseHookParameter,\n isBeforeHook: boolean\n ): Promise<messages.TestStepResult> {\n if (this.shouldSkipHook(isBeforeHook)) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n willBeRetried: false,\n }\n }\n return await this.invokeStep(null, hookDefinition, hookParameter)\n }\n\n async runStepHooks(\n stepHooks: TestStepHookDefinition[],\n stepResult?: messages.TestStepResult\n ): Promise<messages.TestStepResult[]> {\n const stepHooksResult = []\n const hookParameter: ITestStepHookParameter = {\n gherkinDocument: this.gherkinDocument,\n pickle: this.pickle,\n testCaseStartedId: this.currentTestCaseStartedId,\n testStepId: this.currentTestStepId,\n result: stepResult,\n }\n for (const stepHookDefinition of stepHooks) {\n stepHooksResult.push(\n await this.invokeStep(null, stepHookDefinition, hookParameter)\n )\n }\n return stepHooksResult\n }\n\n async runStep(\n pickleStep: messages.PickleStep,\n testStep: messages.TestStep\n ): Promise<messages.TestStepResult> {\n const stepDefinitions = testStep.stepDefinitionIds.map(\n (stepDefinitionId) => {\n return findStepDefinition(stepDefinitionId, this.supportCodeLibrary)\n }\n )\n if (stepDefinitions.length === 0) {\n return {\n status: messages.TestStepResultStatus.UNDEFINED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n willBeRetried: false,\n }\n } else if (stepDefinitions.length > 1) {\n return {\n message: getAmbiguousStepException(stepDefinitions),\n status: messages.TestStepResultStatus.AMBIGUOUS,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n willBeRetried: false,\n }\n } else if (this.isSkippingSteps()) {\n return {\n status: messages.TestStepResultStatus.SKIPPED,\n duration: messages.TimeConversion.millisecondsToDuration(0),\n willBeRetried: false,\n }\n }\n\n let stepResult\n let stepResults = await this.runStepHooks(\n this.getBeforeStepHookDefinitions()\n )\n if (\n getWorstTestStepResult(stepResults).status !==\n messages.TestStepResultStatus.FAILED\n ) {\n stepResult = await this.invokeStep(pickleStep, stepDefinitions[0])\n stepResults.push(stepResult)\n }\n const afterStepHookResults = await this.runStepHooks(\n this.getAfterStepHookDefinitions(),\n stepResult\n )\n stepResults = stepResults.concat(afterStepHookResults)\n\n const finalStepResult = getWorstTestStepResult(stepResults)\n let finalDuration = messages.TimeConversion.millisecondsToDuration(0)\n for (const result of stepResults) {\n finalDuration = messages.TimeConversion.addDurations(\n finalDuration,\n result.duration\n )\n }\n finalStepResult.duration = finalDuration\n return finalStepResult\n }\n}\n\nfunction findHookDefinition(\n id: string,\n supportCodeLibrary: ISupportCodeLibrary\n): TestCaseHookDefinition {\n return [\n ...supportCodeLibrary.beforeTestCaseHookDefinitions,\n ...supportCodeLibrary.afterTestCaseHookDefinitions,\n ].find((definition) => definition.id === id)\n}\n\nfunction findStepDefinition(\n id: string,\n supportCodeLibrary: ISupportCodeLibrary\n): StepDefinition {\n return supportCodeLibrary.stepDefinitions.find(\n (definition) => definition.id === id\n )\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { messages } from '@cucumber/messages';
1
+ import * as messages from '@cucumber/messages';
2
2
  export interface IPickleStepArgumentFunctionMap<T> {
3
- dataTable: (arg: messages.PickleStepArgument.IPickleTable) => T;
4
- docString: (arg: messages.PickleStepArgument.IPickleDocString) => T;
3
+ dataTable: (arg: messages.PickleTable) => T;
4
+ docString: (arg: messages.PickleDocString) => T;
5
5
  }
6
- export declare function parseStepArgument<T>(arg: messages.IPickleStepArgument, mapping: IPickleStepArgumentFunctionMap<T>): T;
6
+ export declare function parseStepArgument<T>(arg: messages.PickleStepArgument, mapping: IPickleStepArgumentFunctionMap<T>): T;
@@ -1 +1 @@
1
- {"version":3,"file":"step_arguments.js","sourceRoot":"","sources":["../src/step_arguments.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAEvB,mDAA+C;AAO/C,SAAgB,iBAAiB,CAC/B,GAAiC,EACjC,OAA0C;IAE1C,IAAI,6BAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QAChC,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;KACxC;SAAM,IAAI,6BAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QACvC,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;KACxC;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AAChE,CAAC;AAVD,8CAUC","sourcesContent":["import util from 'util'\nimport { messages } from '@cucumber/messages'\nimport { doesHaveValue } from './value_checker'\n\nexport interface IPickleStepArgumentFunctionMap<T> {\n dataTable: (arg: messages.PickleStepArgument.IPickleTable) => T\n docString: (arg: messages.PickleStepArgument.IPickleDocString) => T\n}\n\nexport function parseStepArgument<T>(\n arg: messages.IPickleStepArgument,\n mapping: IPickleStepArgumentFunctionMap<T>\n): T {\n if (doesHaveValue(arg.dataTable)) {\n return mapping.dataTable(arg.dataTable)\n } else if (doesHaveValue(arg.docString)) {\n return mapping.docString(arg.docString)\n }\n throw new Error(`Unknown step argument: ${util.inspect(arg)}`)\n}\n"]}
1
+ {"version":3,"file":"step_arguments.js","sourceRoot":"","sources":["../src/step_arguments.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AAEvB,mDAA+C;AAO/C,SAAgB,iBAAiB,CAC/B,GAAgC,EAChC,OAA0C;IAE1C,IAAI,6BAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QAChC,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;KACxC;SAAM,IAAI,6BAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;QACvC,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;KACxC;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,cAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AAChE,CAAC;AAVD,8CAUC","sourcesContent":["import util from 'util'\nimport * as messages from '@cucumber/messages'\nimport { doesHaveValue } from './value_checker'\n\nexport interface IPickleStepArgumentFunctionMap<T> {\n dataTable: (arg: messages.PickleTable) => T\n docString: (arg: messages.PickleDocString) => T\n}\n\nexport function parseStepArgument<T>(\n arg: messages.PickleStepArgument,\n mapping: IPickleStepArgumentFunctionMap<T>\n): T {\n if (doesHaveValue(arg.dataTable)) {\n return mapping.dataTable(arg.dataTable)\n } else if (doesHaveValue(arg.docString)) {\n return mapping.docString(arg.docString)\n }\n throw new Error(`Unknown step argument: ${util.inspect(arg)}`)\n}\n"]}
@@ -1,9 +1,11 @@
1
- import { IdGenerator, messages } from '@cucumber/messages';
1
+ import { IdGenerator } from '@cucumber/messages';
2
+ import * as messages from '@cucumber/messages';
2
3
  import TestCaseHookDefinition from '../models/test_case_hook_definition';
3
4
  import TestStepHookDefinition from '../models/test_step_hook_definition';
4
5
  import TestRunHookDefinition from '../models/test_run_hook_definition';
5
6
  import StepDefinition from '../models/step_definition';
6
7
  import { DefineStepPattern, IDefineStepOptions, IDefineSupportCodeMethods, IDefineTestCaseHookOptions, IDefineTestStepHookOptions, IDefineTestRunHookOptions, IParameterTypeDefinition, ISupportCodeLibrary, TestCaseHookFunction, TestStepHookFunction } from './types';
8
+ import { ICanonicalSupportCodeIds } from '../runtime/parallel/command_types';
7
9
  interface ITestCaseHookDefinitionConfig {
8
10
  code: any;
9
11
  line: number;
@@ -41,21 +43,21 @@ export declare class SupportCodeLibraryBuilder {
41
43
  constructor();
42
44
  defineParameterType(options: IParameterTypeDefinition<any>): void;
43
45
  defineStep(pattern: DefineStepPattern, options: IDefineStepOptions | Function, code?: Function): void;
44
- defineTestCaseHook(getCollection: () => ITestCaseHookDefinitionConfig[]): (options: string | IDefineTestCaseHookOptions | TestCaseHookFunction, code?: TestCaseHookFunction) => void;
45
- defineTestStepHook(getCollection: () => ITestStepHookDefinitionConfig[]): (options: string | IDefineTestStepHookOptions | TestStepHookFunction, code?: TestStepHookFunction) => void;
46
+ defineTestCaseHook(getCollection: () => ITestCaseHookDefinitionConfig[]): <WorldType>(options: string | IDefineTestCaseHookOptions | TestCaseHookFunction<WorldType>, code?: TestCaseHookFunction<WorldType>) => void;
47
+ defineTestStepHook(getCollection: () => ITestStepHookDefinitionConfig[]): <WorldType>(options: string | IDefineTestStepHookOptions | TestStepHookFunction<WorldType>, code?: TestStepHookFunction<WorldType>) => void;
46
48
  defineTestRunHook(getCollection: () => ITestRunHookDefinitionConfig[]): (options: IDefineTestRunHookOptions | Function, code?: Function) => void;
47
49
  wrapCode({ code, wrapperOptions, }: {
48
50
  code: Function;
49
51
  wrapperOptions: any;
50
52
  }): Function;
51
- buildTestCaseHookDefinitions(configs: ITestCaseHookDefinitionConfig[]): TestCaseHookDefinition[];
53
+ buildTestCaseHookDefinitions(configs: ITestCaseHookDefinitionConfig[], canonicalIds?: string[]): TestCaseHookDefinition[];
52
54
  buildTestStepHookDefinitions(configs: ITestStepHookDefinitionConfig[]): TestStepHookDefinition[];
53
55
  buildTestRunHookDefinitions(configs: ITestRunHookDefinitionConfig[]): TestRunHookDefinition[];
54
- buildStepDefinitions(): {
56
+ buildStepDefinitions(canonicalIds?: string[]): {
55
57
  stepDefinitions: StepDefinition[];
56
- undefinedParameterTypes: messages.IUndefinedParameterType[];
58
+ undefinedParameterTypes: messages.UndefinedParameterType[];
57
59
  };
58
- finalize(): ISupportCodeLibrary;
60
+ finalize(canonicalIds?: ICanonicalSupportCodeIds): ISupportCodeLibrary;
59
61
  reset(cwd: string, newId: IdGenerator.NewId): void;
60
62
  }
61
63
  declare const _default: SupportCodeLibraryBuilder;
@@ -35,6 +35,7 @@ class SupportCodeLibraryBuilder {
35
35
  this.defaultTimeout = milliseconds;
36
36
  },
37
37
  setDefinitionFunctionWrapper: (fn) => {
38
+ console.log(`setDefinitionFunctionWrapper is deprecated and will be removed in version 8.0.0 of cucumber-js. If this was used to wrap generator functions, please transition to using async / await. If this was used to wrap step definitions, please use BeforeStep / AfterStep hooks instead. If you had other use cases, please create an issue.`);
38
39
  this.definitionFunctionWrapper = fn;
39
40
  },
40
41
  setWorldConstructor: (fn) => {
@@ -144,15 +145,15 @@ class SupportCodeLibraryBuilder {
144
145
  }
145
146
  return code;
146
147
  }
147
- buildTestCaseHookDefinitions(configs) {
148
- return configs.map(({ code, line, options, uri }) => {
148
+ buildTestCaseHookDefinitions(configs, canonicalIds) {
149
+ return configs.map(({ code, line, options, uri }, index) => {
149
150
  const wrappedCode = this.wrapCode({
150
151
  code,
151
152
  wrapperOptions: options.wrapperOptions,
152
153
  });
153
154
  return new test_case_hook_definition_1.default({
154
155
  code: wrappedCode,
155
- id: this.newId(),
156
+ id: canonicalIds ? canonicalIds[index] : this.newId(),
156
157
  line,
157
158
  options,
158
159
  unwrappedCode: code,
@@ -192,10 +193,10 @@ class SupportCodeLibraryBuilder {
192
193
  });
193
194
  });
194
195
  }
195
- buildStepDefinitions() {
196
+ buildStepDefinitions(canonicalIds) {
196
197
  const stepDefinitions = [];
197
198
  const undefinedParameterTypes = [];
198
- this.stepDefinitionConfigs.forEach(({ code, line, options, pattern, uri }) => {
199
+ this.stepDefinitionConfigs.forEach(({ code, line, options, pattern, uri }, index) => {
199
200
  let expression;
200
201
  if (typeof pattern === 'string') {
201
202
  try {
@@ -222,7 +223,7 @@ class SupportCodeLibraryBuilder {
222
223
  stepDefinitions.push(new step_definition_1.default({
223
224
  code: wrappedCode,
224
225
  expression,
225
- id: this.newId(),
226
+ id: canonicalIds ? canonicalIds[index] : this.newId(),
226
227
  line,
227
228
  options,
228
229
  pattern,
@@ -232,7 +233,7 @@ class SupportCodeLibraryBuilder {
232
233
  });
233
234
  return { stepDefinitions, undefinedParameterTypes };
234
235
  }
235
- finalize() {
236
+ finalize(canonicalIds) {
236
237
  if (value_checker_1.doesNotHaveValue(this.definitionFunctionWrapper)) {
237
238
  const definitionConfigs = lodash_1.default.chain([
238
239
  this.afterTestCaseHookDefinitionConfigs,
@@ -245,12 +246,12 @@ class SupportCodeLibraryBuilder {
245
246
  .value();
246
247
  finalize_helpers_1.validateNoGeneratorFunctions({ cwd: this.cwd, definitionConfigs });
247
248
  }
248
- const stepDefinitionsResult = this.buildStepDefinitions();
249
+ const stepDefinitionsResult = this.buildStepDefinitions(canonicalIds === null || canonicalIds === void 0 ? void 0 : canonicalIds.stepDefinitionIds);
249
250
  return {
250
- afterTestCaseHookDefinitions: this.buildTestCaseHookDefinitions(this.afterTestCaseHookDefinitionConfigs),
251
+ afterTestCaseHookDefinitions: this.buildTestCaseHookDefinitions(this.afterTestCaseHookDefinitionConfigs, canonicalIds === null || canonicalIds === void 0 ? void 0 : canonicalIds.afterTestCaseHookDefinitionIds),
251
252
  afterTestRunHookDefinitions: this.buildTestRunHookDefinitions(this.afterTestRunHookDefinitionConfigs),
252
253
  afterTestStepHookDefinitions: this.buildTestStepHookDefinitions(this.afterTestStepHookDefinitionConfigs),
253
- beforeTestCaseHookDefinitions: this.buildTestCaseHookDefinitions(this.beforeTestCaseHookDefinitionConfigs),
254
+ beforeTestCaseHookDefinitions: this.buildTestCaseHookDefinitions(this.beforeTestCaseHookDefinitionConfigs, canonicalIds === null || canonicalIds === void 0 ? void 0 : canonicalIds.beforeTestCaseHookDefinitionIds),
254
255
  beforeTestRunHookDefinitions: this.buildTestRunHookDefinitions(this.beforeTestRunHookDefinitionConfigs),
255
256
  beforeTestStepHookDefinitions: this.buildTestStepHookDefinitions(this.beforeTestStepHookDefinitionConfigs),
256
257
  defaultTimeout: this.defaultTimeout,