@step-forge/step-forge 0.0.21 → 0.0.23
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/RUNTIME.md +73 -12
- package/dist/analyzer-DIZPMxzN.cjs +441 -0
- package/dist/analyzer-DIZPMxzN.cjs.map +1 -0
- package/dist/analyzer-DnfK54Dw.js +417 -0
- package/dist/analyzer-DnfK54Dw.js.map +1 -0
- package/dist/analyzer-cli.js +1 -1
- package/dist/{analyzer-DYfdoSIS.js → analyzer-gYyAKIpM.js} +61 -25
- package/dist/analyzer-gYyAKIpM.js.map +1 -0
- package/dist/analyzer.d.ts +2 -0
- package/dist/analyzer.js +1 -1
- package/dist/cli.cjs +753 -84
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +751 -84
- package/dist/cli.js.map +1 -1
- package/dist/{hooks-Dar49TtT.d.ts → config-C7PCYgYy.d.cts} +65 -16
- package/dist/{hooks-Dar49TtT.d.cts → config-C7PCYgYy.d.ts} +65 -16
- package/dist/{engine-DPRxs6eC.js → engine-DPVLEHBi.js} +8 -26
- package/dist/engine-DPVLEHBi.js.map +1 -0
- package/dist/{engine-DWAIlwWp.cjs → engine-vqA-eL_T.cjs} +8 -26
- package/dist/engine-vqA-eL_T.cjs.map +1 -0
- package/dist/{gherkinParser-CHpkEwii.cjs → gherkinParser-_ZgvELdy.cjs} +142 -3
- package/dist/gherkinParser-_ZgvELdy.cjs.map +1 -0
- package/dist/{gherkinParser-CKARHgt4.js → gherkinParser-i-Q7M6mi.js} +98 -4
- package/dist/gherkinParser-i-Q7M6mi.js.map +1 -0
- package/dist/hooks-BDCMKeNq.js +71 -0
- package/dist/{hooks-CywugMQQ.js.map → hooks-BDCMKeNq.js.map} +1 -1
- package/dist/{hooks-CGYzwDOv.cjs → hooks-Be0cjULN.cjs} +20 -31
- package/dist/{hooks-CGYzwDOv.cjs.map → hooks-Be0cjULN.cjs.map} +1 -1
- package/dist/runtime.cjs +3 -3
- package/dist/runtime.d.cts +11 -48
- package/dist/runtime.d.ts +11 -48
- package/dist/runtime.js +3 -3
- package/dist/step-forge.cjs +22 -377
- package/dist/step-forge.cjs.map +1 -1
- package/dist/step-forge.d.cts +13 -4
- package/dist/step-forge.d.ts +13 -4
- package/dist/step-forge.js +17 -371
- package/dist/step-forge.js.map +1 -1
- package/package.json +2 -2
- package/dist/analyzer-DYfdoSIS.js.map +0 -1
- package/dist/engine-DPRxs6eC.js.map +0 -1
- package/dist/engine-DWAIlwWp.cjs.map +0 -1
- package/dist/gherkinParser-CHpkEwii.cjs.map +0 -1
- package/dist/gherkinParser-CKARHgt4.js.map +0 -1
- package/dist/hooks-CywugMQQ.js +0 -82
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_hooks = require("./hooks-
|
|
1
|
+
const require_hooks = require("./hooks-Be0cjULN.cjs");
|
|
2
2
|
let _cucumber_cucumber_expressions = require("@cucumber/cucumber-expressions");
|
|
3
3
|
//#region src/runtime/engine.ts
|
|
4
4
|
const keywordToStepType = {
|
|
@@ -112,19 +112,23 @@ async function runScenario(scenario, compiled, makeWorld, hooks = require_hooks.
|
|
|
112
112
|
});
|
|
113
113
|
continue;
|
|
114
114
|
}
|
|
115
|
+
let source;
|
|
115
116
|
try {
|
|
116
117
|
const { step: def, args } = matchStep(step, compiled);
|
|
118
|
+
source = def.source;
|
|
117
119
|
await def.execute(world, args);
|
|
118
120
|
steps.push({
|
|
119
121
|
step,
|
|
120
|
-
status: "passed"
|
|
122
|
+
status: "passed",
|
|
123
|
+
source
|
|
121
124
|
});
|
|
122
125
|
} catch (err) {
|
|
123
126
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
124
127
|
steps.push({
|
|
125
128
|
step,
|
|
126
129
|
status: "failed",
|
|
127
|
-
error
|
|
130
|
+
error,
|
|
131
|
+
source
|
|
128
132
|
});
|
|
129
133
|
fail(error);
|
|
130
134
|
}
|
|
@@ -137,10 +141,6 @@ async function runScenario(scenario, compiled, makeWorld, hooks = require_hooks.
|
|
|
137
141
|
} catch (err) {
|
|
138
142
|
fail(err);
|
|
139
143
|
}
|
|
140
|
-
if (failed && firstError) {
|
|
141
|
-
const failing = steps.find((s) => s.status === "failed");
|
|
142
|
-
if (failing) attachFeatureFrame(firstError, scenario.file, failing.step);
|
|
143
|
-
}
|
|
144
144
|
return {
|
|
145
145
|
scenario,
|
|
146
146
|
status: failed ? "failed" : "passed",
|
|
@@ -157,24 +157,6 @@ async function runScenario(scenario, compiled, makeWorld, hooks = require_hooks.
|
|
|
157
157
|
function now() {
|
|
158
158
|
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
159
159
|
}
|
|
160
|
-
/**
|
|
161
|
-
* Prepend a synthetic stack frame pointing at the failing Gherkin step. Because
|
|
162
|
-
* the frame's file is the real `.feature` on disk, the test runner treats it as
|
|
163
|
-
* a source location and shows a code frame at the step — instead of us jamming
|
|
164
|
-
* `file:line` into the error message. The frame goes *above* the real stack, so
|
|
165
|
-
* the step-definition frames (the actual throw site) are preserved below it.
|
|
166
|
-
*/
|
|
167
|
-
function attachFeatureFrame(error, file, step) {
|
|
168
|
-
const frame = ` at ${`${step.effectiveKeyword} ${step.text}`} (${file}:${step.line}:${step.column})`;
|
|
169
|
-
const stack = error.stack;
|
|
170
|
-
if (!stack) {
|
|
171
|
-
error.stack = `${error.name}: ${error.message}\n${frame}`;
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const firstFrame = stack.indexOf("\n at ");
|
|
175
|
-
if (firstFrame === -1) error.stack = `${stack}\n${frame}`;
|
|
176
|
-
else error.stack = stack.slice(0, firstFrame) + `\n${frame}` + stack.slice(firstFrame);
|
|
177
|
-
}
|
|
178
160
|
//#endregion
|
|
179
161
|
Object.defineProperty(exports, "AmbiguousStepError", {
|
|
180
162
|
enumerable: true,
|
|
@@ -201,4 +183,4 @@ Object.defineProperty(exports, "runScenario", {
|
|
|
201
183
|
}
|
|
202
184
|
});
|
|
203
185
|
|
|
204
|
-
//# sourceMappingURL=engine-
|
|
186
|
+
//# sourceMappingURL=engine-vqA-eL_T.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine-vqA-eL_T.cjs","names":["ParameterTypeRegistry","ParameterType","CucumberExpression","globalHookRegistry"],"sources":["../../src/runtime/engine.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport {\n CucumberExpression,\n ParameterType,\n ParameterTypeRegistry,\n} from \"@cucumber/cucumber-expressions\";\nimport { ParsedScenario, ParsedStep } from \"../analyzer/types\";\nimport { MergeableWorld } from \"../world\";\nimport { globalHookRegistry, HookRegistry, ScenarioHookFn } from \"./hooks\";\nimport { RegisteredStep, StepRegistry, StepType } from \"./registry\";\n\nconst keywordToStepType: Record<ParsedStep[\"effectiveKeyword\"], StepType> = {\n Given: \"given\",\n When: \"when\",\n Then: \"then\",\n};\n\n/** A registered step paired with its compiled Cucumber expression. */\nexport interface CompiledStep {\n step: RegisteredStep;\n expression: CucumberExpression;\n}\n\nexport class UndefinedStepError extends Error {\n constructor(public readonly step: ParsedStep) {\n super(`Undefined step: ${step.effectiveKeyword} ${step.text}`);\n this.name = \"UndefinedStepError\";\n }\n}\n\nexport class AmbiguousStepError extends Error {\n constructor(\n public readonly step: ParsedStep,\n public readonly matches: RegisteredStep[]\n ) {\n super(\n `Ambiguous step: \"${step.text}\" matched ${matches.length} definitions:\\n` +\n matches.map(m => ` - ${m.expression}`).join(\"\\n\")\n );\n this.name = \"AmbiguousStepError\";\n }\n}\n\n/**\n * Compile a registry's steps into matchable Cucumber expressions **once** per\n * run. The result is reused for every scenario — compilation is pure and depends\n * only on the registry, so recompiling per scenario (as an earlier version did)\n * was wasted work proportional to scenarios × steps.\n */\nexport function compileRegistry(registry: StepRegistry): CompiledStep[] {\n return registry.all().map(step => {\n // Each step gets its own parameter-type registry (seeded with the\n // built-ins). A parser whose name is already registered — the built-in\n // `{int}`/`{float}`/`{string}`, or a repeat within the same step — reuses\n // that type; a novel name (e.g. `{boolean}`, `{color}`) is registered from\n // the parser's regexp + parse, so matching and coercion happen in one pass.\n const paramRegistry = new ParameterTypeRegistry();\n for (const parser of step.parsers) {\n if (paramRegistry.lookupByTypeName(parser.name)) continue;\n const regexps = Array.isArray(parser.regexp)\n ? parser.regexp\n : [parser.regexp];\n paramRegistry.defineParameterType(\n new ParameterType(parser.name, regexps, null, (value: string) =>\n parser.parse(value)\n )\n );\n }\n return {\n step,\n expression: new CucumberExpression(step.expression, paramRegistry),\n };\n });\n}\n\n/**\n * Find the single step definition matching a Gherkin step. Matching is\n * opinionated and strict: the keyword must line up with the step type, exactly\n * one definition must match, and undefined/ambiguous both throw rather than\n * silently skipping (unlike Cucumber's pending/undefined dance).\n */\nfunction matchStep(\n step: ParsedStep,\n compiled: CompiledStep[]\n): { step: RegisteredStep; args: unknown[] } {\n const expectedType = keywordToStepType[step.effectiveKeyword];\n const matches: { step: RegisteredStep; args: unknown[] }[] = [];\n\n for (const { step: def, expression } of compiled) {\n if (def.stepType !== expectedType) continue;\n const result = expression.match(step.text);\n if (result) {\n // The parsers are registered as the expression's parameter types, so the\n // captured values are already coerced (`{int}` → number, `{color}` → the\n // parser's T). `execute` consumes them as-is.\n matches.push({ step: def, args: result.map(a => a.getValue(null)) });\n }\n }\n\n if (matches.length === 0) throw new UndefinedStepError(step);\n if (matches.length > 1) {\n throw new AmbiguousStepError(\n step,\n matches.map(m => m.step)\n );\n }\n return matches[0];\n}\n\nexport interface StepResult {\n step: ParsedStep;\n status: \"passed\" | \"failed\" | \"skipped\";\n error?: Error;\n /**\n * Absolute `file:line:column` where the matched step is *defined* (its\n * `.step(...)` call site), for Cucumber-style reporting. Absent when no step\n * matched (undefined/ambiguous) or the step was skipped.\n */\n source?: string;\n durationMs?: number;\n}\n\nexport interface ScenarioResult {\n scenario: ParsedScenario;\n status: \"passed\" | \"failed\";\n steps: StepResult[];\n /**\n * The scenario's first error, if it failed. Usually the same object as the\n * failing step's `error`; for a hook failure there's no step to point at, so\n * this is the only place it surfaces. Reporters read this; the runner never\n * throws it.\n */\n error?: Error;\n /** Wall-clock duration of the whole scenario, in milliseconds. */\n durationMs?: number;\n}\n\n/**\n * Run one scenario against a pre-compiled step table. A fresh world is created\n * per scenario (state never leaks between scenarios). On the first failing step\n * the remaining steps are marked skipped, matching Cucumber's execution\n * semantics.\n *\n * Never throws for step or hook failures: it always resolves to a\n * `ScenarioResult` carrying the per-step breakdown and (on failure) the first\n * `error` with a synthetic `.feature` stack frame attached. Callers decide what\n * to do with a failure — the CLI runner reports it, a test-runner adapter can\n * re-throw `result.error`. It still rejects for truly exceptional conditions\n * (e.g. a bug in the engine itself), never for a normal test failure.\n *\n * Pass the compiled table from {@link compileRegistry} once and reuse it across\n * every scenario in the run.\n */\nexport async function runScenario(\n scenario: ParsedScenario,\n compiled: CompiledStep[],\n makeWorld: () => MergeableWorld<any, any, any>,\n hooks: HookRegistry = globalHookRegistry\n): Promise<ScenarioResult> {\n const start = now();\n const world = makeWorld();\n const scenarioInfo = { name: scenario.name, file: scenario.file };\n const steps: StepResult[] = [];\n let failed = false;\n let firstError: Error | undefined;\n\n const fail = (err: unknown) => {\n if (failed) return;\n failed = true;\n firstError = err instanceof Error ? err : new Error(String(err));\n };\n\n // before-scenario hooks: a throw here aborts the scenario before any step.\n try {\n for (const hook of hooks.for(\"scenario\", \"before\")) {\n await (hook.fn as ScenarioHookFn)({ world, scenario: scenarioInfo });\n }\n } catch (err) {\n fail(err);\n }\n\n for (const step of scenario.steps) {\n if (failed) {\n steps.push({ step, status: \"skipped\" });\n continue;\n }\n // `source` is captured before `execute` so a failing step still carries its\n // definition location; it stays undefined if matching itself throws\n // (undefined/ambiguous step).\n let source: string | undefined;\n try {\n const { step: def, args } = matchStep(step, compiled);\n source = def.source;\n await def.execute(world, args);\n steps.push({ step, status: \"passed\", source });\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n steps.push({ step, status: \"failed\", error, source });\n fail(error);\n }\n }\n\n // after-scenario hooks always run (teardown), even on failure. A hook failure\n // only becomes the scenario's error if nothing else failed first.\n for (const hook of hooks.for(\"scenario\", \"after\")) {\n try {\n await (hook.fn as ScenarioHookFn)({ world, scenario: scenarioInfo });\n } catch (err) {\n fail(err);\n }\n }\n\n return {\n scenario,\n status: failed ? \"failed\" : \"passed\",\n steps,\n error: firstError,\n durationMs: now() - start,\n };\n}\n\n/**\n * Monotonic-ish millisecond clock. `performance.now()` where available (Node &\n * Bun both expose it globally), falling back to `Date.now()`. Kept in one place\n * so timing is consistent across scenarios.\n */\nfunction now(): number {\n return typeof performance !== \"undefined\" ? performance.now() : Date.now();\n}\n"],"mappings":";;;AAWA,MAAM,oBAAsE;CAC1E,OAAO;CACP,MAAM;CACN,MAAM;AACR;AAQA,IAAa,qBAAb,cAAwC,MAAM;CAChB;CAA5B,YAAY,MAAkC;EAC5C,MAAM,mBAAmB,KAAK,iBAAiB,GAAG,KAAK,MAAM;EADnC,KAAA,OAAA;EAE1B,KAAK,OAAO;CACd;AACF;AAEA,IAAa,qBAAb,cAAwC,MAAM;CAE1B;CACA;CAFlB,YACE,MACA,SACA;EACA,MACE,oBAAoB,KAAK,KAAK,YAAY,QAAQ,OAAO,mBACvD,QAAQ,KAAI,MAAK,OAAO,EAAE,YAAY,CAAC,CAAC,KAAK,IAAI,CACrD;EANgB,KAAA,OAAA;EACA,KAAA,UAAA;EAMhB,KAAK,OAAO;CACd;AACF;;;;;;;AAQA,SAAgB,gBAAgB,UAAwC;CACtE,OAAO,SAAS,IAAI,CAAC,CAAC,KAAI,SAAQ;EAMhC,MAAM,gBAAgB,IAAIA,+BAAAA,sBAAsB;EAChD,KAAK,MAAM,UAAU,KAAK,SAAS;GACjC,IAAI,cAAc,iBAAiB,OAAO,IAAI,GAAG;GACjD,MAAM,UAAU,MAAM,QAAQ,OAAO,MAAM,IACvC,OAAO,SACP,CAAC,OAAO,MAAM;GAClB,cAAc,oBACZ,IAAIC,+BAAAA,cAAc,OAAO,MAAM,SAAS,OA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GACV,MAAM,KAAK;IAAE;IAAM,QAAQ;GAAU,CAAC;GACtC;EACF;EAIA,IAAI;EACJ,IAAI;GACF,MAAM,EAAE,MAAM,KAAK,SAAS,UAAU,MAAM,QAAQ;GACpD,SAAS,IAAI;GACb,MAAM,IAAI,QAAQ,OAAO,IAAI;GAC7B,MAAM,KAAK;IAAE;IAAM,QAAQ;IAAU;GAAO,CAAC;EAC/C,SAAS,KAAK;GACZ,MAAM,QAAQ,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC;GAChE,MAAM,KAAK;IAAE;IAAM,QAAQ;IAAU;IAAO;GAAO,CAAC;GACpD,KAAK,KAAK;EACZ;CACF;CAIA,KAAK,MAAM,QAAQ,MAAM,IAAI,YAAY,OAAO,GAC9C,IAAI;EACF,MAAO,KAAK,GAAsB;GAAE;GAAO,UAAU;EAAa,CAAC;CACrE,SAAS,KAAK;EACZ,KAAK,GAAG;CACV;CAGF,OAAO;EACL;EACA,QAAQ,SAAS,WAAW;EAC5B;EACA,OAAO;EACP,YAAY,IAAI,IAAI;CACtB;AACF;;;;;;AAOA,SAAS,MAAc;CACrB,OAAO,OAAO,gBAAgB,cAAc,YAAY,IAAI,IAAI,KAAK,IAAI;AAC3E"}
|
|
@@ -5,6 +5,15 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
8
17
|
var __copyProps = (to, from, except, desc) => {
|
|
9
18
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
19
|
key = keys[i];
|
|
@@ -22,14 +31,83 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
31
|
//#endregion
|
|
23
32
|
let lodash = require("lodash");
|
|
24
33
|
lodash = __toESM(lodash, 1);
|
|
25
|
-
let node_fs_promises = require("node:fs/promises");
|
|
26
34
|
let node_path = require("node:path");
|
|
27
35
|
node_path = __toESM(node_path, 1);
|
|
36
|
+
let node_url = require("node:url");
|
|
37
|
+
let node_fs_promises = require("node:fs/promises");
|
|
28
38
|
let node_fs = require("node:fs");
|
|
29
39
|
node_fs = __toESM(node_fs, 1);
|
|
30
40
|
let _cucumber_gherkin = require("@cucumber/gherkin");
|
|
31
41
|
let _cucumber_messages = require("@cucumber/messages");
|
|
32
42
|
_cucumber_messages = __toESM(_cucumber_messages, 1);
|
|
43
|
+
//#region src/sourceLocation.ts
|
|
44
|
+
/**
|
|
45
|
+
* Directory holding the library's own compiled code. In development this is the
|
|
46
|
+
* `src/` tree; in the published package it's `dist/` (this module is bundled
|
|
47
|
+
* into the shipped chunks). Stack frames under it are internal plumbing —
|
|
48
|
+
* builders, the engine, the runner — and are hidden from users so that a
|
|
49
|
+
* failure points at *their* step, not ours.
|
|
50
|
+
*/
|
|
51
|
+
const LIB_ROOT = node_path.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
52
|
+
/**
|
|
53
|
+
* A frame belongs to user code if it's an absolute path that is neither inside
|
|
54
|
+
* the library nor inside any `node_modules` (assertion libs, etc.). That leaves
|
|
55
|
+
* exactly the frames a user cares about: their own step definitions.
|
|
56
|
+
*/
|
|
57
|
+
function isUserFile(file) {
|
|
58
|
+
return node_path.isAbsolute(file) && !file.startsWith(LIB_ROOT + node_path.sep) && !file.includes(`${node_path.sep}node_modules${node_path.sep}`);
|
|
59
|
+
}
|
|
60
|
+
/** Parse one `Error.stack` line into a frame, tolerating V8/Bun variations. */
|
|
61
|
+
function parseFrame(frameLine) {
|
|
62
|
+
const m = /:(\d+):(\d+)\)?\s*$/.exec(frameLine);
|
|
63
|
+
if (!m) return void 0;
|
|
64
|
+
let file = frameLine.slice(0, m.index);
|
|
65
|
+
const paren = file.lastIndexOf("(");
|
|
66
|
+
if (paren !== -1) file = file.slice(paren + 1);
|
|
67
|
+
file = file.trim().replace(/^at\s+/, "");
|
|
68
|
+
if (file.startsWith("file://")) try {
|
|
69
|
+
file = (0, node_url.fileURLToPath)(file);
|
|
70
|
+
} catch {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
file,
|
|
75
|
+
line: Number(m[1]),
|
|
76
|
+
column: Number(m[2])
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Every user-code frame in a stack, nearest-first, internals removed. */
|
|
80
|
+
function userFrames(stack) {
|
|
81
|
+
if (!stack) return [];
|
|
82
|
+
const frames = [];
|
|
83
|
+
for (const line of stack.split("\n")) {
|
|
84
|
+
const frame = parseFrame(line);
|
|
85
|
+
if (frame && isUserFile(frame.file)) frames.push(frame);
|
|
86
|
+
}
|
|
87
|
+
return frames;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Capture the user source location of the current call site — the first
|
|
91
|
+
* user-code frame above this function. Called from `.step()` registration so
|
|
92
|
+
* each step remembers where it was defined (Cucumber-style), independent of
|
|
93
|
+
* where an error is later thrown. Returns an absolute `file:line:column`, or
|
|
94
|
+
* `undefined` if no user frame is visible.
|
|
95
|
+
*/
|
|
96
|
+
function captureDefinitionSite() {
|
|
97
|
+
const frame = userFrames((/* @__PURE__ */ new Error()).stack)[0];
|
|
98
|
+
return frame ? `${frame.file}:${frame.line}:${frame.column}` : void 0;
|
|
99
|
+
}
|
|
100
|
+
/** Render an absolute `file:line:column` relative to `cwd` for display. */
|
|
101
|
+
function relativeLocation(location, cwd) {
|
|
102
|
+
const m = /^(.*):(\d+):(\d+)$/.exec(location);
|
|
103
|
+
if (!m) return location;
|
|
104
|
+
return `${node_path.relative(cwd, m[1])}:${m[2]}:${m[3]}`;
|
|
105
|
+
}
|
|
106
|
+
/** Render a frame relative to `cwd`. */
|
|
107
|
+
function relativeFrame(frame, cwd) {
|
|
108
|
+
return `${node_path.relative(cwd, frame.file)}:${frame.line}:${frame.column}`;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
33
111
|
//#region src/world.ts
|
|
34
112
|
function mergeCustomizer(objValue, srcValue) {
|
|
35
113
|
if (lodash.default.isArray(objValue)) return objValue.concat(srcValue);
|
|
@@ -108,8 +186,31 @@ function parseFeatureFiles(filePaths) {
|
|
|
108
186
|
}
|
|
109
187
|
return scenarios;
|
|
110
188
|
}
|
|
189
|
+
/** Build a fresh gherkin parser and parse `content` into a document. */
|
|
190
|
+
function parseDocument(content) {
|
|
191
|
+
return new _cucumber_gherkin.Parser(new _cucumber_gherkin.AstBuilder(_cucumber_messages.IdGenerator.uuid()), new _cucumber_gherkin.GherkinClassicTokenMatcher()).parse(content);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Parse feature files into a catalog of `{ file, name, scenarios }`, one entry
|
|
195
|
+
* per file (one gherkin parse each). Used by interactive mode to offer
|
|
196
|
+
* feature/scenario names as typeahead choices labelled by their `Feature:` title.
|
|
197
|
+
*/
|
|
198
|
+
function parseFeatureCatalog(filePaths) {
|
|
199
|
+
return filePaths.map((file) => {
|
|
200
|
+
const document = parseDocument(node_fs.readFileSync(file, "utf-8"));
|
|
201
|
+
return {
|
|
202
|
+
file,
|
|
203
|
+
name: document.feature?.name ?? "",
|
|
204
|
+
scenarios: documentToScenarios(document, file)
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}
|
|
111
208
|
function parseFeatureContent(content, filePath) {
|
|
112
|
-
|
|
209
|
+
return documentToScenarios(parseDocument(content), filePath);
|
|
210
|
+
}
|
|
211
|
+
/** Expand a parsed gherkin document into scenarios (outline rows included). */
|
|
212
|
+
function documentToScenarios(gherkinDocument, filePath) {
|
|
213
|
+
const feature = gherkinDocument.feature;
|
|
113
214
|
if (!feature) return [];
|
|
114
215
|
const featureBackground = [];
|
|
115
216
|
const scenarios = [];
|
|
@@ -141,6 +242,7 @@ function expandScenario(scenario, backgroundSteps, filePath, inheritedTags) {
|
|
|
141
242
|
return [{
|
|
142
243
|
name: scenario.name,
|
|
143
244
|
file: filePath,
|
|
245
|
+
line: scenario.location.line,
|
|
144
246
|
steps: allSteps,
|
|
145
247
|
tags: scenarioTags
|
|
146
248
|
}];
|
|
@@ -165,6 +267,7 @@ function expandScenario(scenario, backgroundSteps, filePath, inheritedTags) {
|
|
|
165
267
|
results.push({
|
|
166
268
|
name: headers.map((h, i) => `${h}=${values[i]}`).join(", "),
|
|
167
269
|
file: filePath,
|
|
270
|
+
line: row.location.line,
|
|
168
271
|
steps: allSteps,
|
|
169
272
|
tags: exampleTags,
|
|
170
273
|
outline: { name: scenario.name }
|
|
@@ -215,18 +318,36 @@ Object.defineProperty(exports, "BasicWorld", {
|
|
|
215
318
|
return BasicWorld;
|
|
216
319
|
}
|
|
217
320
|
});
|
|
321
|
+
Object.defineProperty(exports, "__exportAll", {
|
|
322
|
+
enumerable: true,
|
|
323
|
+
get: function() {
|
|
324
|
+
return __exportAll;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
218
327
|
Object.defineProperty(exports, "__toESM", {
|
|
219
328
|
enumerable: true,
|
|
220
329
|
get: function() {
|
|
221
330
|
return __toESM;
|
|
222
331
|
}
|
|
223
332
|
});
|
|
333
|
+
Object.defineProperty(exports, "captureDefinitionSite", {
|
|
334
|
+
enumerable: true,
|
|
335
|
+
get: function() {
|
|
336
|
+
return captureDefinitionSite;
|
|
337
|
+
}
|
|
338
|
+
});
|
|
224
339
|
Object.defineProperty(exports, "globFiles", {
|
|
225
340
|
enumerable: true,
|
|
226
341
|
get: function() {
|
|
227
342
|
return globFiles;
|
|
228
343
|
}
|
|
229
344
|
});
|
|
345
|
+
Object.defineProperty(exports, "parseFeatureCatalog", {
|
|
346
|
+
enumerable: true,
|
|
347
|
+
get: function() {
|
|
348
|
+
return parseFeatureCatalog;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
230
351
|
Object.defineProperty(exports, "parseFeatureContent", {
|
|
231
352
|
enumerable: true,
|
|
232
353
|
get: function() {
|
|
@@ -239,5 +360,23 @@ Object.defineProperty(exports, "parseFeatureFiles", {
|
|
|
239
360
|
return parseFeatureFiles;
|
|
240
361
|
}
|
|
241
362
|
});
|
|
363
|
+
Object.defineProperty(exports, "relativeFrame", {
|
|
364
|
+
enumerable: true,
|
|
365
|
+
get: function() {
|
|
366
|
+
return relativeFrame;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
Object.defineProperty(exports, "relativeLocation", {
|
|
370
|
+
enumerable: true,
|
|
371
|
+
get: function() {
|
|
372
|
+
return relativeLocation;
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
Object.defineProperty(exports, "userFrames", {
|
|
376
|
+
enumerable: true,
|
|
377
|
+
get: function() {
|
|
378
|
+
return userFrames;
|
|
379
|
+
}
|
|
380
|
+
});
|
|
242
381
|
|
|
243
|
-
//# sourceMappingURL=gherkinParser-
|
|
382
|
+
//# sourceMappingURL=gherkinParser-_ZgvELdy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gherkinParser-_ZgvELdy.cjs","names":["path","_","path","fs","Parser","AstBuilder","messages","GherkinClassicTokenMatcher"],"sources":["../../src/sourceLocation.ts","../../src/world.ts","../../src/globFiles.ts","../../src/analyzer/gherkinParser.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Directory holding the library's own compiled code. In development this is the\n * `src/` tree; in the published package it's `dist/` (this module is bundled\n * into the shipped chunks). Stack frames under it are internal plumbing —\n * builders, the engine, the runner — and are hidden from users so that a\n * failure points at *their* step, not ours.\n */\nconst LIB_ROOT = path.dirname(fileURLToPath(import.meta.url));\n\nexport interface SourceFrame {\n file: string;\n line: number;\n column: number;\n}\n\n/**\n * A frame belongs to user code if it's an absolute path that is neither inside\n * the library nor inside any `node_modules` (assertion libs, etc.). That leaves\n * exactly the frames a user cares about: their own step definitions.\n */\nfunction isUserFile(file: string): boolean {\n return (\n path.isAbsolute(file) &&\n !file.startsWith(LIB_ROOT + path.sep) &&\n !file.includes(`${path.sep}node_modules${path.sep}`)\n );\n}\n\n/** Parse one `Error.stack` line into a frame, tolerating V8/Bun variations. */\nfunction parseFrame(frameLine: string): SourceFrame | undefined {\n const m = /:(\\d+):(\\d+)\\)?\\s*$/.exec(frameLine);\n if (!m) return undefined;\n let file = frameLine.slice(0, m.index);\n const paren = file.lastIndexOf(\"(\");\n if (paren !== -1) file = file.slice(paren + 1);\n file = file.trim().replace(/^at\\s+/, \"\");\n if (file.startsWith(\"file://\")) {\n try {\n file = fileURLToPath(file);\n } catch {\n return undefined;\n }\n }\n return { file, line: Number(m[1]), column: Number(m[2]) };\n}\n\n/** Every user-code frame in a stack, nearest-first, internals removed. */\nexport function userFrames(stack: string | undefined): SourceFrame[] {\n if (!stack) return [];\n const frames: SourceFrame[] = [];\n for (const line of stack.split(\"\\n\")) {\n const frame = parseFrame(line);\n if (frame && isUserFile(frame.file)) frames.push(frame);\n }\n return frames;\n}\n\n/**\n * Capture the user source location of the current call site — the first\n * user-code frame above this function. Called from `.step()` registration so\n * each step remembers where it was defined (Cucumber-style), independent of\n * where an error is later thrown. Returns an absolute `file:line:column`, or\n * `undefined` if no user frame is visible.\n */\nexport function captureDefinitionSite(): string | undefined {\n const frame = userFrames(new Error().stack)[0];\n return frame ? `${frame.file}:${frame.line}:${frame.column}` : undefined;\n}\n\n/** Render an absolute `file:line:column` relative to `cwd` for display. */\nexport function relativeLocation(location: string, cwd: string): string {\n const m = /^(.*):(\\d+):(\\d+)$/.exec(location);\n if (!m) return location;\n return `${path.relative(cwd, m[1])}:${m[2]}:${m[3]}`;\n}\n\n/** Render a frame relative to `cwd`. */\nexport function relativeFrame(frame: SourceFrame, cwd: string): string {\n return `${path.relative(cwd, frame.file)}:${frame.line}:${frame.column}`;\n}\n","import _ from \"lodash\";\n\nexport type WorldState<State> = {\n readonly [K in keyof State]?: State[K];\n};\n\nexport type MergeableWorldState<T> = WorldState<T> & {\n merge: (newState: Partial<T>) => void;\n};\n\nfunction mergeCustomizer(objValue: unknown, srcValue: unknown) {\n if (_.isArray(objValue)) {\n return objValue.concat(srcValue);\n } else if (objValue && !_.isPlainObject(objValue) && objValue !== srcValue) {\n throw new Error(\n `Merge would have destroyed previous value ${objValue} with ${srcValue}`\n );\n }\n return objValue;\n}\n\nexport const createMergeableState = <T>(\n state: WorldState<T>\n): MergeableWorldState<T> => {\n return {\n ...state,\n merge: (newState: Partial<T>) => {\n state = _.merge({ ...state }, newState, mergeCustomizer);\n },\n };\n};\n\nexport type MergeableWorld<Given, When, Then> = {\n given: MergeableWorldState<Given>;\n when: MergeableWorldState<When>;\n then: MergeableWorldState<Then>;\n};\n\nexport class BasicWorld<Given, When, Then> {\n private givenState: WorldState<Given> = {};\n private whenState: WorldState<When> = {};\n private thenState: WorldState<Then> = {};\n\n public get given(): MergeableWorldState<Given> {\n return {\n ...this.givenState,\n merge: (newState: Partial<Given>) => {\n this.givenState = _.merge(\n { ...this.givenState },\n newState,\n mergeCustomizer\n );\n },\n };\n }\n\n public get when(): MergeableWorldState<When> {\n return {\n ...this.whenState,\n merge: (newState: Partial<When>) => {\n this.whenState = _.merge(\n { ...this.whenState },\n newState,\n mergeCustomizer\n );\n },\n };\n }\n\n public get then(): MergeableWorldState<Then> {\n return {\n ...this.thenState,\n merge: (newState: Partial<Then>) => {\n this.thenState = _.merge(\n { ...this.thenState },\n newState,\n mergeCustomizer\n );\n },\n };\n }\n}\n\nexport const createBasicWorld = <Given, When, Then>(): MergeableWorld<\n Given,\n When,\n Then\n> => {\n return new BasicWorld<Given, When, Then>();\n};\n","import { glob } from \"node:fs/promises\";\nimport { stat } from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\n/** Glob metacharacters. A pattern with none of these is a literal path. */\nconst MAGIC = /[*?[\\]{}!()]/;\n\nasync function isFile(p: string): Promise<boolean> {\n try {\n return (await stat(p)).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Resolve glob patterns to a de-duplicated list of absolute file paths, with one\n * important portability guarantee: a **literal absolute path** (no glob magic)\n * is returned directly if it exists, without being handed to `glob()`.\n *\n * This exists because `node:fs`'s `glob` diverges between runtimes — Node\n * matches an absolute-path pattern, Bun returns nothing for one. Rather than\n * depend on that behaviour, we only ever glob relative patterns (against `cwd`)\n * and short-circuit concrete absolute paths ourselves, so callers get identical\n * results under Node and Bun.\n */\nexport async function globFiles(\n patterns: string[],\n cwd: string = process.cwd()\n): Promise<string[]> {\n const files = new Set<string>();\n for (const pattern of patterns) {\n if (path.isAbsolute(pattern) && !MAGIC.test(pattern)) {\n if (await isFile(pattern)) files.add(pattern);\n continue;\n }\n for await (const match of glob(pattern, { cwd })) {\n files.add(path.resolve(cwd, match));\n }\n }\n return [...files];\n}\n","import * as fs from \"node:fs\";\nimport {\n GherkinClassicTokenMatcher,\n Parser,\n AstBuilder,\n} from \"@cucumber/gherkin\";\nimport * as messages from \"@cucumber/messages\";\nimport { ParsedScenario, ParsedStep } from \"./types.js\";\n\ntype GherkinKeyword = \"Given\" | \"When\" | \"Then\" | \"And\" | \"But\";\n\nexport function parseFeatureFiles(filePaths: string[]): ParsedScenario[] {\n const scenarios: ParsedScenario[] = [];\n\n for (const filePath of filePaths) {\n const content = fs.readFileSync(filePath, \"utf-8\");\n const parsed = parseFeatureContent(content, filePath);\n scenarios.push(...parsed);\n }\n\n return scenarios;\n}\n\n/**\n * One parsed feature file: its `Feature:` title (empty if unnamed) plus every\n * scenario (outline rows expanded). {@link parseFeatureContent} exposes just the\n * scenarios; {@link parseFeatureCatalog} keeps the title too, for UIs that label\n * scenarios by their feature.\n */\nexport interface ParsedFeature {\n file: string;\n name: string;\n scenarios: ParsedScenario[];\n}\n\n/** Build a fresh gherkin parser and parse `content` into a document. */\nfunction parseDocument(content: string): messages.GherkinDocument {\n const builder = new AstBuilder(messages.IdGenerator.uuid());\n const matcher = new GherkinClassicTokenMatcher();\n return new Parser(builder, matcher).parse(content);\n}\n\n/**\n * Parse feature files into a catalog of `{ file, name, scenarios }`, one entry\n * per file (one gherkin parse each). Used by interactive mode to offer\n * feature/scenario names as typeahead choices labelled by their `Feature:` title.\n */\nexport function parseFeatureCatalog(filePaths: string[]): ParsedFeature[] {\n return filePaths.map(file => {\n const document = parseDocument(fs.readFileSync(file, \"utf-8\"));\n return {\n file,\n name: document.feature?.name ?? \"\",\n scenarios: documentToScenarios(document, file),\n };\n });\n}\n\nexport function parseFeatureContent(\n content: string,\n filePath: string\n): ParsedScenario[] {\n return documentToScenarios(parseDocument(content), filePath);\n}\n\n/** Expand a parsed gherkin document into scenarios (outline rows included). */\nfunction documentToScenarios(\n gherkinDocument: messages.GherkinDocument,\n filePath: string\n): ParsedScenario[] {\n const feature = gherkinDocument.feature;\n if (!feature) return [];\n\n // Collect background steps at the feature level\n const featureBackground: messages.Step[] = [];\n const scenarios: ParsedScenario[] = [];\n const featureTags = tagNames(feature.tags);\n\n for (const child of feature.children) {\n if (child.background) {\n featureBackground.push(...child.background.steps);\n }\n\n if (child.scenario) {\n scenarios.push(\n ...expandScenario(\n child.scenario,\n featureBackground,\n filePath,\n featureTags\n )\n );\n }\n\n if (child.rule) {\n // Rules can have their own backgrounds and tags, both inherited by the\n // rule's scenarios.\n const ruleBackground: messages.Step[] = [...featureBackground];\n const ruleTags = [...featureTags, ...tagNames(child.rule.tags)];\n for (const ruleChild of child.rule.children) {\n if (ruleChild.background) {\n ruleBackground.push(...ruleChild.background.steps);\n }\n if (ruleChild.scenario) {\n scenarios.push(\n ...expandScenario(\n ruleChild.scenario,\n ruleBackground,\n filePath,\n ruleTags\n )\n );\n }\n }\n }\n }\n\n return scenarios;\n}\n\n/** Extract tag names (each keeping its leading `@`), deduped in order. */\nfunction tagNames(tags: readonly messages.Tag[] | undefined): string[] {\n return [...new Set((tags ?? []).map(t => t.name))];\n}\n\nfunction expandScenario(\n scenario: messages.Scenario,\n backgroundSteps: messages.Step[],\n filePath: string,\n inheritedTags: string[]\n): ParsedScenario[] {\n const scenarioTags = [...inheritedTags, ...tagNames(scenario.tags)];\n const hasExamples =\n scenario.examples.length > 0 &&\n scenario.examples.some(e => e.tableBody.length > 0);\n\n if (!hasExamples) {\n // Regular scenario\n const bgParsed = convertSteps(backgroundSteps);\n const scenarioParsed = convertSteps(scenario.steps);\n const allSteps = resolveEffectiveKeywords([...bgParsed, ...scenarioParsed]);\n\n return [\n {\n name: scenario.name,\n file: filePath,\n line: scenario.location.line,\n steps: allSteps,\n tags: scenarioTags,\n },\n ];\n }\n\n // Scenario Outline — expand with each example row. Rows carry the outline's\n // base name so the runner can group them, plus the Examples-block tags.\n const results: ParsedScenario[] = [];\n for (const example of scenario.examples) {\n if (!example.tableHeader || example.tableBody.length === 0) continue;\n const headers = example.tableHeader.cells.map(c => c.value);\n const exampleTags = [...scenarioTags, ...tagNames(example.tags)];\n\n for (const row of example.tableBody) {\n const values = row.cells.map(c => c.value);\n const substitution: Record<string, string> = {};\n headers.forEach((h, i) => {\n substitution[h] = values[i];\n });\n\n const bgParsed = convertSteps(backgroundSteps);\n const scenarioSteps = convertSteps(scenario.steps).map(step => ({\n ...step,\n text: substituteExampleValues(step.text, substitution),\n }));\n const allSteps = resolveEffectiveKeywords([\n ...bgParsed,\n ...scenarioSteps,\n ]);\n\n results.push({\n name: headers.map((h, i) => `${h}=${values[i]}`).join(\", \"),\n file: filePath,\n line: row.location.line,\n steps: allSteps,\n tags: exampleTags,\n outline: { name: scenario.name },\n });\n }\n }\n\n return results;\n}\n\nfunction convertSteps(\n steps: readonly messages.Step[]\n): Omit<ParsedStep, \"effectiveKeyword\">[] {\n return steps.map(step => ({\n keyword: normalizeKeyword(step.keyword),\n text: step.text,\n line: step.location.line,\n // step.location.column points to the keyword start; shift past the\n // keyword (which includes a trailing space) so column points to the\n // start of the step text. This makes `column + text.length` produce\n // the correct end position for diagnostic ranges.\n column: (step.location.column ?? 1) + step.keyword.length,\n }));\n}\n\nfunction normalizeKeyword(keyword: string): GherkinKeyword {\n const trimmed = keyword.trim();\n // Gherkin keywords may include trailing space, e.g. \"Given \"\n if (trimmed === \"Given\") return \"Given\";\n if (trimmed === \"When\") return \"When\";\n if (trimmed === \"Then\") return \"Then\";\n if (trimmed === \"And\") return \"And\";\n if (trimmed === \"But\") return \"But\";\n // Fallback: treat as Given (shouldn't happen with valid Gherkin)\n return \"Given\";\n}\n\nfunction resolveEffectiveKeywords(\n steps: Omit<ParsedStep, \"effectiveKeyword\">[]\n): ParsedStep[] {\n let lastEffective: \"Given\" | \"When\" | \"Then\" = \"Given\";\n\n return steps.map(step => {\n let effectiveKeyword: \"Given\" | \"When\" | \"Then\";\n if (step.keyword === \"And\" || step.keyword === \"But\") {\n effectiveKeyword = lastEffective;\n } else {\n effectiveKeyword = step.keyword as \"Given\" | \"When\" | \"Then\";\n }\n lastEffective = effectiveKeyword;\n\n return {\n ...step,\n effectiveKeyword,\n };\n });\n}\n\nfunction substituteExampleValues(\n text: string,\n substitution: Record<string, string>\n): string {\n let result = text;\n for (const [key, value] of Object.entries(substitution)) {\n result = result.replace(new RegExp(`<${key}>`, \"g\"), value);\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,WAAWA,UAAK,SAAA,GAAA,SAAA,cAAA,CAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,IAAqC,CAAC;;;;;;AAa5D,SAAS,WAAW,MAAuB;CACzC,OACEA,UAAK,WAAW,IAAI,KACpB,CAAC,KAAK,WAAW,WAAWA,UAAK,GAAG,KACpC,CAAC,KAAK,SAAS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;OAEnB,mBAAmB,KAAK;EAE1B,gBAAgB;EAEhB,OAAO;GACL,GAAG;GACH;EACF;CACF,CAAC;AACH;AAEA,SAAS,wBACP,MACA,cACQ;CACR,IAAI,SAAS;CACb,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,YAAY,GACpD,SAAS,OAAO,QAAQ,IAAI,OAAO,IAAI,IAAI,IAAI,GAAG,GAAG,KAAK;CAE5D,OAAO;AACT"}
|
|
@@ -1,9 +1,78 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
-
import { glob, stat } from "node:fs/promises";
|
|
3
2
|
import * as path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { glob, stat } from "node:fs/promises";
|
|
4
5
|
import * as fs from "node:fs";
|
|
5
6
|
import { AstBuilder, GherkinClassicTokenMatcher, Parser } from "@cucumber/gherkin";
|
|
6
7
|
import * as messages from "@cucumber/messages";
|
|
8
|
+
//#region src/sourceLocation.ts
|
|
9
|
+
/**
|
|
10
|
+
* Directory holding the library's own compiled code. In development this is the
|
|
11
|
+
* `src/` tree; in the published package it's `dist/` (this module is bundled
|
|
12
|
+
* into the shipped chunks). Stack frames under it are internal plumbing —
|
|
13
|
+
* builders, the engine, the runner — and are hidden from users so that a
|
|
14
|
+
* failure points at *their* step, not ours.
|
|
15
|
+
*/
|
|
16
|
+
const LIB_ROOT = path.dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
/**
|
|
18
|
+
* A frame belongs to user code if it's an absolute path that is neither inside
|
|
19
|
+
* the library nor inside any `node_modules` (assertion libs, etc.). That leaves
|
|
20
|
+
* exactly the frames a user cares about: their own step definitions.
|
|
21
|
+
*/
|
|
22
|
+
function isUserFile(file) {
|
|
23
|
+
return path.isAbsolute(file) && !file.startsWith(LIB_ROOT + path.sep) && !file.includes(`${path.sep}node_modules${path.sep}`);
|
|
24
|
+
}
|
|
25
|
+
/** Parse one `Error.stack` line into a frame, tolerating V8/Bun variations. */
|
|
26
|
+
function parseFrame(frameLine) {
|
|
27
|
+
const m = /:(\d+):(\d+)\)?\s*$/.exec(frameLine);
|
|
28
|
+
if (!m) return void 0;
|
|
29
|
+
let file = frameLine.slice(0, m.index);
|
|
30
|
+
const paren = file.lastIndexOf("(");
|
|
31
|
+
if (paren !== -1) file = file.slice(paren + 1);
|
|
32
|
+
file = file.trim().replace(/^at\s+/, "");
|
|
33
|
+
if (file.startsWith("file://")) try {
|
|
34
|
+
file = fileURLToPath(file);
|
|
35
|
+
} catch {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
file,
|
|
40
|
+
line: Number(m[1]),
|
|
41
|
+
column: Number(m[2])
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/** Every user-code frame in a stack, nearest-first, internals removed. */
|
|
45
|
+
function userFrames(stack) {
|
|
46
|
+
if (!stack) return [];
|
|
47
|
+
const frames = [];
|
|
48
|
+
for (const line of stack.split("\n")) {
|
|
49
|
+
const frame = parseFrame(line);
|
|
50
|
+
if (frame && isUserFile(frame.file)) frames.push(frame);
|
|
51
|
+
}
|
|
52
|
+
return frames;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Capture the user source location of the current call site — the first
|
|
56
|
+
* user-code frame above this function. Called from `.step()` registration so
|
|
57
|
+
* each step remembers where it was defined (Cucumber-style), independent of
|
|
58
|
+
* where an error is later thrown. Returns an absolute `file:line:column`, or
|
|
59
|
+
* `undefined` if no user frame is visible.
|
|
60
|
+
*/
|
|
61
|
+
function captureDefinitionSite() {
|
|
62
|
+
const frame = userFrames((/* @__PURE__ */ new Error()).stack)[0];
|
|
63
|
+
return frame ? `${frame.file}:${frame.line}:${frame.column}` : void 0;
|
|
64
|
+
}
|
|
65
|
+
/** Render an absolute `file:line:column` relative to `cwd` for display. */
|
|
66
|
+
function relativeLocation(location, cwd) {
|
|
67
|
+
const m = /^(.*):(\d+):(\d+)$/.exec(location);
|
|
68
|
+
if (!m) return location;
|
|
69
|
+
return `${path.relative(cwd, m[1])}:${m[2]}:${m[3]}`;
|
|
70
|
+
}
|
|
71
|
+
/** Render a frame relative to `cwd`. */
|
|
72
|
+
function relativeFrame(frame, cwd) {
|
|
73
|
+
return `${path.relative(cwd, frame.file)}:${frame.line}:${frame.column}`;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
7
76
|
//#region src/world.ts
|
|
8
77
|
function mergeCustomizer(objValue, srcValue) {
|
|
9
78
|
if (_.isArray(objValue)) return objValue.concat(srcValue);
|
|
@@ -82,8 +151,31 @@ function parseFeatureFiles(filePaths) {
|
|
|
82
151
|
}
|
|
83
152
|
return scenarios;
|
|
84
153
|
}
|
|
154
|
+
/** Build a fresh gherkin parser and parse `content` into a document. */
|
|
155
|
+
function parseDocument(content) {
|
|
156
|
+
return new Parser(new AstBuilder(messages.IdGenerator.uuid()), new GherkinClassicTokenMatcher()).parse(content);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parse feature files into a catalog of `{ file, name, scenarios }`, one entry
|
|
160
|
+
* per file (one gherkin parse each). Used by interactive mode to offer
|
|
161
|
+
* feature/scenario names as typeahead choices labelled by their `Feature:` title.
|
|
162
|
+
*/
|
|
163
|
+
function parseFeatureCatalog(filePaths) {
|
|
164
|
+
return filePaths.map((file) => {
|
|
165
|
+
const document = parseDocument(fs.readFileSync(file, "utf-8"));
|
|
166
|
+
return {
|
|
167
|
+
file,
|
|
168
|
+
name: document.feature?.name ?? "",
|
|
169
|
+
scenarios: documentToScenarios(document, file)
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
}
|
|
85
173
|
function parseFeatureContent(content, filePath) {
|
|
86
|
-
|
|
174
|
+
return documentToScenarios(parseDocument(content), filePath);
|
|
175
|
+
}
|
|
176
|
+
/** Expand a parsed gherkin document into scenarios (outline rows included). */
|
|
177
|
+
function documentToScenarios(gherkinDocument, filePath) {
|
|
178
|
+
const feature = gherkinDocument.feature;
|
|
87
179
|
if (!feature) return [];
|
|
88
180
|
const featureBackground = [];
|
|
89
181
|
const scenarios = [];
|
|
@@ -115,6 +207,7 @@ function expandScenario(scenario, backgroundSteps, filePath, inheritedTags) {
|
|
|
115
207
|
return [{
|
|
116
208
|
name: scenario.name,
|
|
117
209
|
file: filePath,
|
|
210
|
+
line: scenario.location.line,
|
|
118
211
|
steps: allSteps,
|
|
119
212
|
tags: scenarioTags
|
|
120
213
|
}];
|
|
@@ -139,6 +232,7 @@ function expandScenario(scenario, backgroundSteps, filePath, inheritedTags) {
|
|
|
139
232
|
results.push({
|
|
140
233
|
name: headers.map((h, i) => `${h}=${values[i]}`).join(", "),
|
|
141
234
|
file: filePath,
|
|
235
|
+
line: row.location.line,
|
|
142
236
|
steps: allSteps,
|
|
143
237
|
tags: exampleTags,
|
|
144
238
|
outline: { name: scenario.name }
|
|
@@ -183,6 +277,6 @@ function substituteExampleValues(text, substitution) {
|
|
|
183
277
|
return result;
|
|
184
278
|
}
|
|
185
279
|
//#endregion
|
|
186
|
-
export { BasicWorld as i,
|
|
280
|
+
export { BasicWorld as a, relativeLocation as c, globFiles as i, userFrames as l, parseFeatureContent as n, captureDefinitionSite as o, parseFeatureFiles as r, relativeFrame as s, parseFeatureCatalog as t };
|
|
187
281
|
|
|
188
|
-
//# sourceMappingURL=gherkinParser-
|
|
282
|
+
//# sourceMappingURL=gherkinParser-i-Q7M6mi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gherkinParser-i-Q7M6mi.js","names":[],"sources":["../../src/sourceLocation.ts","../../src/world.ts","../../src/globFiles.ts","../../src/analyzer/gherkinParser.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Directory holding the library's own compiled code. In development this is the\n * `src/` tree; in the published package it's `dist/` (this module is bundled\n * into the shipped chunks). Stack frames under it are internal plumbing —\n * builders, the engine, the runner — and are hidden from users so that a\n * failure points at *their* step, not ours.\n */\nconst LIB_ROOT = path.dirname(fileURLToPath(import.meta.url));\n\nexport interface SourceFrame {\n file: string;\n line: number;\n column: number;\n}\n\n/**\n * A frame belongs to user code if it's an absolute path that is neither inside\n * the library nor inside any `node_modules` (assertion libs, etc.). That leaves\n * exactly the frames a user cares about: their own step definitions.\n */\nfunction isUserFile(file: string): boolean {\n return (\n path.isAbsolute(file) &&\n !file.startsWith(LIB_ROOT + path.sep) &&\n !file.includes(`${path.sep}node_modules${path.sep}`)\n );\n}\n\n/** Parse one `Error.stack` line into a frame, tolerating V8/Bun variations. */\nfunction parseFrame(frameLine: string): SourceFrame | undefined {\n const m = /:(\\d+):(\\d+)\\)?\\s*$/.exec(frameLine);\n if (!m) return undefined;\n let file = frameLine.slice(0, m.index);\n const paren = file.lastIndexOf(\"(\");\n if (paren !== -1) file = file.slice(paren + 1);\n file = file.trim().replace(/^at\\s+/, \"\");\n if (file.startsWith(\"file://\")) {\n try {\n file = fileURLToPath(file);\n } catch {\n return undefined;\n }\n }\n return { file, line: Number(m[1]), column: Number(m[2]) };\n}\n\n/** Every user-code frame in a stack, nearest-first, internals removed. */\nexport function userFrames(stack: string | undefined): SourceFrame[] {\n if (!stack) return [];\n const frames: SourceFrame[] = [];\n for (const line of stack.split(\"\\n\")) {\n const frame = parseFrame(line);\n if (frame && isUserFile(frame.file)) frames.push(frame);\n }\n return frames;\n}\n\n/**\n * Capture the user source location of the current call site — the first\n * user-code frame above this function. Called from `.step()` registration so\n * each step remembers where it was defined (Cucumber-style), independent of\n * where an error is later thrown. Returns an absolute `file:line:column`, or\n * `undefined` if no user frame is visible.\n */\nexport function captureDefinitionSite(): string | undefined {\n const frame = userFrames(new Error().stack)[0];\n return frame ? `${frame.file}:${frame.line}:${frame.column}` : undefined;\n}\n\n/** Render an absolute `file:line:column` relative to `cwd` for display. */\nexport function relativeLocation(location: string, cwd: string): string {\n const m = /^(.*):(\\d+):(\\d+)$/.exec(location);\n if (!m) return location;\n return `${path.relative(cwd, m[1])}:${m[2]}:${m[3]}`;\n}\n\n/** Render a frame relative to `cwd`. */\nexport function relativeFrame(frame: SourceFrame, cwd: string): string {\n return `${path.relative(cwd, frame.file)}:${frame.line}:${frame.column}`;\n}\n","import _ from \"lodash\";\n\nexport type WorldState<State> = {\n readonly [K in keyof State]?: State[K];\n};\n\nexport type MergeableWorldState<T> = WorldState<T> & {\n merge: (newState: Partial<T>) => void;\n};\n\nfunction mergeCustomizer(objValue: unknown, srcValue: unknown) {\n if (_.isArray(objValue)) {\n return objValue.concat(srcValue);\n } else if (objValue && !_.isPlainObject(objValue) && objValue !== srcValue) {\n throw new Error(\n `Merge would have destroyed previous value ${objValue} with ${srcValue}`\n );\n }\n return objValue;\n}\n\nexport const createMergeableState = <T>(\n state: WorldState<T>\n): MergeableWorldState<T> => {\n return {\n ...state,\n merge: (newState: Partial<T>) => {\n state = _.merge({ ...state }, newState, mergeCustomizer);\n },\n };\n};\n\nexport type MergeableWorld<Given, When, Then> = {\n given: MergeableWorldState<Given>;\n when: MergeableWorldState<When>;\n then: MergeableWorldState<Then>;\n};\n\nexport class BasicWorld<Given, When, Then> {\n private givenState: WorldState<Given> = {};\n private whenState: WorldState<When> = {};\n private thenState: WorldState<Then> = {};\n\n public get given(): MergeableWorldState<Given> {\n return {\n ...this.givenState,\n merge: (newState: Partial<Given>) => {\n this.givenState = _.merge(\n { ...this.givenState },\n newState,\n mergeCustomizer\n );\n },\n };\n }\n\n public get when(): MergeableWorldState<When> {\n return {\n ...this.whenState,\n merge: (newState: Partial<When>) => {\n this.whenState = _.merge(\n { ...this.whenState },\n newState,\n mergeCustomizer\n );\n },\n };\n }\n\n public get then(): MergeableWorldState<Then> {\n return {\n ...this.thenState,\n merge: (newState: Partial<Then>) => {\n this.thenState = _.merge(\n { ...this.thenState },\n newState,\n mergeCustomizer\n );\n },\n };\n }\n}\n\nexport const createBasicWorld = <Given, When, Then>(): MergeableWorld<\n Given,\n When,\n Then\n> => {\n return new BasicWorld<Given, When, Then>();\n};\n","import { glob } from \"node:fs/promises\";\nimport { stat } from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\n/** Glob metacharacters. A pattern with none of these is a literal path. */\nconst MAGIC = /[*?[\\]{}!()]/;\n\nasync function isFile(p: string): Promise<boolean> {\n try {\n return (await stat(p)).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Resolve glob patterns to a de-duplicated list of absolute file paths, with one\n * important portability guarantee: a **literal absolute path** (no glob magic)\n * is returned directly if it exists, without being handed to `glob()`.\n *\n * This exists because `node:fs`'s `glob` diverges between runtimes — Node\n * matches an absolute-path pattern, Bun returns nothing for one. Rather than\n * depend on that behaviour, we only ever glob relative patterns (against `cwd`)\n * and short-circuit concrete absolute paths ourselves, so callers get identical\n * results under Node and Bun.\n */\nexport async function globFiles(\n patterns: string[],\n cwd: string = process.cwd()\n): Promise<string[]> {\n const files = new Set<string>();\n for (const pattern of patterns) {\n if (path.isAbsolute(pattern) && !MAGIC.test(pattern)) {\n if (await isFile(pattern)) files.add(pattern);\n continue;\n }\n for await (const match of glob(pattern, { cwd })) {\n files.add(path.resolve(cwd, match));\n }\n }\n return [...files];\n}\n","import * as fs from \"node:fs\";\nimport {\n GherkinClassicTokenMatcher,\n Parser,\n AstBuilder,\n} from \"@cucumber/gherkin\";\nimport * as messages from \"@cucumber/messages\";\nimport { ParsedScenario, ParsedStep } from \"./types.js\";\n\ntype GherkinKeyword = \"Given\" | \"When\" | \"Then\" | \"And\" | \"But\";\n\nexport function parseFeatureFiles(filePaths: string[]): ParsedScenario[] {\n const scenarios: ParsedScenario[] = [];\n\n for (const filePath of filePaths) {\n const content = fs.readFileSync(filePath, \"utf-8\");\n const parsed = parseFeatureContent(content, filePath);\n scenarios.push(...parsed);\n }\n\n return scenarios;\n}\n\n/**\n * One parsed feature file: its `Feature:` title (empty if unnamed) plus every\n * scenario (outline rows expanded). {@link parseFeatureContent} exposes just the\n * scenarios; {@link parseFeatureCatalog} keeps the title too, for UIs that label\n * scenarios by their feature.\n */\nexport interface ParsedFeature {\n file: string;\n name: string;\n scenarios: ParsedScenario[];\n}\n\n/** Build a fresh gherkin parser and parse `content` into a document. */\nfunction parseDocument(content: string): messages.GherkinDocument {\n const builder = new AstBuilder(messages.IdGenerator.uuid());\n const matcher = new GherkinClassicTokenMatcher();\n return new Parser(builder, matcher).parse(content);\n}\n\n/**\n * Parse feature files into a catalog of `{ file, name, scenarios }`, one entry\n * per file (one gherkin parse each). Used by interactive mode to offer\n * feature/scenario names as typeahead choices labelled by their `Feature:` title.\n */\nexport function parseFeatureCatalog(filePaths: string[]): ParsedFeature[] {\n return filePaths.map(file => {\n const document = parseDocument(fs.readFileSync(file, \"utf-8\"));\n return {\n file,\n name: document.feature?.name ?? \"\",\n scenarios: documentToScenarios(document, file),\n };\n });\n}\n\nexport function parseFeatureContent(\n content: string,\n filePath: string\n): ParsedScenario[] {\n return documentToScenarios(parseDocument(content), filePath);\n}\n\n/** Expand a parsed gherkin document into scenarios (outline rows included). */\nfunction documentToScenarios(\n gherkinDocument: messages.GherkinDocument,\n filePath: string\n): ParsedScenario[] {\n const feature = gherkinDocument.feature;\n if (!feature) return [];\n\n // Collect background steps at the feature level\n const featureBackground: messages.Step[] = [];\n const scenarios: ParsedScenario[] = [];\n const featureTags = tagNames(feature.tags);\n\n for (const child of feature.children) {\n if (child.background) {\n featureBackground.push(...child.background.steps);\n }\n\n if (child.scenario) {\n scenarios.push(\n ...expandScenario(\n child.scenario,\n featureBackground,\n filePath,\n featureTags\n )\n );\n }\n\n if (child.rule) {\n // Rules can have their own backgrounds and tags, both inherited by the\n // rule's scenarios.\n const ruleBackground: messages.Step[] = [...featureBackground];\n const ruleTags = [...featureTags, ...tagNames(child.rule.tags)];\n for (const ruleChild of child.rule.children) {\n if (ruleChild.background) {\n ruleBackground.push(...ruleChild.background.steps);\n }\n if (ruleChild.scenario) {\n scenarios.push(\n ...expandScenario(\n ruleChild.scenario,\n ruleBackground,\n filePath,\n ruleTags\n )\n );\n }\n }\n }\n }\n\n return scenarios;\n}\n\n/** Extract tag names (each keeping its leading `@`), deduped in order. */\nfunction tagNames(tags: readonly messages.Tag[] | undefined): string[] {\n return [...new Set((tags ?? []).map(t => t.name))];\n}\n\nfunction expandScenario(\n scenario: messages.Scenario,\n backgroundSteps: messages.Step[],\n filePath: string,\n inheritedTags: string[]\n): ParsedScenario[] {\n const scenarioTags = [...inheritedTags, ...tagNames(scenario.tags)];\n const hasExamples =\n scenario.examples.length > 0 &&\n scenario.examples.some(e => e.tableBody.length > 0);\n\n if (!hasExamples) {\n // Regular scenario\n const bgParsed = convertSteps(backgroundSteps);\n const scenarioParsed = convertSteps(scenario.steps);\n const allSteps = resolveEffectiveKeywords([...bgParsed, ...scenarioParsed]);\n\n return [\n {\n name: scenario.name,\n file: filePath,\n line: scenario.location.line,\n steps: allSteps,\n tags: scenarioTags,\n },\n ];\n }\n\n // Scenario Outline — expand with each example row. Rows carry the outline's\n // base name so the runner can group them, plus the Examples-block tags.\n const results: ParsedScenario[] = [];\n for (const example of scenario.examples) {\n if (!example.tableHeader || example.tableBody.length === 0) continue;\n const headers = example.tableHeader.cells.map(c => c.value);\n const exampleTags = [...scenarioTags, ...tagNames(example.tags)];\n\n for (const row of example.tableBody) {\n const values = row.cells.map(c => c.value);\n const substitution: Record<string, string> = {};\n headers.forEach((h, i) => {\n substitution[h] = values[i];\n });\n\n const bgParsed = convertSteps(backgroundSteps);\n const scenarioSteps = convertSteps(scenario.steps).map(step => ({\n ...step,\n text: substituteExampleValues(step.text, substitution),\n }));\n const allSteps = resolveEffectiveKeywords([\n ...bgParsed,\n ...scenarioSteps,\n ]);\n\n results.push({\n name: headers.map((h, i) => `${h}=${values[i]}`).join(\", \"),\n file: filePath,\n line: row.location.line,\n steps: allSteps,\n tags: exampleTags,\n outline: { name: scenario.name },\n });\n }\n }\n\n return results;\n}\n\nfunction convertSteps(\n steps: readonly messages.Step[]\n): Omit<ParsedStep, \"effectiveKeyword\">[] {\n return steps.map(step => ({\n keyword: normalizeKeyword(step.keyword),\n text: step.text,\n line: step.location.line,\n // step.location.column points to the keyword start; shift past the\n // keyword (which includes a trailing space) so column points to the\n // start of the step text. This makes `column + text.length` produce\n // the correct end position for diagnostic ranges.\n column: (step.location.column ?? 1) + step.keyword.length,\n }));\n}\n\nfunction normalizeKeyword(keyword: string): GherkinKeyword {\n const trimmed = keyword.trim();\n // Gherkin keywords may include trailing space, e.g. \"Given \"\n if (trimmed === \"Given\") return \"Given\";\n if (trimmed === \"When\") return \"When\";\n if (trimmed === \"Then\") return \"Then\";\n if (trimmed === \"And\") return \"And\";\n if (trimmed === \"But\") return \"But\";\n // Fallback: treat as Given (shouldn't happen with valid Gherkin)\n return \"Given\";\n}\n\nfunction resolveEffectiveKeywords(\n steps: Omit<ParsedStep, \"effectiveKeyword\">[]\n): ParsedStep[] {\n let lastEffective: \"Given\" | \"When\" | \"Then\" = \"Given\";\n\n return steps.map(step => {\n let effectiveKeyword: \"Given\" | \"When\" | \"Then\";\n if (step.keyword === \"And\" || step.keyword === \"But\") {\n effectiveKeyword = lastEffective;\n } else {\n effectiveKeyword = step.keyword as \"Given\" | \"When\" | \"Then\";\n }\n lastEffective = effectiveKeyword;\n\n return {\n ...step,\n effectiveKeyword,\n };\n });\n}\n\nfunction substituteExampleValues(\n text: string,\n substitution: Record<string, string>\n): string {\n let result = text;\n for (const [key, value] of Object.entries(substitution)) {\n result = result.replace(new RegExp(`<${key}>`, \"g\"), value);\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAUA,MAAM,WAAW,KAAK,QAAQ,cAAc,OAAO,KAAK,GAAG,CAAC;;;;;;AAa5D,SAAS,WAAW,MAAuB;CACzC,OACE,KAAK,WAAW,IAAI,KACpB,CAAC,KAAK,WAAW,WAAW,KAAK,GAAG,KACpC,CAAC,KAAK,SAAS,GAAG,KAAK,IAAI,cAAc,KAAK,KAAK;AAEvD;;AAGA,SAAS,WAAW,WAA4C;CAC9D,MAAM,IAAI,sBAAsB,KAAK,SAAS;CAC9C,IAAI,CAAC,GAAG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ACT"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/runtime/registry.ts
|
|
2
|
+
/**
|
|
3
|
+
* A collection of registered steps. Deliberately a plain instance (not a hidden
|
|
4
|
+
* module global) so tests and the Vitest plugin can create isolated registries.
|
|
5
|
+
* `globalRegistry` is the default sink that `.step()` writes to.
|
|
6
|
+
*/
|
|
7
|
+
var StepRegistry = class {
|
|
8
|
+
steps = [];
|
|
9
|
+
add(step) {
|
|
10
|
+
this.steps.push(step);
|
|
11
|
+
}
|
|
12
|
+
all() {
|
|
13
|
+
return this.steps;
|
|
14
|
+
}
|
|
15
|
+
clear() {
|
|
16
|
+
this.steps = [];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const globalRegistry = new StepRegistry();
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/runtime/hooks.ts
|
|
22
|
+
/**
|
|
23
|
+
* Collection of registered hooks. Like {@link StepRegistry}, a plain instance
|
|
24
|
+
* (not a hidden global) so tests can isolate; `globalHookRegistry` is the
|
|
25
|
+
* default sink the public `beforeScenario`/`afterAll`/etc helpers write to.
|
|
26
|
+
*/
|
|
27
|
+
var HookRegistry = class {
|
|
28
|
+
hooks = [];
|
|
29
|
+
add(hook) {
|
|
30
|
+
this.hooks.push(hook);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Hooks for a scope+timing. `before` hooks run in registration order;
|
|
34
|
+
* `after` hooks run in reverse (LIFO), so teardown unwinds setup.
|
|
35
|
+
*/
|
|
36
|
+
for(scope, timing) {
|
|
37
|
+
const matching = this.hooks.filter((h) => h.scope === scope && h.timing === timing);
|
|
38
|
+
return timing === "after" ? matching.reverse() : matching;
|
|
39
|
+
}
|
|
40
|
+
clear() {
|
|
41
|
+
this.hooks = [];
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const globalHookRegistry = new HookRegistry();
|
|
45
|
+
/**
|
|
46
|
+
* Run every registered hook of a scope+timing **in registration order** (after
|
|
47
|
+
* hooks reversed by {@link HookRegistry.for}, so teardown unwinds setup). Used
|
|
48
|
+
* for feature hooks, where ordering matters. Throws if a hook throws, so the
|
|
49
|
+
* runner reports it against the enclosing boundary.
|
|
50
|
+
*/
|
|
51
|
+
async function runHooks(scope, timing, registry = globalHookRegistry) {
|
|
52
|
+
for (const hook of registry.for(scope, timing)) await hook.fn();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Run every registered hook of a scope+timing **concurrently**, resolving once
|
|
56
|
+
* all of them settle. This is how global `beforeAll`/`afterAll` run: independent
|
|
57
|
+
* setup/teardown steps fire in parallel with no ordering between them. A hook
|
|
58
|
+
* with a sequential requirement should sequence that work inside a single hook.
|
|
59
|
+
*
|
|
60
|
+
* The runner calls this exactly once for `beforeAll` (before any scenario
|
|
61
|
+
* starts) and once for `afterAll` (after every scenario is done), so global
|
|
62
|
+
* setup/teardown brackets the whole run deterministically. Rejects if any hook
|
|
63
|
+
* rejects (via `Promise.all`), surfacing the first failure to the caller.
|
|
64
|
+
*/
|
|
65
|
+
async function runHooksParallel(scope, timing, registry = globalHookRegistry) {
|
|
66
|
+
await Promise.all(registry.for(scope, timing).map((hook) => hook.fn()));
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { StepRegistry as a, runHooksParallel as i, globalHookRegistry as n, globalRegistry as o, runHooks as r, HookRegistry as t };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=hooks-BDCMKeNq.js.map
|