@autometa/jest-executor 0.0.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/.eslintignore +3 -0
- package/.eslintrc.cjs +4 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/esm/index.js +333 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +345 -0
- package/package.json +60 -0
- package/tsup.config.ts +14 -0
package/.eslintignore
ADDED
package/.eslintrc.cjs
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) undefined Ben Aherne
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// src/executor.ts
|
|
2
|
+
import {
|
|
3
|
+
ScenarioOutlineBridge,
|
|
4
|
+
find
|
|
5
|
+
} from "@autometa/test-builder";
|
|
6
|
+
import {
|
|
7
|
+
describe,
|
|
8
|
+
it,
|
|
9
|
+
expect,
|
|
10
|
+
beforeEach,
|
|
11
|
+
afterEach,
|
|
12
|
+
afterAll,
|
|
13
|
+
beforeAll
|
|
14
|
+
} from "@jest/globals";
|
|
15
|
+
import { getApp } from "@autometa/app";
|
|
16
|
+
import { AutomationError } from "@autometa/errors";
|
|
17
|
+
import { Query } from "@autometa/test-builder";
|
|
18
|
+
function execute({ app, world }, bridge, events) {
|
|
19
|
+
const featureTitle = bridge.data.scope.title(bridge.data.gherkin);
|
|
20
|
+
const [group, modifier] = getGroupOrModifier(bridge);
|
|
21
|
+
beforeAll(() => {
|
|
22
|
+
events.feature.emitStart({
|
|
23
|
+
title: featureTitle,
|
|
24
|
+
path: bridge.data.scope.path,
|
|
25
|
+
modifier,
|
|
26
|
+
tags: [...bridge.data.gherkin.tags]
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
group(featureTitle, () => {
|
|
30
|
+
let localApp;
|
|
31
|
+
const staticApp = getApp(app, world);
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
localApp = getApp(app, world);
|
|
34
|
+
});
|
|
35
|
+
bootstrapSetupHooks(bridge, staticApp, events);
|
|
36
|
+
bootstrapBeforeHooks(bridge, () => localApp, events);
|
|
37
|
+
bootstrapBackground(bridge, () => localApp, events);
|
|
38
|
+
bootstrapScenarios(bridge, () => localApp, staticApp, events);
|
|
39
|
+
bootstrapRules(bridge, () => localApp, staticApp, events);
|
|
40
|
+
bootstrapAfterHooks(bridge, () => localApp, events);
|
|
41
|
+
bootstrapTeardownHooks(bridge, staticApp, events);
|
|
42
|
+
});
|
|
43
|
+
afterAll(() => {
|
|
44
|
+
const failures = Query.find.failed(bridge);
|
|
45
|
+
const status = modifier === "skip" ? "SKIPPED" : failures.length === 0 ? "PASSED" : "FAILED";
|
|
46
|
+
events.feature.emitEnd({
|
|
47
|
+
title: featureTitle,
|
|
48
|
+
modifier,
|
|
49
|
+
tags: [...bridge.data.gherkin.tags],
|
|
50
|
+
status
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function bootstrapBackground(bridge, localApp, events) {
|
|
55
|
+
const background = bridge.background;
|
|
56
|
+
if (!background)
|
|
57
|
+
return;
|
|
58
|
+
const testName = expect.getState().currentTestName;
|
|
59
|
+
if (!testName)
|
|
60
|
+
throw new AutomationError("A Scenario must have a title");
|
|
61
|
+
const scenarioBridge = find(bridge, testName);
|
|
62
|
+
if (!scenarioBridge) {
|
|
63
|
+
throw new AutomationError(
|
|
64
|
+
`No matching scenario bridge was found matching the test name: ${testName}`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const tags = bridge?.data?.gherkin?.tags ?? [];
|
|
68
|
+
if (tags.has("@skip") || tags.has("@skipped"))
|
|
69
|
+
return;
|
|
70
|
+
beforeEach(async () => {
|
|
71
|
+
const title = background.data.scope.title(background.data.gherkin);
|
|
72
|
+
events.before.emitStart({
|
|
73
|
+
title,
|
|
74
|
+
tags: [...tags]
|
|
75
|
+
});
|
|
76
|
+
const steps = background.steps;
|
|
77
|
+
try {
|
|
78
|
+
for (const step of steps) {
|
|
79
|
+
await step.data.scope.execute(step.data.gherkin, localApp());
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {
|
|
82
|
+
events.before.emitEnd({
|
|
83
|
+
title: background.data.scope.title(background.data.gherkin),
|
|
84
|
+
tags: [...tags],
|
|
85
|
+
status: "FAILED",
|
|
86
|
+
error: e
|
|
87
|
+
});
|
|
88
|
+
const message = `${title} failed to execute.
|
|
89
|
+
Test: ${testName}`;
|
|
90
|
+
throw new AutomationError(message, { cause: e });
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function bootstrapScenarios(bridge, localApp, staticApp, events) {
|
|
95
|
+
const { scenarios } = bridge;
|
|
96
|
+
scenarios.forEach((scenario) => {
|
|
97
|
+
if (isOutline(scenario)) {
|
|
98
|
+
bootstrapScenarioOutline(scenario, localApp, staticApp, events);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
bootstrapScenario(scenario, localApp, events);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function bootstrapScenario(bridge, localApp, events) {
|
|
105
|
+
const { data } = bridge;
|
|
106
|
+
const scenarioName = data.scope.title(data.gherkin);
|
|
107
|
+
const test = getTestOrModifier(bridge);
|
|
108
|
+
test(scenarioName, async () => {
|
|
109
|
+
events.scenario.emitStart({
|
|
110
|
+
title: scenarioName,
|
|
111
|
+
tags: [...data.gherkin.tags]
|
|
112
|
+
});
|
|
113
|
+
try {
|
|
114
|
+
for (const step of bridge.steps) {
|
|
115
|
+
await step.data.scope.execute(step.data.gherkin, localApp());
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
events.scenario.emitEnd({
|
|
119
|
+
title: scenarioName,
|
|
120
|
+
tags: [...data.gherkin.tags],
|
|
121
|
+
status: "FAILED",
|
|
122
|
+
error: e
|
|
123
|
+
});
|
|
124
|
+
const message = `${scenarioName} failed to execute.`;
|
|
125
|
+
throw new AutomationError(message, { cause: e });
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function isOutline(data) {
|
|
130
|
+
return data instanceof ScenarioOutlineBridge;
|
|
131
|
+
}
|
|
132
|
+
function bootstrapScenarioOutline(bridge, localApp, staticApp, events) {
|
|
133
|
+
const {
|
|
134
|
+
data: { scope, gherkin },
|
|
135
|
+
examples
|
|
136
|
+
} = bridge;
|
|
137
|
+
const title = scope.title(gherkin);
|
|
138
|
+
const [group, modifier] = getGroupOrModifier(bridge);
|
|
139
|
+
group(title, () => {
|
|
140
|
+
beforeAll(() => {
|
|
141
|
+
events.scenarioOutline.emitStart({
|
|
142
|
+
title,
|
|
143
|
+
modifier,
|
|
144
|
+
tags: [...gherkin.tags]
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
bootstrapSetupHooks(bridge, staticApp, events);
|
|
148
|
+
bootstrapBeforeHooks(bridge, localApp, events);
|
|
149
|
+
examples.forEach((example) => {
|
|
150
|
+
bootstrapExamples(example, localApp, staticApp, events);
|
|
151
|
+
});
|
|
152
|
+
bootstrapAfterHooks(bridge, localApp, events);
|
|
153
|
+
bootstrapTeardownHooks(bridge, staticApp, events);
|
|
154
|
+
afterAll(() => {
|
|
155
|
+
const failures = Query.find.failed(bridge);
|
|
156
|
+
const status = modifier === "skip" ? "SKIPPED" : failures.length === 0 ? "PASSED" : "FAILED";
|
|
157
|
+
events.scenarioOutline.emitEnd({
|
|
158
|
+
title,
|
|
159
|
+
modifier,
|
|
160
|
+
tags: [...gherkin.tags],
|
|
161
|
+
status
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function bootstrapExamples(example, localApp, staticApp, events) {
|
|
167
|
+
const title = example.data.scope.title(example.data.gherkin);
|
|
168
|
+
const [group] = getGroupOrModifier(example);
|
|
169
|
+
group(title, () => {
|
|
170
|
+
bootstrapScenarios(example, localApp, staticApp, events);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function bootstrapRules(bridge, localApp, staticApp, events) {
|
|
174
|
+
bridge.rules.forEach(({ data }) => {
|
|
175
|
+
const ruleName = data.scope.title(data.gherkin);
|
|
176
|
+
const [group, modifier] = getGroupOrModifier(bridge);
|
|
177
|
+
group(ruleName, () => {
|
|
178
|
+
beforeAll(() => {
|
|
179
|
+
events.rule.emitStart({
|
|
180
|
+
title: ruleName,
|
|
181
|
+
modifier,
|
|
182
|
+
tags: [...data.gherkin.tags]
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
bootstrapSetupHooks(bridge, staticApp, events);
|
|
186
|
+
bootstrapBeforeHooks(bridge, localApp, events);
|
|
187
|
+
bootstrapBackground(bridge, localApp, events);
|
|
188
|
+
bootstrapScenarios(bridge, localApp, staticApp, events);
|
|
189
|
+
bootstrapAfterHooks(bridge, localApp, events);
|
|
190
|
+
bootstrapTeardownHooks(bridge, staticApp, events);
|
|
191
|
+
afterAll(() => {
|
|
192
|
+
const failures = Query.find.failed(bridge);
|
|
193
|
+
const status = modifier === "skip" ? "SKIPPED" : failures.length === 0 ? "PASSED" : "FAILED";
|
|
194
|
+
events.rule.emitEnd({
|
|
195
|
+
title: ruleName,
|
|
196
|
+
modifier,
|
|
197
|
+
tags: [...data.gherkin.tags],
|
|
198
|
+
status
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function getGroupOrModifier({
|
|
205
|
+
data
|
|
206
|
+
}) {
|
|
207
|
+
if (data.gherkin.tags?.has("@skip") || data.gherkin.tags?.has("@skipped")) {
|
|
208
|
+
return [describe.skip, "skip"];
|
|
209
|
+
}
|
|
210
|
+
if (data.gherkin.tags?.has("@only")) {
|
|
211
|
+
return [describe.only, "only"];
|
|
212
|
+
}
|
|
213
|
+
return [describe, void 0];
|
|
214
|
+
}
|
|
215
|
+
function getTestOrModifier({ data }) {
|
|
216
|
+
if (data.gherkin.tags?.has("@skip") || data.gherkin.tags?.has("@skipped")) {
|
|
217
|
+
return it.skip;
|
|
218
|
+
}
|
|
219
|
+
if (data.gherkin.tags?.has("@only")) {
|
|
220
|
+
return it.only;
|
|
221
|
+
}
|
|
222
|
+
return it;
|
|
223
|
+
}
|
|
224
|
+
function bootstrapBeforeHooks(bridge, localApp, events) {
|
|
225
|
+
bridge.data.scope.hooks.before.forEach((hook) => {
|
|
226
|
+
const testName = expect.getState().currentTestName;
|
|
227
|
+
if (!testName)
|
|
228
|
+
throw new AutomationError("A Scenario must have a title");
|
|
229
|
+
const scenarioBridge = find(bridge, testName);
|
|
230
|
+
if (!scenarioBridge) {
|
|
231
|
+
throw new AutomationError(
|
|
232
|
+
`No matching scenario was found matching the test name: ${testName}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const tags = scenarioBridge?.data?.gherkin?.tags ?? [];
|
|
236
|
+
beforeEach(async () => {
|
|
237
|
+
events.before.emitStart({
|
|
238
|
+
title: hook.name,
|
|
239
|
+
tags: [...tags]
|
|
240
|
+
});
|
|
241
|
+
const report = await hook.execute(localApp(), ...tags);
|
|
242
|
+
events.before.emitEnd({
|
|
243
|
+
title: hook.name,
|
|
244
|
+
tags: [...tags],
|
|
245
|
+
status: report.status,
|
|
246
|
+
error: report.error
|
|
247
|
+
});
|
|
248
|
+
if (report.error) {
|
|
249
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
250
|
+
throw new AutomationError(message, { cause: report.error });
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function bootstrapSetupHooks(bridge, staticApp, events) {
|
|
256
|
+
bridge.data.scope.hooks.setup.forEach((hook) => {
|
|
257
|
+
const tags = bridge.data.gherkin.tags ?? [];
|
|
258
|
+
beforeAll(async () => {
|
|
259
|
+
events.setup.emitStart({
|
|
260
|
+
title: hook.name
|
|
261
|
+
});
|
|
262
|
+
const report = await hook.execute(staticApp, ...tags);
|
|
263
|
+
events.setup.emitEnd({
|
|
264
|
+
title: hook.name,
|
|
265
|
+
status: report.status,
|
|
266
|
+
error: report.error
|
|
267
|
+
});
|
|
268
|
+
if (report.error) {
|
|
269
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
270
|
+
throw new AutomationError(message, { cause: report.error });
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function bootstrapAfterHooks(bridge, localApp, events) {
|
|
276
|
+
bridge.data.scope.hooks.after.forEach((hook) => {
|
|
277
|
+
const testName = expect.getState().currentTestName;
|
|
278
|
+
if (!testName)
|
|
279
|
+
throw new AutomationError("A Scenario must have a title");
|
|
280
|
+
const scenarioBridge = find(bridge, testName);
|
|
281
|
+
if (!scenarioBridge) {
|
|
282
|
+
throw new AutomationError(
|
|
283
|
+
`No matching scenario bridge was found matching the test name: ${testName}`
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const tags = scenarioBridge?.data?.gherkin?.tags ?? [];
|
|
287
|
+
afterEach(async () => {
|
|
288
|
+
events.after.emitStart({
|
|
289
|
+
title: hook.name,
|
|
290
|
+
tags: [...tags]
|
|
291
|
+
});
|
|
292
|
+
const report = await hook.execute(localApp(), ...tags);
|
|
293
|
+
events.after.emitEnd({
|
|
294
|
+
title: hook.name,
|
|
295
|
+
tags: [...tags],
|
|
296
|
+
status: report.status,
|
|
297
|
+
error: report.error
|
|
298
|
+
});
|
|
299
|
+
if (report.error) {
|
|
300
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
301
|
+
throw new AutomationError(message, { cause: report.error });
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
function bootstrapTeardownHooks(bridge, staticApp, event) {
|
|
307
|
+
const tags = bridge.data.gherkin.tags ?? [];
|
|
308
|
+
bridge.data.scope.hooks.teardown.forEach((hook) => {
|
|
309
|
+
afterAll(async () => {
|
|
310
|
+
event.teardown.emitStart({
|
|
311
|
+
title: hook.name,
|
|
312
|
+
tags: [...tags]
|
|
313
|
+
});
|
|
314
|
+
const report = await hook.execute(staticApp, ...tags);
|
|
315
|
+
event.teardown.emitEnd({
|
|
316
|
+
title: hook.name,
|
|
317
|
+
tags: [...tags],
|
|
318
|
+
status: report.status,
|
|
319
|
+
error: report.error
|
|
320
|
+
});
|
|
321
|
+
if (report.error) {
|
|
322
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
323
|
+
throw new AutomationError(message, { cause: report.error });
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/index.ts
|
|
330
|
+
var src_default = execute;
|
|
331
|
+
export {
|
|
332
|
+
src_default as default
|
|
333
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FeatureBridge } from '@autometa/test-builder';
|
|
2
|
+
import { AutometaApp, AutometaWorld } from '@autometa/app';
|
|
3
|
+
import { Class } from '@autometa/types';
|
|
4
|
+
import { TestEventEmitter } from '@autometa/events';
|
|
5
|
+
|
|
6
|
+
declare function execute({ app, world }: {
|
|
7
|
+
app: Class<AutometaApp>;
|
|
8
|
+
world: Class<AutometaWorld>;
|
|
9
|
+
}, bridge: FeatureBridge, events: TestEventEmitter): void;
|
|
10
|
+
|
|
11
|
+
export { execute as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
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);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
default: () => src_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/executor.ts
|
|
28
|
+
var import_test_builder = require("@autometa/test-builder");
|
|
29
|
+
var import_globals = require("@jest/globals");
|
|
30
|
+
var import_app = require("@autometa/app");
|
|
31
|
+
var import_errors = require("@autometa/errors");
|
|
32
|
+
var import_test_builder2 = require("@autometa/test-builder");
|
|
33
|
+
function execute({ app, world }, bridge, events) {
|
|
34
|
+
const featureTitle = bridge.data.scope.title(bridge.data.gherkin);
|
|
35
|
+
const [group, modifier] = getGroupOrModifier(bridge);
|
|
36
|
+
(0, import_globals.beforeAll)(() => {
|
|
37
|
+
events.feature.emitStart({
|
|
38
|
+
title: featureTitle,
|
|
39
|
+
path: bridge.data.scope.path,
|
|
40
|
+
modifier,
|
|
41
|
+
tags: [...bridge.data.gherkin.tags]
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
group(featureTitle, () => {
|
|
45
|
+
let localApp;
|
|
46
|
+
const staticApp = (0, import_app.getApp)(app, world);
|
|
47
|
+
(0, import_globals.beforeEach)(() => {
|
|
48
|
+
localApp = (0, import_app.getApp)(app, world);
|
|
49
|
+
});
|
|
50
|
+
bootstrapSetupHooks(bridge, staticApp, events);
|
|
51
|
+
bootstrapBeforeHooks(bridge, () => localApp, events);
|
|
52
|
+
bootstrapBackground(bridge, () => localApp, events);
|
|
53
|
+
bootstrapScenarios(bridge, () => localApp, staticApp, events);
|
|
54
|
+
bootstrapRules(bridge, () => localApp, staticApp, events);
|
|
55
|
+
bootstrapAfterHooks(bridge, () => localApp, events);
|
|
56
|
+
bootstrapTeardownHooks(bridge, staticApp, events);
|
|
57
|
+
});
|
|
58
|
+
(0, import_globals.afterAll)(() => {
|
|
59
|
+
const failures = import_test_builder2.Query.find.failed(bridge);
|
|
60
|
+
const status = modifier === "skip" ? "SKIPPED" : failures.length === 0 ? "PASSED" : "FAILED";
|
|
61
|
+
events.feature.emitEnd({
|
|
62
|
+
title: featureTitle,
|
|
63
|
+
modifier,
|
|
64
|
+
tags: [...bridge.data.gherkin.tags],
|
|
65
|
+
status
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function bootstrapBackground(bridge, localApp, events) {
|
|
70
|
+
const background = bridge.background;
|
|
71
|
+
if (!background)
|
|
72
|
+
return;
|
|
73
|
+
const testName = import_globals.expect.getState().currentTestName;
|
|
74
|
+
if (!testName)
|
|
75
|
+
throw new import_errors.AutomationError("A Scenario must have a title");
|
|
76
|
+
const scenarioBridge = (0, import_test_builder.find)(bridge, testName);
|
|
77
|
+
if (!scenarioBridge) {
|
|
78
|
+
throw new import_errors.AutomationError(
|
|
79
|
+
`No matching scenario bridge was found matching the test name: ${testName}`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
const tags = bridge?.data?.gherkin?.tags ?? [];
|
|
83
|
+
if (tags.has("@skip") || tags.has("@skipped"))
|
|
84
|
+
return;
|
|
85
|
+
(0, import_globals.beforeEach)(async () => {
|
|
86
|
+
const title = background.data.scope.title(background.data.gherkin);
|
|
87
|
+
events.before.emitStart({
|
|
88
|
+
title,
|
|
89
|
+
tags: [...tags]
|
|
90
|
+
});
|
|
91
|
+
const steps = background.steps;
|
|
92
|
+
try {
|
|
93
|
+
for (const step of steps) {
|
|
94
|
+
await step.data.scope.execute(step.data.gherkin, localApp());
|
|
95
|
+
}
|
|
96
|
+
} catch (e) {
|
|
97
|
+
events.before.emitEnd({
|
|
98
|
+
title: background.data.scope.title(background.data.gherkin),
|
|
99
|
+
tags: [...tags],
|
|
100
|
+
status: "FAILED",
|
|
101
|
+
error: e
|
|
102
|
+
});
|
|
103
|
+
const message = `${title} failed to execute.
|
|
104
|
+
Test: ${testName}`;
|
|
105
|
+
throw new import_errors.AutomationError(message, { cause: e });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function bootstrapScenarios(bridge, localApp, staticApp, events) {
|
|
110
|
+
const { scenarios } = bridge;
|
|
111
|
+
scenarios.forEach((scenario) => {
|
|
112
|
+
if (isOutline(scenario)) {
|
|
113
|
+
bootstrapScenarioOutline(scenario, localApp, staticApp, events);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
bootstrapScenario(scenario, localApp, events);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function bootstrapScenario(bridge, localApp, events) {
|
|
120
|
+
const { data } = bridge;
|
|
121
|
+
const scenarioName = data.scope.title(data.gherkin);
|
|
122
|
+
const test = getTestOrModifier(bridge);
|
|
123
|
+
test(scenarioName, async () => {
|
|
124
|
+
events.scenario.emitStart({
|
|
125
|
+
title: scenarioName,
|
|
126
|
+
tags: [...data.gherkin.tags]
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
for (const step of bridge.steps) {
|
|
130
|
+
await step.data.scope.execute(step.data.gherkin, localApp());
|
|
131
|
+
}
|
|
132
|
+
} catch (e) {
|
|
133
|
+
events.scenario.emitEnd({
|
|
134
|
+
title: scenarioName,
|
|
135
|
+
tags: [...data.gherkin.tags],
|
|
136
|
+
status: "FAILED",
|
|
137
|
+
error: e
|
|
138
|
+
});
|
|
139
|
+
const message = `${scenarioName} failed to execute.`;
|
|
140
|
+
throw new import_errors.AutomationError(message, { cause: e });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function isOutline(data) {
|
|
145
|
+
return data instanceof import_test_builder.ScenarioOutlineBridge;
|
|
146
|
+
}
|
|
147
|
+
function bootstrapScenarioOutline(bridge, localApp, staticApp, events) {
|
|
148
|
+
const {
|
|
149
|
+
data: { scope, gherkin },
|
|
150
|
+
examples
|
|
151
|
+
} = bridge;
|
|
152
|
+
const title = scope.title(gherkin);
|
|
153
|
+
const [group, modifier] = getGroupOrModifier(bridge);
|
|
154
|
+
group(title, () => {
|
|
155
|
+
(0, import_globals.beforeAll)(() => {
|
|
156
|
+
events.scenarioOutline.emitStart({
|
|
157
|
+
title,
|
|
158
|
+
modifier,
|
|
159
|
+
tags: [...gherkin.tags]
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
bootstrapSetupHooks(bridge, staticApp, events);
|
|
163
|
+
bootstrapBeforeHooks(bridge, localApp, events);
|
|
164
|
+
examples.forEach((example) => {
|
|
165
|
+
bootstrapExamples(example, localApp, staticApp, events);
|
|
166
|
+
});
|
|
167
|
+
bootstrapAfterHooks(bridge, localApp, events);
|
|
168
|
+
bootstrapTeardownHooks(bridge, staticApp, events);
|
|
169
|
+
(0, import_globals.afterAll)(() => {
|
|
170
|
+
const failures = import_test_builder2.Query.find.failed(bridge);
|
|
171
|
+
const status = modifier === "skip" ? "SKIPPED" : failures.length === 0 ? "PASSED" : "FAILED";
|
|
172
|
+
events.scenarioOutline.emitEnd({
|
|
173
|
+
title,
|
|
174
|
+
modifier,
|
|
175
|
+
tags: [...gherkin.tags],
|
|
176
|
+
status
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function bootstrapExamples(example, localApp, staticApp, events) {
|
|
182
|
+
const title = example.data.scope.title(example.data.gherkin);
|
|
183
|
+
const [group] = getGroupOrModifier(example);
|
|
184
|
+
group(title, () => {
|
|
185
|
+
bootstrapScenarios(example, localApp, staticApp, events);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function bootstrapRules(bridge, localApp, staticApp, events) {
|
|
189
|
+
bridge.rules.forEach(({ data }) => {
|
|
190
|
+
const ruleName = data.scope.title(data.gherkin);
|
|
191
|
+
const [group, modifier] = getGroupOrModifier(bridge);
|
|
192
|
+
group(ruleName, () => {
|
|
193
|
+
(0, import_globals.beforeAll)(() => {
|
|
194
|
+
events.rule.emitStart({
|
|
195
|
+
title: ruleName,
|
|
196
|
+
modifier,
|
|
197
|
+
tags: [...data.gherkin.tags]
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
bootstrapSetupHooks(bridge, staticApp, events);
|
|
201
|
+
bootstrapBeforeHooks(bridge, localApp, events);
|
|
202
|
+
bootstrapBackground(bridge, localApp, events);
|
|
203
|
+
bootstrapScenarios(bridge, localApp, staticApp, events);
|
|
204
|
+
bootstrapAfterHooks(bridge, localApp, events);
|
|
205
|
+
bootstrapTeardownHooks(bridge, staticApp, events);
|
|
206
|
+
(0, import_globals.afterAll)(() => {
|
|
207
|
+
const failures = import_test_builder2.Query.find.failed(bridge);
|
|
208
|
+
const status = modifier === "skip" ? "SKIPPED" : failures.length === 0 ? "PASSED" : "FAILED";
|
|
209
|
+
events.rule.emitEnd({
|
|
210
|
+
title: ruleName,
|
|
211
|
+
modifier,
|
|
212
|
+
tags: [...data.gherkin.tags],
|
|
213
|
+
status
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function getGroupOrModifier({
|
|
220
|
+
data
|
|
221
|
+
}) {
|
|
222
|
+
if (data.gherkin.tags?.has("@skip") || data.gherkin.tags?.has("@skipped")) {
|
|
223
|
+
return [import_globals.describe.skip, "skip"];
|
|
224
|
+
}
|
|
225
|
+
if (data.gherkin.tags?.has("@only")) {
|
|
226
|
+
return [import_globals.describe.only, "only"];
|
|
227
|
+
}
|
|
228
|
+
return [import_globals.describe, void 0];
|
|
229
|
+
}
|
|
230
|
+
function getTestOrModifier({ data }) {
|
|
231
|
+
if (data.gherkin.tags?.has("@skip") || data.gherkin.tags?.has("@skipped")) {
|
|
232
|
+
return import_globals.it.skip;
|
|
233
|
+
}
|
|
234
|
+
if (data.gherkin.tags?.has("@only")) {
|
|
235
|
+
return import_globals.it.only;
|
|
236
|
+
}
|
|
237
|
+
return import_globals.it;
|
|
238
|
+
}
|
|
239
|
+
function bootstrapBeforeHooks(bridge, localApp, events) {
|
|
240
|
+
bridge.data.scope.hooks.before.forEach((hook) => {
|
|
241
|
+
const testName = import_globals.expect.getState().currentTestName;
|
|
242
|
+
if (!testName)
|
|
243
|
+
throw new import_errors.AutomationError("A Scenario must have a title");
|
|
244
|
+
const scenarioBridge = (0, import_test_builder.find)(bridge, testName);
|
|
245
|
+
if (!scenarioBridge) {
|
|
246
|
+
throw new import_errors.AutomationError(
|
|
247
|
+
`No matching scenario was found matching the test name: ${testName}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
const tags = scenarioBridge?.data?.gherkin?.tags ?? [];
|
|
251
|
+
(0, import_globals.beforeEach)(async () => {
|
|
252
|
+
events.before.emitStart({
|
|
253
|
+
title: hook.name,
|
|
254
|
+
tags: [...tags]
|
|
255
|
+
});
|
|
256
|
+
const report = await hook.execute(localApp(), ...tags);
|
|
257
|
+
events.before.emitEnd({
|
|
258
|
+
title: hook.name,
|
|
259
|
+
tags: [...tags],
|
|
260
|
+
status: report.status,
|
|
261
|
+
error: report.error
|
|
262
|
+
});
|
|
263
|
+
if (report.error) {
|
|
264
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
265
|
+
throw new import_errors.AutomationError(message, { cause: report.error });
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function bootstrapSetupHooks(bridge, staticApp, events) {
|
|
271
|
+
bridge.data.scope.hooks.setup.forEach((hook) => {
|
|
272
|
+
const tags = bridge.data.gherkin.tags ?? [];
|
|
273
|
+
(0, import_globals.beforeAll)(async () => {
|
|
274
|
+
events.setup.emitStart({
|
|
275
|
+
title: hook.name
|
|
276
|
+
});
|
|
277
|
+
const report = await hook.execute(staticApp, ...tags);
|
|
278
|
+
events.setup.emitEnd({
|
|
279
|
+
title: hook.name,
|
|
280
|
+
status: report.status,
|
|
281
|
+
error: report.error
|
|
282
|
+
});
|
|
283
|
+
if (report.error) {
|
|
284
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
285
|
+
throw new import_errors.AutomationError(message, { cause: report.error });
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
function bootstrapAfterHooks(bridge, localApp, events) {
|
|
291
|
+
bridge.data.scope.hooks.after.forEach((hook) => {
|
|
292
|
+
const testName = import_globals.expect.getState().currentTestName;
|
|
293
|
+
if (!testName)
|
|
294
|
+
throw new import_errors.AutomationError("A Scenario must have a title");
|
|
295
|
+
const scenarioBridge = (0, import_test_builder.find)(bridge, testName);
|
|
296
|
+
if (!scenarioBridge) {
|
|
297
|
+
throw new import_errors.AutomationError(
|
|
298
|
+
`No matching scenario bridge was found matching the test name: ${testName}`
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const tags = scenarioBridge?.data?.gherkin?.tags ?? [];
|
|
302
|
+
(0, import_globals.afterEach)(async () => {
|
|
303
|
+
events.after.emitStart({
|
|
304
|
+
title: hook.name,
|
|
305
|
+
tags: [...tags]
|
|
306
|
+
});
|
|
307
|
+
const report = await hook.execute(localApp(), ...tags);
|
|
308
|
+
events.after.emitEnd({
|
|
309
|
+
title: hook.name,
|
|
310
|
+
tags: [...tags],
|
|
311
|
+
status: report.status,
|
|
312
|
+
error: report.error
|
|
313
|
+
});
|
|
314
|
+
if (report.error) {
|
|
315
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
316
|
+
throw new import_errors.AutomationError(message, { cause: report.error });
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function bootstrapTeardownHooks(bridge, staticApp, event) {
|
|
322
|
+
const tags = bridge.data.gherkin.tags ?? [];
|
|
323
|
+
bridge.data.scope.hooks.teardown.forEach((hook) => {
|
|
324
|
+
(0, import_globals.afterAll)(async () => {
|
|
325
|
+
event.teardown.emitStart({
|
|
326
|
+
title: hook.name,
|
|
327
|
+
tags: [...tags]
|
|
328
|
+
});
|
|
329
|
+
const report = await hook.execute(staticApp, ...tags);
|
|
330
|
+
event.teardown.emitEnd({
|
|
331
|
+
title: hook.name,
|
|
332
|
+
tags: [...tags],
|
|
333
|
+
status: report.status,
|
|
334
|
+
error: report.error
|
|
335
|
+
});
|
|
336
|
+
if (report.error) {
|
|
337
|
+
const message = `${hook.name}: ${hook.description} failed to execute.`;
|
|
338
|
+
throw new import_errors.AutomationError(message, { cause: report.error });
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// src/index.ts
|
|
345
|
+
var src_default = execute;
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@autometa/jest-executor",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/esm/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/esm/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@cucumber/cucumber-expressions": "^16.1.2",
|
|
18
|
+
"@jest/globals": "^29.5.0",
|
|
19
|
+
"@types/node": "^18.11.18",
|
|
20
|
+
"@types/uuid": "^9.0.1",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
22
|
+
"@typescript-eslint/parser": "^5.54.1",
|
|
23
|
+
"eslint": "^8.37.0",
|
|
24
|
+
"eslint-config-custom": "0.5.1",
|
|
25
|
+
"eslint-config-prettier": "^8.3.0",
|
|
26
|
+
"jest": "^29.5.0",
|
|
27
|
+
"rimraf": "^4.1.2",
|
|
28
|
+
"ts-jest": "^29.1.1",
|
|
29
|
+
"ts-node": "^10.9.1",
|
|
30
|
+
"tsconfig": " *",
|
|
31
|
+
"tsup": "^6.7.0",
|
|
32
|
+
"typescript": "^4.9.5",
|
|
33
|
+
"vitest": "^0.29.8"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@jest/globals": "^29.5.0",
|
|
37
|
+
"jest": "^29.5.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@autometa/app": "^0.0.0",
|
|
41
|
+
"@autometa/asserters": "^0.0.0",
|
|
42
|
+
"@autometa/config": "^0.0.0",
|
|
43
|
+
"@autometa/errors": "^0.0.0",
|
|
44
|
+
"@autometa/events": "^0.0.10",
|
|
45
|
+
"@autometa/gherkin": "^0.3.3",
|
|
46
|
+
"@autometa/scopes": "^0.1.10",
|
|
47
|
+
"@autometa/test-builder": "^0.0.0",
|
|
48
|
+
"@autometa/types": "^0.3.1"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"test": "vitest run --passWithNoTests",
|
|
52
|
+
"prettify": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
|
53
|
+
"lint": "eslint . --max-warnings 0",
|
|
54
|
+
"lint:fix": "eslint . --fix",
|
|
55
|
+
"clean": "rimraf dist",
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"build:watch": "tsup --watch"
|
|
58
|
+
},
|
|
59
|
+
"readme": "# Introduction\n\nThere's nothing here yet"
|
|
60
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from "tsup";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
clean: true, // clean up the dist folder
|
|
5
|
+
format: ["cjs", "esm"], // generate cjs and esm files
|
|
6
|
+
dts: true,
|
|
7
|
+
sourcemap: false, // generate sourcemaps
|
|
8
|
+
skipNodeModulesBundle: true,
|
|
9
|
+
entryPoints: ["src/index.ts"],
|
|
10
|
+
target: "es2020",
|
|
11
|
+
outDir: "dist",
|
|
12
|
+
legacyOutput: true,
|
|
13
|
+
external: ["dist"],
|
|
14
|
+
});
|