@autometa/jest-executor 0.6.3 → 1.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,989 +1,36 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import { registerFeaturePlan } from '@autometa/executor';
19
2
 
20
3
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- default: () => src_default,
24
- execute: () => execute,
25
- getTimeout: () => getTimeout
26
- });
27
- module.exports = __toCommonJS(src_exports);
28
-
29
- // src/executor.ts
30
- var import_test_builder = require("@autometa/test-builder");
31
- var import_globals = require("@jest/globals");
32
- var import_errors = require("@autometa/errors");
33
- var import_test_builder2 = require("@autometa/test-builder");
34
-
35
- // src/timeout-selector.ts
36
- var import_scopes = require("@autometa/scopes");
37
- function getTimeout(target, config) {
38
- if (target && !(target instanceof import_scopes.NullTimeout)) {
39
- return target;
40
- }
41
- return import_scopes.Timeout.from(config?.current?.test?.timeout);
42
- }
43
- function chooseTimeout(timeout1, timeout2) {
44
- if (timeout2 instanceof import_scopes.Timeout && !(timeout2 instanceof import_scopes.NullTimeout)) {
45
- return {
46
- getTimeout: getTimeout.bind(null, timeout2)
47
- };
48
- }
49
- if (timeout1 instanceof import_scopes.Timeout && !(timeout1 instanceof import_scopes.NullTimeout)) {
50
- return {
51
- getTimeout: getTimeout.bind(null, timeout1)
52
- };
53
- }
54
- return {
55
- getTimeout: getTimeout.bind(null, import_scopes.Timeout.from(0))
56
- };
57
- }
58
-
59
- // src/executor.ts
60
- var import_scopes2 = require("@autometa/scopes");
61
- var import_injection = require("@autometa/injection");
62
- var import_gherkin = require("@autometa/gherkin");
63
- var outlineApps = /* @__PURE__ */ new Map();
64
- var examplesApps = /* @__PURE__ */ new Map();
65
- var featureApps = /* @__PURE__ */ new Map();
66
- var ruleApps = /* @__PURE__ */ new Map();
67
- function execute({ app, world }, global, bridge, events, config) {
68
- const globalBridge = new import_test_builder.GlobalBridge(global);
69
- const featureTitle = bridge.data.scope.title(bridge.data.gherkin);
70
- const [group, modifier] = getGroupOrModifier(
71
- bridge,
72
- config.current.test?.tagFilter
73
- );
74
- const chosenTimeout = chooseTimeout(
75
- new import_scopes2.NullTimeout(),
76
- bridge.data.scope.timeout
77
- ).getTimeout(config);
78
- (0, import_globals.beforeAll)(() => {
79
- events.feature.emitStart({
80
- title: featureTitle,
81
- path: bridge.data.scope.path,
82
- modifier,
83
- tags: [...bridge.data.gherkin.tags]
84
- });
85
- }, chosenTimeout.milliseconds);
86
- group(featureTitle, () => {
87
- const tags = [...bridge.data.gherkin.tags];
88
- const retries = tags.find((tag) => tag.startsWith("@retries="));
89
- let testContainerContext;
90
- let testContainer;
91
- let localApp;
92
- const globalContainerContext = (0, import_injection.defineContainerContext)("global");
93
- const globalContainer = new import_injection.Container(globalContainerContext);
94
- globalContainer.registerCached(world);
95
- const staticApp = globalContainer.get(app);
96
- staticApp.world = globalContainer.get(world);
97
- staticApp.di = globalContainer;
98
- (0, import_globals.beforeAll)(() => {
99
- if (retries) {
100
- const count = parseInt(retries.split("=")[1]);
101
- import_globals.jest.retryTimes(count);
102
- }
103
- });
104
- (0, import_globals.beforeEach)(() => {
105
- const name = import_globals.expect.getState().currentTestName ?? (0, import_errors.raise)("A test must have a name");
106
- testContainerContext = (0, import_injection.defineContainerContext)(name);
107
- testContainer = new import_injection.Container(testContainerContext);
108
- testContainer.registerCached(world);
109
- localApp = testContainer.get(app);
110
- localApp.world = testContainer.get(world);
111
- localApp.di = testContainer;
112
- if (!featureApps.has(name)) {
113
- featureApps.set(name, []);
114
- }
115
- featureApps.get(name)?.push(localApp);
116
- });
117
- bridge.data.scope.hooks.beforeFeatureHooks.forEach((hook) => {
118
- const hookTimeout = chooseTimeout(
119
- chosenTimeout,
120
- hook.options.timeout
121
- ).getTimeout(config).milliseconds;
122
- (0, import_globals.beforeAll)(async () => {
123
- const tags2 = bridge?.data?.gherkin?.tags ?? [];
124
- if (!hook.canExecute(...tags2)) {
125
- return;
126
- }
127
- events.beforeFeature.emitStart({
128
- title: hook.description,
129
- tags: [...tags2]
130
- });
131
- const report = await hook.execute(staticApp, ...tags2);
132
- if (report.error) {
133
- const message = `${hook.name}: ${hook.description} failed to execute.`;
134
- events.beforeFeature.emitEnd({
135
- title: hook.description,
136
- tags: [...tags2],
137
- status: "FAILED",
138
- error: report.error
139
- });
140
- throw new import_errors.AutomationError(message, { cause: report.error });
141
- }
142
- events.beforeFeature.emitEnd({
143
- title: hook.description,
144
- tags: [...tags2],
145
- status: "PASSED"
146
- });
147
- }, hookTimeout);
148
- });
149
- bridge.data.scope.hooks.afterFeatureHooks.forEach((hook) => {
150
- const hookTimeout = chooseTimeout(
151
- chosenTimeout,
152
- hook.options.timeout
153
- ).getTimeout(config).milliseconds;
154
- (0, import_globals.afterAll)(async () => {
155
- const tags2 = bridge?.data?.gherkin?.tags ?? [];
156
- if (!hook.canExecute(...bridge.data.gherkin.tags)) {
157
- return;
158
- }
159
- events.afterFeature.emitStart({
160
- title: hook.description,
161
- tags: [...tags2]
162
- });
163
- const testName = import_globals.expect.getState().currentTestName;
164
- const apps = featureApps.get(testName);
165
- const report = await hook.execute(staticApp, apps, ...tags2);
166
- if (report.error) {
167
- const message = `${hook.name}: ${hook.description} failed to execute.`;
168
- events.afterFeature.emitEnd({
169
- title: hook.description,
170
- tags: [...tags2],
171
- status: "FAILED",
172
- error: report.error
173
- });
174
- throw new import_errors.AutomationError(message, { cause: report.error });
175
- }
176
- events.afterFeature.emitEnd({
177
- title: hook.description,
178
- tags: [...tags2],
179
- status: "PASSED"
180
- });
181
- }, hookTimeout);
182
- });
183
- bootstrapSetupHooks(globalBridge, staticApp, events, [
184
- config,
185
- chosenTimeout
186
- ]);
187
- bootstrapSetupHooks(bridge, staticApp, events, [config, chosenTimeout]);
188
- bootstrapBeforeHooks(
189
- bridge,
190
- globalBridge,
191
- () => [testContainer, localApp],
192
- events,
193
- [config, chosenTimeout]
194
- );
195
- bootstrapBeforeHooks(
196
- bridge,
197
- bridge,
198
- () => [testContainer, localApp],
199
- events,
200
- [config, chosenTimeout]
201
- );
202
- bootstrapBackground(bridge, bridge, () => [testContainer, localApp], events, [
203
- config,
204
- chosenTimeout
205
- ]);
206
- bootstrapScenarios(
207
- bridge,
208
- bridge,
209
- () => [testContainer, localApp],
210
- staticApp,
211
- events,
212
- [config, chosenTimeout]
213
- );
214
- bootstrapRules(bridge, () => [testContainer, localApp], staticApp, events, [
215
- config,
216
- chosenTimeout
217
- ]);
218
- bootstrapAfterHooks(bridge, bridge, () => [testContainer, localApp], events, [
219
- config,
220
- chosenTimeout
221
- ]);
222
- bootstrapAfterHooks(bridge, globalBridge, () => [testContainer, localApp], events, [
223
- config,
224
- chosenTimeout
225
- ]);
226
- bootstrapTeardownHooks(globalBridge, staticApp, events, [
227
- config,
228
- chosenTimeout
229
- ]);
230
- bootstrapTeardownHooks(bridge, staticApp, events, [config, chosenTimeout]);
231
- (0, import_globals.afterAll)(async () => {
232
- await globalContainer.disposeGlobal(tags, import_gherkin.isTagsMatch);
233
- });
234
- });
235
- (0, import_globals.afterAll)(async () => {
236
- const failures = import_test_builder2.Query.find.failed(bridge);
237
- const status = modifier === "skip" ? "SKIPPED" : failures.length === 0 ? "PASSED" : "FAILED";
238
- events.feature.emitEnd({
239
- title: featureTitle,
240
- modifier,
241
- tags: [...bridge.data.gherkin.tags],
242
- status
243
- });
244
- const settled = await events.settleAsyncEvents();
245
- const failedCount = settled.filter((e) => e.status === "rejected").length;
246
- if (failedCount > 0) {
247
- const count = `${failedCount}/${settled.length}`;
248
- const message = `${count} asynchronous Test Events were rejected.`;
249
- console.warn(message);
250
- }
251
- featureApps.clear();
252
- outlineApps.clear();
253
- examplesApps.clear();
254
- ruleApps.clear();
255
- });
256
- }
257
- function bootstrapBackground(root, bridge, localApp, events, [config, timeout]) {
258
- const background = bridge.background;
259
- if (!background)
260
- return;
261
- const chosenTimeout = chooseTimeout(
262
- timeout,
263
- bridge.data.scope.timeout
264
- ).getTimeout(config).milliseconds;
265
- const tags = bridge?.data?.gherkin?.tags ?? [];
266
- if (tags.has("@skip") || tags.has("@skipped"))
267
- return;
268
- (0, import_globals.beforeEach)(async () => {
269
- const testName = import_globals.expect.getState().currentTestName;
270
- if (!testName)
271
- throw new import_errors.AutomationError("A Scenario must have a title");
272
- const scenarioBridge = (0, import_test_builder.find)(root, testName);
273
- if (!scenarioBridge) {
274
- throw new import_errors.AutomationError(
275
- `No matching scenario bridge was found matching the test name: ${testName}`
276
- );
277
- }
278
- const title = background.data.scope.title(background.data.gherkin);
279
- events.before.emitStart({
280
- title,
281
- tags: [...tags]
282
- });
283
- const steps = background.steps;
284
- try {
285
- for (const step of steps) {
286
- const [_, app] = localApp();
287
- const args = step.args?.(app) ?? [];
288
- const title2 = step.data.scope.stepText(
289
- step.data.gherkin.keyword,
290
- step.data.gherkin.text
291
- );
292
- events.step.emitStart({
293
- title: title2,
294
- args,
295
- expression: step.data.scope.expression.source
296
- });
297
- await step.data.scope.execute(step.data.gherkin, args, app);
298
- events.step.emitEnd({
299
- expression: step.data.scope.expression.source,
300
- title: title2,
301
- args
302
- });
303
- }
304
- events.before.emitEnd({
305
- title,
306
- tags: [...tags],
307
- status: "PASSED"
308
- });
309
- } catch (e) {
310
- events.before.emitEnd({
311
- title,
312
- tags: [...tags],
313
- status: "FAILED",
314
- error: e
315
- });
316
- const message = `${title} failed to execute.
317
- Test: ${testName}`;
318
- throw new import_errors.AutomationError(message, { cause: e });
319
- }
320
- }, chosenTimeout);
321
- }
322
- function bootstrapScenarios(root, bridge, localApp, staticApp, events, [config, timeout]) {
323
- const { scenarios } = bridge;
324
- const chosenTimeout = chooseTimeout(
325
- timeout,
326
- bridge.data.scope.timeout
327
- ).getTimeout(config);
328
- scenarios.forEach((scenario) => {
329
- if (isOutline(scenario)) {
330
- bootstrapScenarioOutline(root, scenario, localApp, staticApp, events, [
331
- config,
332
- chosenTimeout
333
- ]);
334
- return;
335
- }
336
- bootstrapScenario(scenario, localApp, events, [config, chosenTimeout]);
337
- });
338
- }
339
- function bootstrapScenario(bridge, localApp, events, [config, timeout]) {
340
- const { data } = bridge;
341
- const chosenTimeout = chooseTimeout(
342
- timeout,
343
- bridge.data.scope.timeout
344
- ).getTimeout(config);
345
- const scenarioName = data.scope.title(data.gherkin);
346
- const test = getTestOrModifier(bridge, config.current.test?.tagFilter);
347
- test(
348
- scenarioName,
349
- async () => {
350
- events.scenario.emitStart({
351
- title: bridge.title,
352
- tags: bridge.tags
353
- });
354
- const [container, app] = localApp();
355
- try {
356
- for (const step of bridge.steps) {
357
- await tryRunStep(step, events, bridge, () => app);
358
- }
359
- bridge.report = { passed: true };
360
- events.scenario.emitEnd({
361
- title: bridge.title,
362
- tags: bridge.tags,
363
- status: "PASSED"
364
- });
365
- } catch (e) {
366
- const error = e;
367
- bridge.report = { passed: false, error: e };
368
- events.scenario.emitEnd({
369
- title: bridge.title,
370
- tags: bridge.tags,
371
- status: "FAILED",
372
- error
373
- });
374
- const message = `${bridge.title} failed while executing a step`;
375
- const meta = { cause: error };
376
- throw new import_errors.AutomationError(message, meta);
377
- } finally {
378
- await container.disposeAll(bridge.tags, import_gherkin.isTagsMatch);
379
- }
380
- },
381
- chosenTimeout.milliseconds
382
- );
383
- }
384
- async function tryRunStep(step, events, bridge, localApp) {
385
- await bootstrapStep(step, events, bridge, localApp);
386
- }
387
- async function bootstrapStep(step, events, bridge, localApp) {
388
- const title = step.data.scope.stepText(
389
- step.data.gherkin.keyword,
390
- step.data.gherkin.text
391
- );
392
- let args = [];
393
- try {
394
- const app = localApp();
395
- args = step.args?.(app) ?? [];
396
- events.step.emitStart({
397
- title,
398
- args,
399
- expression: step.expressionText
400
- });
401
- await step.data.scope.execute(step.data.gherkin, args, app);
402
- events.step.emitEnd({
403
- expression: step.expressionText,
404
- title,
405
- args,
406
- status: "PASSED"
407
- });
408
- } catch (e) {
409
- const error = e;
410
- events.step.emitEnd({
411
- expression: step.expressionText,
412
- title,
413
- args,
414
- status: "FAILED",
415
- error: e
416
- });
417
- const message = `${title} experienced an error`;
418
- const meta = { cause: error };
419
- const newError = new import_errors.AutomationError(message, meta);
420
- console.error((0, import_errors.formatErrorCauses)(newError));
421
- throw newError;
422
- }
423
- }
424
- function isOutline(data) {
425
- return data instanceof import_test_builder.ScenarioOutlineBridge;
426
- }
427
- function bootstrapScenarioOutline(root, bridge, localApp, staticApp, events, [config, timeout]) {
428
- const {
429
- data: { scope, gherkin },
430
- examples
431
- } = bridge;
432
- const title = scope.title(gherkin);
433
- const retry = [...gherkin.tags].find((tag) => tag.startsWith("@retries="));
434
- const { beforeScenarioOutlineHooks, afterScenarioOutlineHooks } = scope.hooks;
435
- const [group, modifier] = getGroupOrModifier(
436
- bridge,
437
- config.current.test?.tagFilter
438
- );
439
- const chosenTimeout = chooseTimeout(
440
- timeout,
441
- bridge.data.scope.timeout
442
- ).getTimeout(config).milliseconds;
443
- const original = localApp;
444
- localApp = () => {
445
- const testName = import_globals.expect.getState().currentTestName;
446
- if (!outlineApps.has(testName)) {
447
- outlineApps.set(testName, []);
448
- }
449
- const apps = outlineApps.get(testName);
450
- const [container, app] = original();
451
- apps.push(app);
452
- return [container, app];
453
- };
454
- group(title, () => {
455
- beforeScenarioOutlineHooks.forEach((hook) => {
456
- const hookTimeout = chooseTimeout(
457
- timeout,
458
- hook.options.timeout
459
- ).getTimeout(config).milliseconds;
460
- (0, import_globals.beforeAll)(async () => {
461
- if (!hook.canExecute(...gherkin.tags)) {
462
- return;
463
- }
464
- events.beforeScenarioOutline.emitStart({
465
- title,
466
- modifier,
467
- tags: [...gherkin.tags]
468
- });
469
- const tags = gherkin.tags ?? [];
470
- events.beforeScenarioOutline.emitStart({
471
- title,
472
- modifier,
473
- tags: [...gherkin.tags]
474
- });
475
- const report = await hook.execute(staticApp, ...tags);
476
- if (report.error) {
477
- const message = `${hook.name}: ${hook.description} failed to execute.`;
478
- events.beforeScenarioOutline.emitEnd({
479
- title,
480
- modifier,
481
- error: report.error,
482
- tags: [...gherkin.tags],
483
- status: "FAILED"
484
- });
485
- throw new import_errors.AutomationError(message, { cause: report.error });
486
- }
487
- events.beforeScenarioOutline.emitEnd({
488
- title,
489
- modifier,
490
- tags: [...gherkin.tags],
491
- status: "PASSED"
492
- });
493
- }, hookTimeout);
494
- });
495
- (0, import_globals.beforeAll)(() => {
496
- if (retry) {
497
- const count = parseInt(retry.split("=")[1]);
498
- import_globals.jest.retryTimes(count);
499
- }
500
- events.scenarioOutline.emitStart({
501
- title,
502
- modifier,
503
- tags: [...gherkin.tags]
504
- });
505
- });
506
- bootstrapSetupHooks(bridge, staticApp, events, [config, timeout]);
507
- bootstrapBeforeHooks(root, bridge, localApp, events, [config, timeout]);
508
- examples.forEach((example) => {
509
- bootstrapExamples(root, example, localApp, staticApp, events, [
510
- config,
511
- timeout
512
- ]);
513
- });
514
- bootstrapAfterHooks(root, bridge, localApp, events, [config, timeout]);
515
- bootstrapTeardownHooks(bridge, staticApp, events, [config, timeout]);
516
- afterScenarioOutlineHooks.forEach((hook) => {
517
- const hookTimeout = chooseTimeout(
518
- timeout,
519
- hook.options.timeout
520
- ).getTimeout(config).milliseconds;
521
- (0, import_globals.afterAll)(async () => {
522
- if (!hook.canExecute(...gherkin.tags)) {
523
- return;
524
- }
525
- const testName = import_globals.expect.getState().currentTestName;
526
- const tags = gherkin.tags ?? [];
527
- const apps = outlineApps.get(testName);
528
- events.afterScenarioOutline.emitStart({
529
- title,
530
- modifier,
531
- tags: [...gherkin.tags]
532
- });
533
- const report = await hook.execute(staticApp, apps, ...tags);
534
- if (report.error) {
535
- const message = `${hook.name}: ${hook.description} failed to execute.`;
536
- events.scenarioOutline.emitEnd({
537
- title,
538
- modifier,
539
- error: report.error,
540
- tags: [...gherkin.tags],
541
- status: "FAILED"
542
- });
543
- throw new import_errors.AutomationError(message, { cause: report.error });
544
- }
545
- events.afterScenarioOutline.emitEnd({
546
- title,
547
- modifier,
548
- tags: [...gherkin.tags],
549
- status: "PASSED"
550
- });
551
- }, hookTimeout);
552
- });
553
- (0, import_globals.afterAll)(() => {
554
- const failures = import_test_builder2.Query.find.failed(bridge);
555
- const status = getStatus(modifier, failures);
556
- events.scenarioOutline.emitEnd({
557
- title,
558
- modifier,
559
- tags: [...gherkin.tags],
560
- status
561
- });
562
- outlineApps.clear();
563
- examplesApps.clear();
564
- }, chosenTimeout);
565
- });
566
- }
567
- function bootstrapExamples(root, example, localApp, staticApp, events, timeout) {
568
- const { gherkin } = example.data;
569
- const title = `${gherkin.keyword}: ${gherkin.name}`;
570
- const retry = [...example.data.gherkin.tags].find(
571
- (tag) => tag.startsWith("@retries=")
572
- );
573
- const original = localApp;
574
- localApp = () => {
575
- const testName = import_globals.expect.getState().currentTestName ?? "unnamed test";
576
- if (!examplesApps.has(testName)) {
577
- examplesApps.set(testName, []);
578
- }
579
- const apps = examplesApps.get(testName);
580
- const [container, app] = original();
581
- apps.push(app);
582
- return [container, app];
583
- };
584
- const [group] = getGroupOrModifier(
585
- example,
586
- timeout[0].current.test?.tagFilter
587
- );
588
- group(title, () => {
589
- (0, import_globals.beforeAll)(() => {
590
- if (retry) {
591
- const count = parseInt(retry.split("=")[1]);
592
- import_globals.jest.retryTimes(count);
593
- }
594
- });
595
- example.data.scope.hooks.beforeExamplesHooks.forEach((hook) => {
596
- const hookTimeout = chooseTimeout(
597
- timeout[1],
598
- hook.options.timeout
599
- ).getTimeout(timeout[0]).milliseconds;
600
- (0, import_globals.beforeAll)(async () => {
601
- if (!hook.canExecute(...example.data.gherkin.tags)) {
602
- return;
603
- }
604
- const tags = example?.data?.gherkin?.tags ?? [];
605
- events.beforeExamples.emitStart({
606
- title,
607
- tags: [...tags]
608
- });
609
- const report = await hook.execute(staticApp, ...tags);
610
- if (report.error) {
611
- const message = `${hook.name}: ${hook.description} failed to execute.`;
612
- events.beforeExamples.emitEnd({
613
- title,
614
- error: report.error,
615
- tags: [...tags],
616
- status: "FAILED"
617
- });
618
- throw new import_errors.AutomationError(message, { cause: report.error });
619
- }
620
- events.beforeExamples.emitEnd({
621
- title,
622
- tags: [...tags],
623
- status: "PASSED"
624
- });
625
- }, hookTimeout);
626
- });
627
- bootstrapScenarios(root, example, localApp, staticApp, events, timeout);
628
- example.data.scope.hooks.afterExamplesHooks.forEach((hook) => {
629
- const hookTimeout = chooseTimeout(
630
- timeout[1],
631
- hook.options.timeout
632
- ).getTimeout(timeout[0]).milliseconds;
633
- (0, import_globals.afterAll)(async () => {
634
- const testName = import_globals.expect.getState().currentTestName;
635
- if (!hook.canExecute(...example.data.gherkin.tags)) {
636
- return;
637
- }
638
- const tags = example?.data?.gherkin?.tags ?? [];
639
- const apps = examplesApps.get(testName);
640
- const report = await hook.execute(staticApp, apps, ...tags);
641
- if (report.error) {
642
- const message = `${hook.name}: ${hook.description} failed to execute.`;
643
- throw new import_errors.AutomationError(message, { cause: report.error });
644
- }
645
- }, hookTimeout);
646
- });
647
- (0, import_globals.afterAll)(() => {
648
- const testName = import_globals.expect.getState().currentTestName;
649
- examplesApps.delete(testName);
650
- });
651
- });
652
- }
653
- function bootstrapRules(bridge, localApp, staticApp, events, [config, timeout]) {
654
- const chosenTimeout = chooseTimeout(
655
- timeout,
656
- bridge.data.scope.timeout
657
- ).getTimeout(config);
658
- bridge.rules.forEach((rule) => {
659
- const tags = [...rule.data.gherkin.tags];
660
- const retry = tags.find((tag) => tag.startsWith("@retries="));
661
- const ruleTimeout = chooseTimeout(
662
- chosenTimeout,
663
- rule.data.scope.timeout
664
- ).getTimeout(config);
665
- const transferTimeout = [config, ruleTimeout];
666
- const { data } = rule;
667
- const ruleName = data.scope.title(data.gherkin);
668
- const [group, modifier] = getGroupOrModifier(
669
- bridge,
670
- config.current.test?.tagFilter
671
- );
672
- group(ruleName, () => {
673
- (0, import_globals.beforeAll)(() => {
674
- events.rule.emitStart({
675
- title: ruleName,
676
- modifier,
677
- tags: [...data.gherkin.tags]
678
- });
679
- if (retry) {
680
- const count = parseInt(retry.split("=")[1]);
681
- import_globals.jest.retryTimes(count);
682
- }
683
- const original = localApp;
684
- localApp = () => {
685
- const testName = import_globals.expect.getState().currentTestName;
686
- if (!ruleApps.has(testName)) {
687
- ruleApps.set(testName, []);
688
- }
689
- const apps = ruleApps.get(testName);
690
- const [container, app] = original();
691
- apps.push(app);
692
- return [container, app];
693
- };
694
- });
695
- bridge.data.scope.hooks.beforeRuleHooks.forEach((hook) => {
696
- const hookTimeout = chooseTimeout(
697
- ruleTimeout,
698
- hook.options.timeout
699
- ).getTimeout(config).milliseconds;
700
- (0, import_globals.beforeAll)(async () => {
701
- if (!hook.canExecute(...data.gherkin.tags)) {
702
- return;
703
- }
704
- const tags2 = data.gherkin.tags ?? [];
705
- events.beforeRule.emitStart({
706
- title: `${hook.name}: ${hook.description}`,
707
- tags: [...tags2]
708
- });
709
- const report = await hook.execute(staticApp, ...tags2);
710
- if (report.error) {
711
- const message = `${hook.name}: ${hook.description} failed to execute.`;
712
- events.beforeRule.emitEnd({
713
- title: `${hook.name}: ${hook.description}`,
714
- tags: [...tags2],
715
- status: "FAILED",
716
- error: report.error
717
- });
718
- throw new import_errors.AutomationError(message, { cause: report.error });
719
- }
720
- events.beforeRule.emitEnd({
721
- title: `${hook.name}: ${hook.description}`,
722
- tags: [...tags2],
723
- status: "PASSED"
724
- });
725
- }, hookTimeout);
726
- });
727
- bridge.data.scope.hooks.afterRuleHooks.forEach((hook) => {
728
- const hookTimeout = chooseTimeout(
729
- ruleTimeout,
730
- hook.options.timeout
731
- ).getTimeout(config).milliseconds;
732
- (0, import_globals.afterAll)(async () => {
733
- const testName = import_globals.expect.getState().currentTestName;
734
- if (!hook.canExecute(...data.gherkin.tags)) {
735
- return;
736
- }
737
- const tags2 = data.gherkin.tags ?? [];
738
- const apps = ruleApps.get(testName);
739
- events.afterRule.emitStart({
740
- title: `${hook.name}: ${hook.description}`,
741
- tags: [...tags2]
742
- });
743
- const report = await hook.execute(staticApp, apps, ...tags2);
744
- if (report.error) {
745
- const message = `${hook.name}: ${hook.description} failed to execute.`;
746
- events.afterRule.emitEnd({
747
- title: `${hook.name}: ${hook.description}`,
748
- tags: [...tags2],
749
- status: "FAILED",
750
- error: report.error
751
- });
752
- throw new import_errors.AutomationError(message, { cause: report.error });
753
- }
754
- events.afterRule.emitEnd({
755
- title: `${hook.name}: ${hook.description}`,
756
- tags: [...tags2],
757
- status: "PASSED"
758
- });
759
- }, hookTimeout);
760
- });
761
- bootstrapSetupHooks(rule, staticApp, events, transferTimeout);
762
- bootstrapBeforeHooks(bridge, rule, localApp, events, transferTimeout);
763
- bootstrapBackground(bridge, rule, localApp, events, transferTimeout);
764
- bootstrapScenarios(
765
- bridge,
766
- rule,
767
- localApp,
768
- staticApp,
769
- events,
770
- transferTimeout
771
- );
772
- bootstrapAfterHooks(bridge, rule, localApp, events, transferTimeout);
773
- bootstrapTeardownHooks(rule, staticApp, events, transferTimeout);
774
- (0, import_globals.afterAll)(() => {
775
- const failures = import_test_builder2.Query.find.failed(rule);
776
- const status = getStatus(modifier, failures);
777
- events.rule.emitEnd({
778
- title: ruleName,
779
- modifier,
780
- tags: [...data.gherkin.tags],
781
- status
782
- });
783
- const testName = import_globals.expect.getState().currentTestName;
784
- ruleApps.delete(testName);
785
- }, ruleTimeout.milliseconds);
786
- });
787
- });
788
- }
789
- function getStatus(modifier, failures) {
790
- if (modifier === "skip") {
791
- return "SKIPPED";
4
+ var runtime = {
5
+ suite: describe,
6
+ test: it,
7
+ beforeAll,
8
+ afterAll,
9
+ beforeEach,
10
+ afterEach,
11
+ currentTestName: () => expect.getState().currentTestName,
12
+ retry: (count) => {
13
+ if (typeof jest?.retryTimes === "function") {
14
+ jest.retryTimes(count);
15
+ }
16
+ },
17
+ warn: (message) => {
18
+ console.warn(message);
19
+ },
20
+ logError: (error) => {
21
+ console.error(error);
792
22
  }
793
- if (failures.length === 0) {
794
- return "PASSED";
795
- }
796
- return "FAILED";
797
- }
798
- function getGroupOrModifier(bridge, tagFilter) {
799
- const { data } = bridge;
800
- if (data.gherkin.tags?.has("@skip") || data.gherkin.tags?.has("@skipped")) {
801
- return [import_globals.describe.skip, "skip"];
802
- }
803
- if (data.gherkin.tags?.has("@only")) {
804
- return [import_globals.describe.only, "only"];
805
- }
806
- if (tagFilter) {
807
- const parse = require("@cucumber/tag-expressions").default;
808
- const expression = parse(tagFilter).evaluate([...bridge.data.gherkin.tags]);
809
- if (!expression) {
810
- return [import_globals.describe.skip, "skip"];
811
- }
812
- }
813
- return [import_globals.describe, void 0];
814
- }
815
- function getTestOrModifier({ data }, tagFilter) {
816
- if (data.gherkin.tags?.has("@skip") || data.gherkin.tags?.has("@skipped")) {
817
- return import_globals.it.skip;
818
- }
819
- if (data.gherkin.tags?.has("@only")) {
820
- return import_globals.it.only;
821
- }
822
- if (tagFilter) {
823
- const parse = require("@cucumber/tag-expressions").default;
824
- const expression = parse(tagFilter).evaluate([...data.gherkin.tags]);
825
- if (!expression) {
826
- return import_globals.it.skip;
827
- }
828
- }
829
- return import_globals.it;
830
- }
831
- function bootstrapBeforeHooks(root, bridge, localApp, events, [config, timeout]) {
832
- const chosenTimeout = chooseTimeout(
833
- timeout,
834
- bridge.data.scope.timeout
835
- ).getTimeout(config);
836
- bridge.data.scope.hooks.before.forEach((hook) => {
837
- const hookTimeout = chooseTimeout(
838
- chosenTimeout,
839
- hook.options.timeout
840
- ).getTimeout(config).milliseconds;
841
- (0, import_globals.beforeEach)(async () => {
842
- const testName = import_globals.expect.getState().currentTestName;
843
- if (!testName)
844
- throw new import_errors.AutomationError("A Scenario must have a title");
845
- const scenarioBridge = (0, import_test_builder.find)(root, testName);
846
- if (!scenarioBridge) {
847
- throw new import_errors.AutomationError(
848
- `No matching scenario was found matching the test name: ${testName}`
849
- );
850
- }
851
- if (!hook.canExecute(...scenarioBridge.data.gherkin.tags)) {
852
- return;
853
- }
854
- const tags = scenarioBridge?.data?.gherkin?.tags ?? [];
855
- events.before.emitStart({
856
- title: `${hook.name}: ${hook.description}`,
857
- tags: [...tags]
858
- });
859
- const report = await hook.execute(localApp()[1], ...tags);
860
- events.before.emitEnd({
861
- title: `${hook.name}: ${hook.description}`,
862
- tags: [...tags],
863
- status: report.status,
864
- error: report.error
865
- });
866
- if (report.error) {
867
- const message = `${hook.name}: ${hook.description} experienced a failure.`;
868
- throw new import_errors.AutomationError(message, { cause: report.error });
869
- }
870
- }, hookTimeout);
871
- });
872
- }
873
- function bootstrapSetupHooks(bridge, staticApp, events, [config, timeout]) {
874
- const { scope, gherkin } = bridge.data;
875
- const chosenTimeout = chooseTimeout(
876
- timeout,
877
- bridge.data.scope.timeout
878
- ).getTimeout(config).milliseconds;
879
- const setups = scope.hooks.setup;
880
- setups.forEach((hook) => {
881
- const hookTimeout = chooseTimeout(
882
- import_scopes2.Timeout.from(chosenTimeout),
883
- hook.options.timeout
884
- ).getTimeout(config).milliseconds;
885
- const tags = gherkin.tags ?? [];
886
- (0, import_globals.beforeAll)(async () => {
887
- if (!hook.canExecute(...tags)) {
888
- return;
889
- }
890
- events.setup.emitStart({
891
- title: `${hook.name}: ${hook.description}`
892
- });
893
- const report = await hook.execute(staticApp, ...tags);
894
- events.setup.emitEnd({
895
- title: `${hook.name}: ${hook.description}`,
896
- status: report.status,
897
- error: report.error
898
- });
899
- if (report.error) {
900
- const message = `${hook.name}: ${hook.description} failed to execute.`;
901
- throw new import_errors.AutomationError(message, { cause: report.error });
902
- }
903
- }, hookTimeout);
904
- });
905
- }
906
- function bootstrapAfterHooks(root, bridge, localApp, events, [config, timeout]) {
907
- const { scope } = bridge.data;
908
- const chosenTimeout = chooseTimeout(timeout, scope.timeout).getTimeout(
909
- config
910
- ).milliseconds;
911
- scope.hooks.after.forEach((hook) => {
912
- const hookTimeout = chooseTimeout(
913
- import_scopes2.Timeout.from(chosenTimeout),
914
- hook.options.timeout
915
- ).getTimeout(config).milliseconds;
916
- (0, import_globals.afterEach)(async () => {
917
- const testName = import_globals.expect.getState().currentTestName;
918
- if (!testName)
919
- throw new import_errors.AutomationError("A Scenario must have a title");
920
- const scenarioBridge = (0, import_test_builder.find)(root, testName);
921
- if (!scenarioBridge) {
922
- throw new import_errors.AutomationError(
923
- `No scenario was found matching the test path: ${testName}`
924
- );
925
- }
926
- if (!hook.canExecute(...scenarioBridge.data.gherkin.tags)) {
927
- return;
928
- }
929
- const tags = scenarioBridge?.data?.gherkin?.tags ?? [];
930
- events.after.emitStart({
931
- title: `${hook.name}: ${hook.description}`,
932
- tags: [...tags]
933
- });
934
- const report = await hook.execute(localApp()[1], ...tags);
935
- events.after.emitEnd({
936
- title: `${hook.name}: ${hook.description}`,
937
- tags: [...tags],
938
- status: report.status,
939
- error: report.error
940
- });
941
- if (report.error) {
942
- const message = `${hook.name}: ${hook.description} failed to execute.`;
943
- throw new import_errors.AutomationError(message, { cause: report.error });
944
- }
945
- }, hookTimeout);
946
- });
947
- }
948
- function bootstrapTeardownHooks(bridge, staticApp, event, [config, timeout]) {
949
- const tags = [...bridge.data.gherkin.tags];
950
- const { scope } = bridge.data;
951
- const chosenTimeout = chooseTimeout(timeout, scope.timeout).getTimeout(
952
- config
953
- );
954
- scope.hooks.teardown.forEach((hook) => {
955
- const hookTimeout = chooseTimeout(
956
- chosenTimeout,
957
- hook.options.timeout
958
- ).getTimeout(config).milliseconds;
959
- (0, import_globals.afterAll)(async () => {
960
- if (!hook.canExecute(...tags)) {
961
- return;
962
- }
963
- event.teardown.emitStart({
964
- title: `${hook.name}: ${hook.description}`,
965
- tags: [...tags]
966
- });
967
- const report = await hook.execute(staticApp, tags);
968
- event.teardown.emitEnd({
969
- title: `${hook.name}: ${hook.description}`,
970
- tags: [...tags],
971
- status: report.status,
972
- error: report.error
973
- });
974
- if (report.error) {
975
- const message = `${hook.name}: ${hook.description} failed to execute.`;
976
- throw new import_errors.AutomationError(message, { cause: report.error });
977
- }
978
- }, hookTimeout);
23
+ };
24
+ function execute(options) {
25
+ registerFeaturePlan({
26
+ plan: options.plan,
27
+ adapter: options.adapter,
28
+ config: options.config,
29
+ runtime
979
30
  });
980
31
  }
32
+ var src_default = { execute };
981
33
 
982
- // src/index.ts
983
- var src_default = execute;
984
- // Annotate the CommonJS export names for ESM import in node:
985
- 0 && (module.exports = {
986
- execute,
987
- getTimeout
988
- });
34
+ export { src_default as default, execute };
35
+ //# sourceMappingURL=out.js.map
989
36
  //# sourceMappingURL=index.js.map