@step-forge/step-forge 0.0.20 → 0.0.22
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/README.md +2 -0
- package/RUNTIME.md +242 -0
- package/dist/{analyzer-DJyJbU_V.js → analyzer-byS8yRrY.js} +202 -34
- package/dist/analyzer-byS8yRrY.js.map +1 -0
- package/dist/analyzer-cli.js +1 -1
- package/dist/analyzer.d.ts +2 -0
- package/dist/analyzer.js +1 -2
- package/dist/cli.cjs +525 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +526 -0
- package/dist/cli.js.map +1 -0
- 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-DPVLEHBi.js +163 -0
- package/dist/engine-DPVLEHBi.js.map +1 -0
- package/dist/engine-vqA-eL_T.cjs +186 -0
- package/dist/engine-vqA-eL_T.cjs.map +1 -0
- package/dist/gherkinParser-BT40q_i3.cjs +338 -0
- package/dist/gherkinParser-BT40q_i3.cjs.map +1 -0
- package/dist/gherkinParser-NcttZgN4.js +259 -0
- package/dist/gherkinParser-NcttZgN4.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 +7 -162
- package/dist/runtime.d.cts +44 -8
- package/dist/runtime.d.ts +44 -8
- package/dist/runtime.js +3 -159
- package/dist/step-forge.cjs +73 -216
- package/dist/step-forge.cjs.map +1 -1
- package/dist/step-forge.d.cts +19 -10
- package/dist/step-forge.d.ts +19 -10
- package/dist/step-forge.js +67 -185
- package/dist/step-forge.js.map +1 -1
- package/package.json +12 -18
- package/dist/analyzer-DJyJbU_V.js.map +0 -1
- package/dist/gherkinParser-Dp2d7JNr.js +0 -116
- package/dist/gherkinParser-Dp2d7JNr.js.map +0 -1
- package/dist/hooks-CywugMQQ.js +0 -82
- package/dist/runtime.cjs.map +0 -1
- package/dist/runtime.js.map +0 -1
- package/dist/vitest.d.ts +0 -74
- package/dist/vitest.js +0 -136
- package/dist/vitest.js.map +0 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
const require_hooks = require("./hooks-Be0cjULN.cjs");
|
|
2
|
+
let _cucumber_cucumber_expressions = require("@cucumber/cucumber-expressions");
|
|
3
|
+
//#region src/runtime/engine.ts
|
|
4
|
+
const keywordToStepType = {
|
|
5
|
+
Given: "given",
|
|
6
|
+
When: "when",
|
|
7
|
+
Then: "then"
|
|
8
|
+
};
|
|
9
|
+
var UndefinedStepError = class extends Error {
|
|
10
|
+
step;
|
|
11
|
+
constructor(step) {
|
|
12
|
+
super(`Undefined step: ${step.effectiveKeyword} ${step.text}`);
|
|
13
|
+
this.step = step;
|
|
14
|
+
this.name = "UndefinedStepError";
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var AmbiguousStepError = class extends Error {
|
|
18
|
+
step;
|
|
19
|
+
matches;
|
|
20
|
+
constructor(step, matches) {
|
|
21
|
+
super(`Ambiguous step: "${step.text}" matched ${matches.length} definitions:\n` + matches.map((m) => ` - ${m.expression}`).join("\n"));
|
|
22
|
+
this.step = step;
|
|
23
|
+
this.matches = matches;
|
|
24
|
+
this.name = "AmbiguousStepError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Compile a registry's steps into matchable Cucumber expressions **once** per
|
|
29
|
+
* run. The result is reused for every scenario — compilation is pure and depends
|
|
30
|
+
* only on the registry, so recompiling per scenario (as an earlier version did)
|
|
31
|
+
* was wasted work proportional to scenarios × steps.
|
|
32
|
+
*/
|
|
33
|
+
function compileRegistry(registry) {
|
|
34
|
+
return registry.all().map((step) => {
|
|
35
|
+
const paramRegistry = new _cucumber_cucumber_expressions.ParameterTypeRegistry();
|
|
36
|
+
for (const parser of step.parsers) {
|
|
37
|
+
if (paramRegistry.lookupByTypeName(parser.name)) continue;
|
|
38
|
+
const regexps = Array.isArray(parser.regexp) ? parser.regexp : [parser.regexp];
|
|
39
|
+
paramRegistry.defineParameterType(new _cucumber_cucumber_expressions.ParameterType(parser.name, regexps, null, (value) => parser.parse(value)));
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
step,
|
|
43
|
+
expression: new _cucumber_cucumber_expressions.CucumberExpression(step.expression, paramRegistry)
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Find the single step definition matching a Gherkin step. Matching is
|
|
49
|
+
* opinionated and strict: the keyword must line up with the step type, exactly
|
|
50
|
+
* one definition must match, and undefined/ambiguous both throw rather than
|
|
51
|
+
* silently skipping (unlike Cucumber's pending/undefined dance).
|
|
52
|
+
*/
|
|
53
|
+
function matchStep(step, compiled) {
|
|
54
|
+
const expectedType = keywordToStepType[step.effectiveKeyword];
|
|
55
|
+
const matches = [];
|
|
56
|
+
for (const { step: def, expression } of compiled) {
|
|
57
|
+
if (def.stepType !== expectedType) continue;
|
|
58
|
+
const result = expression.match(step.text);
|
|
59
|
+
if (result) matches.push({
|
|
60
|
+
step: def,
|
|
61
|
+
args: result.map((a) => a.getValue(null))
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (matches.length === 0) throw new UndefinedStepError(step);
|
|
65
|
+
if (matches.length > 1) throw new AmbiguousStepError(step, matches.map((m) => m.step));
|
|
66
|
+
return matches[0];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Run one scenario against a pre-compiled step table. A fresh world is created
|
|
70
|
+
* per scenario (state never leaks between scenarios). On the first failing step
|
|
71
|
+
* the remaining steps are marked skipped, matching Cucumber's execution
|
|
72
|
+
* semantics.
|
|
73
|
+
*
|
|
74
|
+
* Never throws for step or hook failures: it always resolves to a
|
|
75
|
+
* `ScenarioResult` carrying the per-step breakdown and (on failure) the first
|
|
76
|
+
* `error` with a synthetic `.feature` stack frame attached. Callers decide what
|
|
77
|
+
* to do with a failure — the CLI runner reports it, a test-runner adapter can
|
|
78
|
+
* re-throw `result.error`. It still rejects for truly exceptional conditions
|
|
79
|
+
* (e.g. a bug in the engine itself), never for a normal test failure.
|
|
80
|
+
*
|
|
81
|
+
* Pass the compiled table from {@link compileRegistry} once and reuse it across
|
|
82
|
+
* every scenario in the run.
|
|
83
|
+
*/
|
|
84
|
+
async function runScenario(scenario, compiled, makeWorld, hooks = require_hooks.globalHookRegistry) {
|
|
85
|
+
const start = now();
|
|
86
|
+
const world = makeWorld();
|
|
87
|
+
const scenarioInfo = {
|
|
88
|
+
name: scenario.name,
|
|
89
|
+
file: scenario.file
|
|
90
|
+
};
|
|
91
|
+
const steps = [];
|
|
92
|
+
let failed = false;
|
|
93
|
+
let firstError;
|
|
94
|
+
const fail = (err) => {
|
|
95
|
+
if (failed) return;
|
|
96
|
+
failed = true;
|
|
97
|
+
firstError = err instanceof Error ? err : new Error(String(err));
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
for (const hook of hooks.for("scenario", "before")) await hook.fn({
|
|
101
|
+
world,
|
|
102
|
+
scenario: scenarioInfo
|
|
103
|
+
});
|
|
104
|
+
} catch (err) {
|
|
105
|
+
fail(err);
|
|
106
|
+
}
|
|
107
|
+
for (const step of scenario.steps) {
|
|
108
|
+
if (failed) {
|
|
109
|
+
steps.push({
|
|
110
|
+
step,
|
|
111
|
+
status: "skipped"
|
|
112
|
+
});
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
let source;
|
|
116
|
+
try {
|
|
117
|
+
const { step: def, args } = matchStep(step, compiled);
|
|
118
|
+
source = def.source;
|
|
119
|
+
await def.execute(world, args);
|
|
120
|
+
steps.push({
|
|
121
|
+
step,
|
|
122
|
+
status: "passed",
|
|
123
|
+
source
|
|
124
|
+
});
|
|
125
|
+
} catch (err) {
|
|
126
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
127
|
+
steps.push({
|
|
128
|
+
step,
|
|
129
|
+
status: "failed",
|
|
130
|
+
error,
|
|
131
|
+
source
|
|
132
|
+
});
|
|
133
|
+
fail(error);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
for (const hook of hooks.for("scenario", "after")) try {
|
|
137
|
+
await hook.fn({
|
|
138
|
+
world,
|
|
139
|
+
scenario: scenarioInfo
|
|
140
|
+
});
|
|
141
|
+
} catch (err) {
|
|
142
|
+
fail(err);
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
scenario,
|
|
146
|
+
status: failed ? "failed" : "passed",
|
|
147
|
+
steps,
|
|
148
|
+
error: firstError,
|
|
149
|
+
durationMs: now() - start
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Monotonic-ish millisecond clock. `performance.now()` where available (Node &
|
|
154
|
+
* Bun both expose it globally), falling back to `Date.now()`. Kept in one place
|
|
155
|
+
* so timing is consistent across scenarios.
|
|
156
|
+
*/
|
|
157
|
+
function now() {
|
|
158
|
+
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
Object.defineProperty(exports, "AmbiguousStepError", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: function() {
|
|
164
|
+
return AmbiguousStepError;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(exports, "UndefinedStepError", {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
get: function() {
|
|
170
|
+
return UndefinedStepError;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
Object.defineProperty(exports, "compileRegistry", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function() {
|
|
176
|
+
return compileRegistry;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(exports, "runScenario", {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function() {
|
|
182
|
+
return runScenario;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
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,iBA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QAAQ,GAC/C,MAAO,KAAK,GAAsB;GAAE;GAAO,UAAU;EAAa,CAAC;CAEvE,SAAS,KAAK;EACZ,KAAK,GAAG;CACV;CAEA,KAAK,MAAM,QAAQ,SAAS,OAAO;EACjC,IAAI,QAAQ;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"}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let lodash = require("lodash");
|
|
24
|
+
lodash = __toESM(lodash, 1);
|
|
25
|
+
let node_path = require("node:path");
|
|
26
|
+
node_path = __toESM(node_path, 1);
|
|
27
|
+
let node_url = require("node:url");
|
|
28
|
+
let node_fs_promises = require("node:fs/promises");
|
|
29
|
+
let node_fs = require("node:fs");
|
|
30
|
+
node_fs = __toESM(node_fs, 1);
|
|
31
|
+
let _cucumber_gherkin = require("@cucumber/gherkin");
|
|
32
|
+
let _cucumber_messages = require("@cucumber/messages");
|
|
33
|
+
_cucumber_messages = __toESM(_cucumber_messages, 1);
|
|
34
|
+
//#region src/sourceLocation.ts
|
|
35
|
+
/**
|
|
36
|
+
* Directory holding the library's own compiled code. In development this is the
|
|
37
|
+
* `src/` tree; in the published package it's `dist/` (this module is bundled
|
|
38
|
+
* into the shipped chunks). Stack frames under it are internal plumbing —
|
|
39
|
+
* builders, the engine, the runner — and are hidden from users so that a
|
|
40
|
+
* failure points at *their* step, not ours.
|
|
41
|
+
*/
|
|
42
|
+
const LIB_ROOT = node_path.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
43
|
+
/**
|
|
44
|
+
* A frame belongs to user code if it's an absolute path that is neither inside
|
|
45
|
+
* the library nor inside any `node_modules` (assertion libs, etc.). That leaves
|
|
46
|
+
* exactly the frames a user cares about: their own step definitions.
|
|
47
|
+
*/
|
|
48
|
+
function isUserFile(file) {
|
|
49
|
+
return node_path.isAbsolute(file) && !file.startsWith(LIB_ROOT + node_path.sep) && !file.includes(`${node_path.sep}node_modules${node_path.sep}`);
|
|
50
|
+
}
|
|
51
|
+
/** Parse one `Error.stack` line into a frame, tolerating V8/Bun variations. */
|
|
52
|
+
function parseFrame(frameLine) {
|
|
53
|
+
const m = /:(\d+):(\d+)\)?\s*$/.exec(frameLine);
|
|
54
|
+
if (!m) return void 0;
|
|
55
|
+
let file = frameLine.slice(0, m.index);
|
|
56
|
+
const paren = file.lastIndexOf("(");
|
|
57
|
+
if (paren !== -1) file = file.slice(paren + 1);
|
|
58
|
+
file = file.trim().replace(/^at\s+/, "");
|
|
59
|
+
if (file.startsWith("file://")) try {
|
|
60
|
+
file = (0, node_url.fileURLToPath)(file);
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
file,
|
|
66
|
+
line: Number(m[1]),
|
|
67
|
+
column: Number(m[2])
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** Every user-code frame in a stack, nearest-first, internals removed. */
|
|
71
|
+
function userFrames(stack) {
|
|
72
|
+
if (!stack) return [];
|
|
73
|
+
const frames = [];
|
|
74
|
+
for (const line of stack.split("\n")) {
|
|
75
|
+
const frame = parseFrame(line);
|
|
76
|
+
if (frame && isUserFile(frame.file)) frames.push(frame);
|
|
77
|
+
}
|
|
78
|
+
return frames;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Capture the user source location of the current call site — the first
|
|
82
|
+
* user-code frame above this function. Called from `.step()` registration so
|
|
83
|
+
* each step remembers where it was defined (Cucumber-style), independent of
|
|
84
|
+
* where an error is later thrown. Returns an absolute `file:line:column`, or
|
|
85
|
+
* `undefined` if no user frame is visible.
|
|
86
|
+
*/
|
|
87
|
+
function captureDefinitionSite() {
|
|
88
|
+
const frame = userFrames((/* @__PURE__ */ new Error()).stack)[0];
|
|
89
|
+
return frame ? `${frame.file}:${frame.line}:${frame.column}` : void 0;
|
|
90
|
+
}
|
|
91
|
+
/** Render an absolute `file:line:column` relative to `cwd` for display. */
|
|
92
|
+
function relativeLocation(location, cwd) {
|
|
93
|
+
const m = /^(.*):(\d+):(\d+)$/.exec(location);
|
|
94
|
+
if (!m) return location;
|
|
95
|
+
return `${node_path.relative(cwd, m[1])}:${m[2]}:${m[3]}`;
|
|
96
|
+
}
|
|
97
|
+
/** Render a frame relative to `cwd`. */
|
|
98
|
+
function relativeFrame(frame, cwd) {
|
|
99
|
+
return `${node_path.relative(cwd, frame.file)}:${frame.line}:${frame.column}`;
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/world.ts
|
|
103
|
+
function mergeCustomizer(objValue, srcValue) {
|
|
104
|
+
if (lodash.default.isArray(objValue)) return objValue.concat(srcValue);
|
|
105
|
+
else if (objValue && !lodash.default.isPlainObject(objValue) && objValue !== srcValue) throw new Error(`Merge would have destroyed previous value ${objValue} with ${srcValue}`);
|
|
106
|
+
return objValue;
|
|
107
|
+
}
|
|
108
|
+
var BasicWorld = class {
|
|
109
|
+
givenState = {};
|
|
110
|
+
whenState = {};
|
|
111
|
+
thenState = {};
|
|
112
|
+
get given() {
|
|
113
|
+
return {
|
|
114
|
+
...this.givenState,
|
|
115
|
+
merge: (newState) => {
|
|
116
|
+
this.givenState = lodash.default.merge({ ...this.givenState }, newState, mergeCustomizer);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
get when() {
|
|
121
|
+
return {
|
|
122
|
+
...this.whenState,
|
|
123
|
+
merge: (newState) => {
|
|
124
|
+
this.whenState = lodash.default.merge({ ...this.whenState }, newState, mergeCustomizer);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
get then() {
|
|
129
|
+
return {
|
|
130
|
+
...this.thenState,
|
|
131
|
+
merge: (newState) => {
|
|
132
|
+
this.thenState = lodash.default.merge({ ...this.thenState }, newState, mergeCustomizer);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/globFiles.ts
|
|
139
|
+
/** Glob metacharacters. A pattern with none of these is a literal path. */
|
|
140
|
+
const MAGIC = /[*?[\]{}!()]/;
|
|
141
|
+
async function isFile(p) {
|
|
142
|
+
try {
|
|
143
|
+
return (await (0, node_fs_promises.stat)(p)).isFile();
|
|
144
|
+
} catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Resolve glob patterns to a de-duplicated list of absolute file paths, with one
|
|
150
|
+
* important portability guarantee: a **literal absolute path** (no glob magic)
|
|
151
|
+
* is returned directly if it exists, without being handed to `glob()`.
|
|
152
|
+
*
|
|
153
|
+
* This exists because `node:fs`'s `glob` diverges between runtimes — Node
|
|
154
|
+
* matches an absolute-path pattern, Bun returns nothing for one. Rather than
|
|
155
|
+
* depend on that behaviour, we only ever glob relative patterns (against `cwd`)
|
|
156
|
+
* and short-circuit concrete absolute paths ourselves, so callers get identical
|
|
157
|
+
* results under Node and Bun.
|
|
158
|
+
*/
|
|
159
|
+
async function globFiles(patterns, cwd = process.cwd()) {
|
|
160
|
+
const files = /* @__PURE__ */ new Set();
|
|
161
|
+
for (const pattern of patterns) {
|
|
162
|
+
if (node_path.isAbsolute(pattern) && !MAGIC.test(pattern)) {
|
|
163
|
+
if (await isFile(pattern)) files.add(pattern);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
for await (const match of (0, node_fs_promises.glob)(pattern, { cwd })) files.add(node_path.resolve(cwd, match));
|
|
167
|
+
}
|
|
168
|
+
return [...files];
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/analyzer/gherkinParser.ts
|
|
172
|
+
function parseFeatureFiles(filePaths) {
|
|
173
|
+
const scenarios = [];
|
|
174
|
+
for (const filePath of filePaths) {
|
|
175
|
+
const parsed = parseFeatureContent(node_fs.readFileSync(filePath, "utf-8"), filePath);
|
|
176
|
+
scenarios.push(...parsed);
|
|
177
|
+
}
|
|
178
|
+
return scenarios;
|
|
179
|
+
}
|
|
180
|
+
function parseFeatureContent(content, filePath) {
|
|
181
|
+
const feature = new _cucumber_gherkin.Parser(new _cucumber_gherkin.AstBuilder(_cucumber_messages.IdGenerator.uuid()), new _cucumber_gherkin.GherkinClassicTokenMatcher()).parse(content).feature;
|
|
182
|
+
if (!feature) return [];
|
|
183
|
+
const featureBackground = [];
|
|
184
|
+
const scenarios = [];
|
|
185
|
+
const featureTags = tagNames(feature.tags);
|
|
186
|
+
for (const child of feature.children) {
|
|
187
|
+
if (child.background) featureBackground.push(...child.background.steps);
|
|
188
|
+
if (child.scenario) scenarios.push(...expandScenario(child.scenario, featureBackground, filePath, featureTags));
|
|
189
|
+
if (child.rule) {
|
|
190
|
+
const ruleBackground = [...featureBackground];
|
|
191
|
+
const ruleTags = [...featureTags, ...tagNames(child.rule.tags)];
|
|
192
|
+
for (const ruleChild of child.rule.children) {
|
|
193
|
+
if (ruleChild.background) ruleBackground.push(...ruleChild.background.steps);
|
|
194
|
+
if (ruleChild.scenario) scenarios.push(...expandScenario(ruleChild.scenario, ruleBackground, filePath, ruleTags));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return scenarios;
|
|
199
|
+
}
|
|
200
|
+
/** Extract tag names (each keeping its leading `@`), deduped in order. */
|
|
201
|
+
function tagNames(tags) {
|
|
202
|
+
return [...new Set((tags ?? []).map((t) => t.name))];
|
|
203
|
+
}
|
|
204
|
+
function expandScenario(scenario, backgroundSteps, filePath, inheritedTags) {
|
|
205
|
+
const scenarioTags = [...inheritedTags, ...tagNames(scenario.tags)];
|
|
206
|
+
if (!(scenario.examples.length > 0 && scenario.examples.some((e) => e.tableBody.length > 0))) {
|
|
207
|
+
const bgParsed = convertSteps(backgroundSteps);
|
|
208
|
+
const scenarioParsed = convertSteps(scenario.steps);
|
|
209
|
+
const allSteps = resolveEffectiveKeywords([...bgParsed, ...scenarioParsed]);
|
|
210
|
+
return [{
|
|
211
|
+
name: scenario.name,
|
|
212
|
+
file: filePath,
|
|
213
|
+
line: scenario.location.line,
|
|
214
|
+
steps: allSteps,
|
|
215
|
+
tags: scenarioTags
|
|
216
|
+
}];
|
|
217
|
+
}
|
|
218
|
+
const results = [];
|
|
219
|
+
for (const example of scenario.examples) {
|
|
220
|
+
if (!example.tableHeader || example.tableBody.length === 0) continue;
|
|
221
|
+
const headers = example.tableHeader.cells.map((c) => c.value);
|
|
222
|
+
const exampleTags = [...scenarioTags, ...tagNames(example.tags)];
|
|
223
|
+
for (const row of example.tableBody) {
|
|
224
|
+
const values = row.cells.map((c) => c.value);
|
|
225
|
+
const substitution = {};
|
|
226
|
+
headers.forEach((h, i) => {
|
|
227
|
+
substitution[h] = values[i];
|
|
228
|
+
});
|
|
229
|
+
const bgParsed = convertSteps(backgroundSteps);
|
|
230
|
+
const scenarioSteps = convertSteps(scenario.steps).map((step) => ({
|
|
231
|
+
...step,
|
|
232
|
+
text: substituteExampleValues(step.text, substitution)
|
|
233
|
+
}));
|
|
234
|
+
const allSteps = resolveEffectiveKeywords([...bgParsed, ...scenarioSteps]);
|
|
235
|
+
results.push({
|
|
236
|
+
name: headers.map((h, i) => `${h}=${values[i]}`).join(", "),
|
|
237
|
+
file: filePath,
|
|
238
|
+
line: row.location.line,
|
|
239
|
+
steps: allSteps,
|
|
240
|
+
tags: exampleTags,
|
|
241
|
+
outline: { name: scenario.name }
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return results;
|
|
246
|
+
}
|
|
247
|
+
function convertSteps(steps) {
|
|
248
|
+
return steps.map((step) => ({
|
|
249
|
+
keyword: normalizeKeyword(step.keyword),
|
|
250
|
+
text: step.text,
|
|
251
|
+
line: step.location.line,
|
|
252
|
+
column: (step.location.column ?? 1) + step.keyword.length
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
function normalizeKeyword(keyword) {
|
|
256
|
+
const trimmed = keyword.trim();
|
|
257
|
+
if (trimmed === "Given") return "Given";
|
|
258
|
+
if (trimmed === "When") return "When";
|
|
259
|
+
if (trimmed === "Then") return "Then";
|
|
260
|
+
if (trimmed === "And") return "And";
|
|
261
|
+
if (trimmed === "But") return "But";
|
|
262
|
+
return "Given";
|
|
263
|
+
}
|
|
264
|
+
function resolveEffectiveKeywords(steps) {
|
|
265
|
+
let lastEffective = "Given";
|
|
266
|
+
return steps.map((step) => {
|
|
267
|
+
let effectiveKeyword;
|
|
268
|
+
if (step.keyword === "And" || step.keyword === "But") effectiveKeyword = lastEffective;
|
|
269
|
+
else effectiveKeyword = step.keyword;
|
|
270
|
+
lastEffective = effectiveKeyword;
|
|
271
|
+
return {
|
|
272
|
+
...step,
|
|
273
|
+
effectiveKeyword
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function substituteExampleValues(text, substitution) {
|
|
278
|
+
let result = text;
|
|
279
|
+
for (const [key, value] of Object.entries(substitution)) result = result.replace(new RegExp(`<${key}>`, "g"), value);
|
|
280
|
+
return result;
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
Object.defineProperty(exports, "BasicWorld", {
|
|
284
|
+
enumerable: true,
|
|
285
|
+
get: function() {
|
|
286
|
+
return BasicWorld;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
Object.defineProperty(exports, "__toESM", {
|
|
290
|
+
enumerable: true,
|
|
291
|
+
get: function() {
|
|
292
|
+
return __toESM;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
Object.defineProperty(exports, "captureDefinitionSite", {
|
|
296
|
+
enumerable: true,
|
|
297
|
+
get: function() {
|
|
298
|
+
return captureDefinitionSite;
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
Object.defineProperty(exports, "globFiles", {
|
|
302
|
+
enumerable: true,
|
|
303
|
+
get: function() {
|
|
304
|
+
return globFiles;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
Object.defineProperty(exports, "parseFeatureContent", {
|
|
308
|
+
enumerable: true,
|
|
309
|
+
get: function() {
|
|
310
|
+
return parseFeatureContent;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
Object.defineProperty(exports, "parseFeatureFiles", {
|
|
314
|
+
enumerable: true,
|
|
315
|
+
get: function() {
|
|
316
|
+
return parseFeatureFiles;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
Object.defineProperty(exports, "relativeFrame", {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
get: function() {
|
|
322
|
+
return relativeFrame;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
Object.defineProperty(exports, "relativeLocation", {
|
|
326
|
+
enumerable: true,
|
|
327
|
+
get: function() {
|
|
328
|
+
return relativeLocation;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
Object.defineProperty(exports, "userFrames", {
|
|
332
|
+
enumerable: true,
|
|
333
|
+
get: function() {
|
|
334
|
+
return userFrames;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
//# sourceMappingURL=gherkinParser-BT40q_i3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gherkinParser-BT40q_i3.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 { GherkinClassicTokenMatcher, Parser, AstBuilder } 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\nexport function parseFeatureContent(\n content: string,\n filePath: string\n): ParsedScenario[] {\n const newId = messages.IdGenerator.uuid();\n const builder = new AstBuilder(newId);\n const matcher = new GherkinClassicTokenMatcher();\n const parser = new Parser(builder, matcher);\n\n const gherkinDocument: messages.GherkinDocument = parser.parse(content);\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([...bgParsed, ...scenarioSteps]);\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,GAAGA,UAAK,IAAI,cAAcA,UAAK,KAAK;AAEvD;;AAGA,SAAS,WAAW,WAA4C;CAC9D,MAAM,IAAI,sBAAsB,KAAK,SAAS;CAC9C,IAAI,CAAC,GAAG,OAAO,KAAA;CACf,IAAI,OAAO,UAAU,MAAM,GAAG,EAAE,KAAK;CACrC,MAAM,QAAQ,KAAK,YAAY,GAAG;CAClC,IAAI,UAAU,IAAI,OAAO,KAAK,MAAM,QAAQ,CAAC;CAC7C,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,UAAU,EAAE;CACvC,IAAI,KAAK,WAAW,SAAS,GAC3B,IAAI;EACF,QAAA,GAAA,SAAA,cAAA,CAAqB,IAAI;CAC3B,QAAQ;EACN;CACF;CAEF,OAAO;EAAE;EAAM,MAAM,OAAO,EAAE,EAAE;EAAG,QAAQ,OAAO,EAAE,EAAE;CAAE;AAC1D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