@autometa/test-builder 0.4.2 → 1.0.0-rc.0

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,700 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result)
9
- __defProp(target, key, result);
10
- return result;
11
- };
12
- var __accessCheck = (obj, member, msg) => {
13
- if (!member.has(obj))
14
- throw TypeError("Cannot " + msg);
15
- };
16
- var __privateAdd = (obj, member, value) => {
17
- if (member.has(obj))
18
- throw TypeError("Cannot add the same private member more than once");
19
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
- };
21
- var __privateMethod = (obj, member, method) => {
22
- __accessCheck(obj, member, "access private method");
23
- return method;
24
- };
25
-
26
- // src/bridges/bridge.ts
27
- import {
28
- GherkinNode
29
- } from "@autometa/gherkin";
30
- var GherkinCodeBridge = class {
31
- };
32
- var GlobalBridge = class extends GherkinCodeBridge {
33
- constructor(scope2) {
34
- super();
35
- const nullNode = class extends GherkinNode {
36
- constructor() {
37
- super(...arguments);
38
- this.keyword = "none";
39
- }
40
- };
41
- this.data = {
42
- scope: scope2,
43
- gherkin: new nullNode()
44
- };
45
- }
46
- };
47
- var FeatureBridge = class extends GherkinCodeBridge {
48
- constructor() {
49
- super(...arguments);
50
- this.scenarios = [];
51
- this.rules = [];
52
- this.steps = [];
53
- }
54
- accumulateTags() {
55
- const scenarioTags = this.scenarios.map((scenario) => scenario.accumulateTags()).flat();
56
- const ruleTags = this.rules.map((rule) => rule.accumulateTags()).flat();
57
- const allTags = [...this.data.gherkin.tags, ...scenarioTags, ...ruleTags];
58
- return [...new Set(allTags)];
59
- }
60
- };
61
- var BackgroundBridge = class extends GherkinCodeBridge {
62
- constructor() {
63
- super(...arguments);
64
- this.steps = [];
65
- }
66
- };
67
- var RuleBridge = class extends GherkinCodeBridge {
68
- constructor() {
69
- super(...arguments);
70
- this.scenarios = [];
71
- this.steps = [];
72
- }
73
- accumulateTags() {
74
- const scenarioTags = this.scenarios.map((scenario) => scenario.accumulateTags()).flat();
75
- const allTags = [...this.data.gherkin.tags, ...scenarioTags];
76
- return [...new Set(allTags)];
77
- }
78
- };
79
- var ScenarioBridge = class extends GherkinCodeBridge {
80
- constructor() {
81
- super(...arguments);
82
- this.steps = [];
83
- this.report = {};
84
- }
85
- get title() {
86
- return this.data.scope.title(this.data.gherkin);
87
- }
88
- get tags() {
89
- return [...this.data.gherkin.tags];
90
- }
91
- accumulateTags() {
92
- return this.tags;
93
- }
94
- };
95
- var ExampleBridge = class extends GherkinCodeBridge {
96
- constructor() {
97
- super(...arguments);
98
- this.steps = [];
99
- this.report = {};
100
- }
101
- get title() {
102
- return this.data.scope.title(this.data.gherkin);
103
- }
104
- get tags() {
105
- return [...this.data.gherkin.tags];
106
- }
107
- accumulateTags() {
108
- return this.tags;
109
- }
110
- };
111
- var ScenarioOutlineBridge = class extends GherkinCodeBridge {
112
- constructor() {
113
- super(...arguments);
114
- this.examples = [];
115
- this.steps = [];
116
- }
117
- get title() {
118
- return this.data.scope.title(this.data.gherkin);
119
- }
120
- get tags() {
121
- return [...this.data.gherkin.tags];
122
- }
123
- accumulateTags() {
124
- const exampleTags = this.examples.map((example) => example.tags).flat();
125
- const allTags = [...this.data.gherkin.tags, ...exampleTags];
126
- return [...new Set(allTags)];
127
- }
128
- };
129
- var ExamplesBridge = class extends GherkinCodeBridge {
130
- constructor() {
131
- super(...arguments);
132
- this.scenarios = [];
133
- this.steps = [];
134
- }
135
- get title() {
136
- return this.data.scope.title(this.data.gherkin);
137
- }
138
- get tags() {
139
- return [...this.data.gherkin.tags];
140
- }
141
- accumulateTags() {
142
- const scenarioTags = this.scenarios.map((scenario) => scenario.accumulateTags()).flat();
143
- const allTags = [...this.data.gherkin.tags, ...scenarioTags];
144
- return [...new Set(allTags)];
145
- }
146
- };
147
- var StepBridge = class extends GherkinCodeBridge {
148
- get args() {
149
- return this.data.args;
150
- }
151
- get expressionText() {
152
- return this.data.scope.expression.source;
153
- }
154
- };
155
-
156
- // src/bridges/bridge-search.ts
157
- import { AutomationError } from "@autometa/errors";
158
- function find(bridge, testName) {
159
- if (bridge instanceof FeatureBridge) {
160
- return findByFeature(bridge, testName);
161
- }
162
- if (bridge instanceof RuleBridge) {
163
- return findByRule(bridge, testName);
164
- }
165
- if (bridge instanceof ScenarioOutlineBridge) {
166
- return findScenarioOutlineOrChild(bridge, testName);
167
- }
168
- throw new AutomationError(`Could not find test matching ${testName}`);
169
- }
170
- function findByFeature(feature, testName) {
171
- const title = feature.data.scope.title(feature.data.gherkin);
172
- const byScenario = findTestTypes(feature.scenarios, testName, title);
173
- if (byScenario) {
174
- return byScenario;
175
- }
176
- const byRule = findRuleTypes(feature.rules, testName, title);
177
- if (byRule) {
178
- return byRule;
179
- }
180
- }
181
- function findByRule(rule, testName) {
182
- const title = rule.data.scope.title(rule.data.gherkin);
183
- const byScenario = findTestTypes(rule.scenarios, testName, title);
184
- if (byScenario) {
185
- return byScenario;
186
- }
187
- const byRule = findRuleOrChild(rule, testName, title);
188
- if (byRule) {
189
- return byRule;
190
- }
191
- }
192
- function findTestTypes(scenarios, testName, from) {
193
- for (const scenario of scenarios) {
194
- if (scenario instanceof ScenarioOutlineBridge) {
195
- const found = findScenarioOutlineOrChild(scenario, testName, from);
196
- if (found) {
197
- return found;
198
- }
199
- }
200
- if (scenario instanceof ExamplesBridge) {
201
- const found = findExamplesOrChild(scenario, testName, from);
202
- if (found) {
203
- return found;
204
- }
205
- }
206
- if (scenario instanceof ScenarioBridge) {
207
- const found = findScenario(scenario, testName, from);
208
- if (found) {
209
- return found;
210
- }
211
- }
212
- }
213
- }
214
- function findRuleTypes(rules, testName, from) {
215
- for (const rule of rules) {
216
- const found = findRuleOrChild(rule, testName, from);
217
- if (found) {
218
- return found;
219
- }
220
- }
221
- }
222
- function findRuleOrChild(rule, testName, from) {
223
- const {
224
- data: { scope: scope2, gherkin }
225
- } = rule;
226
- const title = scope2.title(gherkin);
227
- if (testName === title) {
228
- return rule;
229
- }
230
- if (from) {
231
- const fullTitle = `${from} ${title}`;
232
- if (fullTitle === testName) {
233
- return rule;
234
- }
235
- }
236
- const newFrom = appendPath(from, title);
237
- return findTestTypes(rule.scenarios, testName, newFrom);
238
- }
239
- function findScenarioOutlineOrChild(outline, testName, from) {
240
- const {
241
- data: { scope: scope2, gherkin }
242
- } = outline;
243
- const title = scope2.title(gherkin);
244
- if (testName === title) {
245
- return outline;
246
- }
247
- if (from) {
248
- const fullTitle = `${from} ${title}`;
249
- if (fullTitle === testName) {
250
- return outline;
251
- }
252
- }
253
- for (const example of outline.examples) {
254
- const newFrom = appendPath(from, title);
255
- const found = findExamplesOrChild(example, testName, newFrom);
256
- if (found) {
257
- return found;
258
- }
259
- }
260
- }
261
- function appendPath(from, title) {
262
- return from ? `${from} ${title}` : title;
263
- }
264
- function findExamplesOrChild(example, testName, from) {
265
- const {
266
- data: { gherkin }
267
- } = example;
268
- const title = `${gherkin.keyword}: ${gherkin.name}`;
269
- if (testName === title) {
270
- return example;
271
- }
272
- if (from) {
273
- const fullTitle = `${from} ${title}`;
274
- if (fullTitle === testName) {
275
- return example;
276
- }
277
- }
278
- for (const scenario of example.scenarios) {
279
- const newFrom = appendPath(from, title);
280
- const found = findScenario(scenario, testName, newFrom);
281
- if (found) {
282
- return found;
283
- }
284
- }
285
- }
286
- function findScenario(scenario, testName, from) {
287
- const {
288
- data: { scope: scope2, gherkin }
289
- } = scenario;
290
- const title = scope2.title(gherkin);
291
- if (testName === title) {
292
- return scenario;
293
- }
294
- if (from) {
295
- const fullTitle = `${from} ${title}`;
296
- if (fullTitle === testName) {
297
- return scenario;
298
- }
299
- }
300
- }
301
-
302
- // src/bridges/bridge-query.ts
303
- import { Background as Background2 } from "@autometa/gherkin";
304
- function failed(bridge) {
305
- const accumulator = [];
306
- if (bridge instanceof ScenarioOutlineBridge) {
307
- return failedOutline(bridge);
308
- }
309
- for (const scenario of bridge.scenarios) {
310
- if (scenario instanceof ScenarioOutlineBridge) {
311
- accumulator.push(...failedOutline(scenario));
312
- } else if (scenario.report.error !== void 0) {
313
- accumulator.push(scenario);
314
- }
315
- }
316
- if (bridge instanceof FeatureBridge) {
317
- accumulator.push(...failedRule(bridge));
318
- }
319
- return accumulator;
320
- }
321
- function failedOutline(bridge) {
322
- const accumulator = [];
323
- for (const example of bridge.examples) {
324
- for (const scenario of example.scenarios) {
325
- if (scenario.report.error) {
326
- accumulator.push(scenario);
327
- }
328
- }
329
- }
330
- return accumulator;
331
- }
332
- function failedRule(bridge) {
333
- const accumulator = [];
334
- for (const rule of bridge.rules) {
335
- for (const scenario of rule.scenarios) {
336
- if (scenario instanceof ScenarioOutlineBridge) {
337
- accumulator.push(...failedOutline(scenario));
338
- } else if (scenario.report.error) {
339
- accumulator.push(scenario);
340
- }
341
- }
342
- }
343
- return accumulator;
344
- }
345
- function gherkinToTestNames(node, path = "", accumulator = []) {
346
- if (!("name" in node) || node instanceof Background2) {
347
- return;
348
- }
349
- const title = `${node.keyword}: ${node.name}`;
350
- const fullPath = path ? `${path} ${title}` : title;
351
- accumulator.push(fullPath);
352
- if (!node.children) {
353
- return;
354
- }
355
- for (const child of node.children) {
356
- if (!("name" in child) || child instanceof Background2) {
357
- continue;
358
- }
359
- gherkinToTestNames(child, fullPath, accumulator);
360
- }
361
- return accumulator;
362
- }
363
- var Query = {
364
- find: {
365
- failed
366
- },
367
- testNames: gherkinToTestNames
368
- };
369
-
370
- // src/gherkin-walker.ts
371
- import {
372
- Background as Background3,
373
- Examples as Examples2,
374
- Feature as Feature2,
375
- Rule as Rule2,
376
- Scenario as Scenario2,
377
- ScenarioOutline as ScenarioOutline2,
378
- Step as Step2
379
- } from "@autometa/gherkin";
380
- import { AutomationError as AutomationError2 } from "@autometa/errors";
381
- import { Example as Example2 } from "@autometa/gherkin";
382
- var _walkNode, walkNode_fn, _walkChildren, walkChildren_fn;
383
- var GherkinWalker = class {
384
- static walk(walkFunction, childNode, accumulator, parentNode) {
385
- if (accumulator === void 0) {
386
- throw new AutomationError2(
387
- `An accumulator must be defined to continue the walker from ${childNode.constructor.name}${JSON.stringify(childNode)}`
388
- );
389
- }
390
- __privateMethod(this, _walkNode, walkNode_fn).call(this, childNode, accumulator, walkFunction, parentNode);
391
- return accumulator;
392
- }
393
- };
394
- _walkNode = new WeakSet();
395
- walkNode_fn = function(child, accumulator, walkFunction, lastNode) {
396
- if (child instanceof Feature2 && walkFunction.onFeature) {
397
- const acc = walkFunction.onFeature(child, accumulator, lastNode);
398
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
399
- }
400
- if (child instanceof Rule2 && walkFunction.onRule) {
401
- const acc = walkFunction.onRule(child, accumulator, lastNode);
402
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
403
- }
404
- if (child instanceof Examples2) {
405
- const acc = walkFunction.onExamples?.(child, accumulator, lastNode);
406
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
407
- }
408
- if (child instanceof Example2) {
409
- const acc = walkFunction.onExample?.(child, accumulator, lastNode);
410
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
411
- }
412
- if (child instanceof Scenario2) {
413
- const acc = walkFunction.onScenario?.(child, accumulator, lastNode);
414
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
415
- }
416
- if (child instanceof ScenarioOutline2) {
417
- const acc = walkFunction.onScenarioOutline?.(
418
- child,
419
- accumulator,
420
- lastNode
421
- );
422
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
423
- }
424
- if (child instanceof Background3) {
425
- const acc = walkFunction?.onBackground?.(child, accumulator, lastNode);
426
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
427
- }
428
- if (child instanceof Step2) {
429
- const acc = walkFunction.onStep?.(child, accumulator, lastNode);
430
- return __privateMethod(this, _walkChildren, walkChildren_fn).call(this, child, acc, walkFunction);
431
- }
432
- };
433
- _walkChildren = new WeakSet();
434
- walkChildren_fn = function(child, accumulator, walkFunction) {
435
- for (const node of child.children) {
436
- this.walk(walkFunction, node, accumulator, child);
437
- }
438
- };
439
- __privateAdd(GherkinWalker, _walkNode);
440
- __privateAdd(GherkinWalker, _walkChildren);
441
-
442
- // src/scope-search.ts
443
- import { AutomationError as AutomationError3 } from "@autometa/errors";
444
- import {
445
- RuleScope,
446
- ScenarioScope,
447
- ScenarioOutlineScope,
448
- BackgroundScope
449
- } from "@autometa/scopes";
450
- import { Empty_Function } from "@autometa/scopes";
451
- function scope(value) {
452
- return {
453
- findRule: (name) => {
454
- const found = value.closedScopes.find((child) => {
455
- return child instanceof RuleScope && child.name === name;
456
- });
457
- if (!found) {
458
- const rule = new RuleScope(
459
- name,
460
- Empty_Function,
461
- void 0,
462
- value.hooks,
463
- value.steps
464
- );
465
- value.attach(rule);
466
- return rule;
467
- }
468
- return found;
469
- },
470
- findScenario: (name) => {
471
- const found = value.closedScopes.find((child) => {
472
- return child instanceof ScenarioScope && child.name === name && !(child instanceof ScenarioOutlineScope);
473
- });
474
- if (!found) {
475
- const scenario = new ScenarioScope(
476
- name,
477
- Empty_Function,
478
- void 0,
479
- value.hooks,
480
- value.steps
481
- );
482
- value.attach(scenario);
483
- return scenario;
484
- }
485
- return found;
486
- },
487
- findBackground: ({ name }) => {
488
- const found = value.closedScopes.find((child) => {
489
- return child instanceof BackgroundScope;
490
- });
491
- if (found && found.name !== name) {
492
- throw new AutomationError3(
493
- `Could not find background matching ${name} but found ${found?.name}`
494
- );
495
- }
496
- if (found) {
497
- return found;
498
- }
499
- const bgScope = new BackgroundScope(
500
- name,
501
- Empty_Function,
502
- value.hooks,
503
- value.steps
504
- );
505
- value.attach(bgScope);
506
- return bgScope;
507
- },
508
- findScenarioOutline: (name) => {
509
- const found = value.closedScopes.find((child) => {
510
- return child instanceof ScenarioOutlineScope && child.name === name;
511
- });
512
- if (!found) {
513
- const scenarioOutline = new ScenarioOutlineScope(
514
- name,
515
- Empty_Function,
516
- void 0,
517
- value.hooks,
518
- value.steps
519
- );
520
- value.attach(scenarioOutline);
521
- return scenarioOutline;
522
- }
523
- return found;
524
- },
525
- findExample(name) {
526
- const found = value.closedScopes.find((child) => {
527
- if (!(child instanceof ScenarioScope)) {
528
- return false;
529
- }
530
- return child.name === name;
531
- });
532
- if (!found) {
533
- const scenario = new ScenarioScope(
534
- name,
535
- Empty_Function,
536
- void 0,
537
- value.hooks,
538
- value.steps
539
- );
540
- value.attach(scenario);
541
- return scenario;
542
- }
543
- return found;
544
- },
545
- findStep: (keywordType, keyword, name) => {
546
- return value.steps.find(keywordType, keyword, name);
547
- }
548
- };
549
- }
550
-
551
- // src/test-builder.ts
552
- import { Bind } from "@autometa/bind-decorator";
553
- import { raise } from "@autometa/errors";
554
- var TestBuilder = class {
555
- constructor(feature) {
556
- this.feature = feature;
557
- }
558
- onFeatureExecuted(featureScope) {
559
- const bridge = new FeatureBridge();
560
- GherkinWalker.walk(
561
- {
562
- onFeature: (feature, accumulator) => {
563
- accumulator.data = { gherkin: feature, scope: featureScope };
564
- return accumulator;
565
- },
566
- onRule: (rule, accumulator) => {
567
- const ruleScope = scope(featureScope).findRule(
568
- rule.name
569
- );
570
- const bridge2 = new RuleBridge();
571
- bridge2.data = { gherkin: rule, scope: ruleScope };
572
- accumulator.rules.push(bridge2);
573
- return bridge2;
574
- },
575
- onScenario: (gherkin, accumulator) => {
576
- const scenarioScope = scope(accumulator.data.scope).findScenario(
577
- gherkin.name
578
- );
579
- const bridge2 = new ScenarioBridge();
580
- bridge2.data = { gherkin, scope: scenarioScope };
581
- accumulator.scenarios.push(bridge2);
582
- return bridge2;
583
- },
584
- onScenarioOutline: (gherkin, accumulator) => {
585
- const outlineScope = scope(
586
- accumulator.data.scope
587
- ).findScenarioOutline(gherkin.name);
588
- const bridge2 = new ScenarioOutlineBridge();
589
- bridge2.data = { gherkin, scope: outlineScope };
590
- accumulator.scenarios.push(bridge2);
591
- return bridge2;
592
- },
593
- onExamples: (gherkin, accumulator) => {
594
- const outlineScope = accumulator.data.scope;
595
- const bridge2 = new ExamplesBridge();
596
- bridge2.data = { gherkin, scope: outlineScope };
597
- accumulator.examples.push(bridge2);
598
- return bridge2;
599
- },
600
- onExample(gherkin, accumulator) {
601
- if (gherkin.table === void 0) {
602
- raise(
603
- `Example ${gherkin.name} has no Example Table data. A Row of data is required.`
604
- );
605
- }
606
- const title = gherkin.name;
607
- const exampleScope = scope(accumulator.data.scope).findExample(title);
608
- const bridge2 = new ExampleBridge();
609
- bridge2.data = { gherkin, scope: exampleScope };
610
- const acc = accumulator;
611
- acc.scenarios.push(bridge2);
612
- return bridge2;
613
- },
614
- onBackground(gherkin, accumulator) {
615
- const backgroundScope = scope(accumulator.data.scope).findBackground({
616
- name: gherkin.name
617
- });
618
- const bridge2 = new BackgroundBridge();
619
- bridge2.data = { gherkin, scope: backgroundScope };
620
- const acc = accumulator;
621
- acc.background = bridge2;
622
- return bridge2;
623
- },
624
- onStep: (step, accumulator) => {
625
- const {
626
- data: { scope: parentScope, gherkin }
627
- } = accumulator;
628
- const { keyword, keywordType, text } = step;
629
- const cache = parentScope.steps;
630
- const existing = getStep(
631
- accumulator,
632
- gherkin,
633
- cache,
634
- keywordType,
635
- keyword,
636
- text
637
- );
638
- const bridge2 = new StepBridge();
639
- const acc = accumulator;
640
- if (existing) {
641
- bridge2.data = {
642
- gherkin: step,
643
- scope: existing.step,
644
- args: existing.args
645
- };
646
- } else {
647
- raise(`No step definition matching ${step.keyword} ${step.text}`);
648
- }
649
- acc.steps.push(bridge2);
650
- return accumulator;
651
- }
652
- },
653
- this.feature,
654
- bridge
655
- );
656
- return bridge;
657
- }
658
- };
659
- __decorateClass([
660
- Bind
661
- ], TestBuilder.prototype, "onFeatureExecuted", 1);
662
- function getStep(accumulator, gherkin, cache, keywordType, keyword, text) {
663
- try {
664
- if (accumulator instanceof ExampleBridge) {
665
- const scenario = gherkin;
666
- if (scenario.table) {
667
- return cache.findByExample(keywordType, keyword, text, scenario.table);
668
- }
669
- }
670
- return cache.find(keywordType, keyword, text);
671
- } catch (e) {
672
- const cause = e;
673
- const { title } = gherkin;
674
- raise(`'${title}' could not find a step definition`, { cause });
675
- }
676
- }
677
- export {
678
- BackgroundBridge,
679
- ExampleBridge,
680
- ExamplesBridge,
681
- FeatureBridge,
682
- GherkinCodeBridge,
683
- GherkinWalker,
684
- GlobalBridge,
685
- Query,
686
- RuleBridge,
687
- ScenarioBridge,
688
- ScenarioOutlineBridge,
689
- StepBridge,
690
- TestBuilder,
691
- find,
692
- findExamplesOrChild,
693
- findRuleOrChild,
694
- findRuleTypes,
695
- findScenario,
696
- findScenarioOutlineOrChild,
697
- findTestTypes,
698
- scope
699
- };
700
- //# sourceMappingURL=index.js.map