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