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