@step-forge/step-forge 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer-QH03uejK.js +478 -0
- package/dist/analyzer-QH03uejK.js.map +1 -0
- package/dist/analyzer-cli.d.ts +1 -0
- package/dist/analyzer-cli.js +69 -0
- package/dist/analyzer-cli.js.map +1 -0
- package/dist/analyzer.d.ts +73 -0
- package/dist/analyzer.js +2 -0
- package/dist/step-forge.cjs +727 -0
- package/dist/step-forge.cjs.map +1 -0
- package/dist/step-forge.d.cts +326 -0
- package/dist/step-forge.d.ts +326 -0
- package/dist/step-forge.js +695 -0
- package/dist/step-forge.js.map +1 -0
- package/package.json +1 -2
- package/.claude/settings.local.json +0 -18
- package/.eslintignore +0 -6
- package/.eslintrc +0 -18
- package/.prettierignore +0 -6
- package/.prettierrc +0 -15
- package/CLAUDE.md +0 -115
- package/cucumber.mjs +0 -39
- package/docs/assets/state_deps.gif +0 -0
- package/features/TESTING.md +0 -100
- package/features/analyzer/analyzer.feature +0 -110
- package/features/analyzer/fixtures/ambiguous-step.feature +0 -5
- package/features/analyzer/fixtures/missing-given-dep.feature +0 -5
- package/features/analyzer/fixtures/missing-multiple-deps.feature +0 -6
- package/features/analyzer/fixtures/missing-when-dep.feature +0 -5
- package/features/analyzer/fixtures/steps.ts +0 -113
- package/features/analyzer/fixtures/undefined-step.feature +0 -5
- package/features/analyzer/fixtures/undefined-with-missing-dep.feature +0 -5
- package/features/analyzer/fixtures/valid-and-but-keywords.feature +0 -8
- package/features/analyzer/fixtures/valid-deps.feature +0 -6
- package/features/analyzer/fixtures/valid-no-deps.feature +0 -6
- package/features/analyzer/fixtures/valid-optional-deps.feature +0 -6
- package/features/analyzer/fixtures/valid-variables.feature +0 -6
- package/features/basic.feature +0 -21
- package/features/exported.feature +0 -6
- package/features/steps/analyzerSteps.ts +0 -67
- package/features/steps/commonSteps.ts +0 -93
- package/features/steps/exportedSteps.ts +0 -42
- package/features/steps/world.ts +0 -29
- package/src/analyzer/cli.ts +0 -96
- package/src/analyzer/gherkinParser.ts +0 -179
- package/src/analyzer/index.ts +0 -89
- package/src/analyzer/rules/ambiguousStepRule.ts +0 -36
- package/src/analyzer/rules/dependencyRule.ts +0 -71
- package/src/analyzer/rules/index.ts +0 -23
- package/src/analyzer/rules/undefinedStepRule.ts +0 -31
- package/src/analyzer/stepExtractor.ts +0 -432
- package/src/analyzer/stepMatcher.ts +0 -85
- package/src/analyzer/types.ts +0 -55
- package/src/builderTypeUtils.ts +0 -27
- package/src/common.ts +0 -138
- package/src/given.ts +0 -102
- package/src/index.ts +0 -46
- package/src/then.ts +0 -128
- package/src/utils.ts +0 -74
- package/src/when.ts +0 -118
- package/src/world.ts +0 -90
- package/test/givenCompilationTests.ts +0 -130
- package/test/testUtils.ts +0 -30
- package/test/thenCompilationTests.ts +0 -207
- package/test/whenCompilationTests.ts +0 -157
- package/ts-node-esm-register.js +0 -8
- package/tsconfig.cucumber.json +0 -14
- package/tsconfig.json +0 -29
- package/tsdown.config.ts +0 -35
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { glob } from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import { AstBuilder, GherkinClassicTokenMatcher, Parser } from "@cucumber/gherkin";
|
|
6
|
+
import * as messages from "@cucumber/messages";
|
|
7
|
+
//#region src/analyzer/stepExtractor.ts
|
|
8
|
+
const BUILDER_NAMES = {
|
|
9
|
+
givenBuilder: "given",
|
|
10
|
+
whenBuilder: "when",
|
|
11
|
+
thenBuilder: "then"
|
|
12
|
+
};
|
|
13
|
+
function extractStepDefinitions(filePaths, tsConfigPath) {
|
|
14
|
+
const configPath = tsConfigPath ?? ts.findConfigFile(process.cwd(), ts.sys.fileExists);
|
|
15
|
+
let compilerOptions = {
|
|
16
|
+
target: ts.ScriptTarget.ESNext,
|
|
17
|
+
module: ts.ModuleKind.ESNext,
|
|
18
|
+
moduleResolution: ts.ModuleResolutionKind.Node10,
|
|
19
|
+
strict: true,
|
|
20
|
+
esModuleInterop: true
|
|
21
|
+
};
|
|
22
|
+
if (configPath) {
|
|
23
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
24
|
+
if (!configFile.error) compilerOptions = ts.parseJsonConfigFileContent(configFile.config, ts.sys, configPath.replace(/[/\\][^/\\]+$/, "")).options;
|
|
25
|
+
}
|
|
26
|
+
compilerOptions.noEmit = true;
|
|
27
|
+
const program = ts.createProgram(filePaths, compilerOptions);
|
|
28
|
+
const checker = program.getTypeChecker();
|
|
29
|
+
const results = [];
|
|
30
|
+
for (const filePath of filePaths) {
|
|
31
|
+
const sourceFile = program.getSourceFile(filePath);
|
|
32
|
+
if (!sourceFile) continue;
|
|
33
|
+
const fileResults = extractFromSourceFile(sourceFile, checker);
|
|
34
|
+
results.push(...fileResults);
|
|
35
|
+
}
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
function extractFromSourceFile(sourceFile, checker) {
|
|
39
|
+
const results = [];
|
|
40
|
+
function visit(node) {
|
|
41
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "register") {
|
|
42
|
+
const meta = extractFromRegisterCall(node, sourceFile, checker);
|
|
43
|
+
if (meta) results.push(meta);
|
|
44
|
+
}
|
|
45
|
+
ts.forEachChild(node, visit);
|
|
46
|
+
}
|
|
47
|
+
visit(sourceFile);
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
function extractFromRegisterCall(registerCall, sourceFile, checker) {
|
|
51
|
+
const chain = collectCallChain(registerCall);
|
|
52
|
+
let stepType = null;
|
|
53
|
+
let expression = null;
|
|
54
|
+
let dependencies = {
|
|
55
|
+
given: {},
|
|
56
|
+
when: {},
|
|
57
|
+
then: {}
|
|
58
|
+
};
|
|
59
|
+
let produces = [];
|
|
60
|
+
for (const link of chain) {
|
|
61
|
+
const name = getCallName(link);
|
|
62
|
+
if (!name) continue;
|
|
63
|
+
if (name === "register") continue;
|
|
64
|
+
if (name === "step") {
|
|
65
|
+
produces = extractProducedKeys(link, checker);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (name === "dependencies") {
|
|
69
|
+
dependencies = extractDependencies(link);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (name === "statement") {
|
|
73
|
+
expression = extractExpression(link);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (BUILDER_NAMES[name]) {
|
|
77
|
+
stepType = BUILDER_NAMES[name];
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!stepType || !expression) {
|
|
82
|
+
const reExport = resolveReExportedCall(chain, checker);
|
|
83
|
+
if (reExport) {
|
|
84
|
+
if (!stepType) stepType = reExport.stepType;
|
|
85
|
+
if (!expression) expression = reExport.expression;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!stepType || !expression) return null;
|
|
89
|
+
const line = sourceFile.getLineAndCharacterOfPosition(registerCall.getStart()).line + 1;
|
|
90
|
+
return {
|
|
91
|
+
stepType,
|
|
92
|
+
expression,
|
|
93
|
+
dependencies,
|
|
94
|
+
produces,
|
|
95
|
+
sourceFile: sourceFile.fileName,
|
|
96
|
+
line
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Collect all call expressions in the method chain, from register() back to the origin.
|
|
101
|
+
*/
|
|
102
|
+
function collectCallChain(call) {
|
|
103
|
+
const chain = [call];
|
|
104
|
+
let current = call.expression;
|
|
105
|
+
while (true) {
|
|
106
|
+
if (ts.isPropertyAccessExpression(current)) current = current.expression;
|
|
107
|
+
if (ts.isCallExpression(current)) {
|
|
108
|
+
chain.push(current);
|
|
109
|
+
current = current.expression;
|
|
110
|
+
} else break;
|
|
111
|
+
}
|
|
112
|
+
return chain;
|
|
113
|
+
}
|
|
114
|
+
function getCallName(call) {
|
|
115
|
+
const expr = call.expression;
|
|
116
|
+
if (ts.isPropertyAccessExpression(expr)) return expr.name.text;
|
|
117
|
+
if (ts.isIdentifier(expr)) return expr.text;
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
function extractExpression(statementCall) {
|
|
121
|
+
const arg = statementCall.arguments[0];
|
|
122
|
+
if (!arg) return null;
|
|
123
|
+
if (ts.isStringLiteral(arg)) return arg.text;
|
|
124
|
+
if (ts.isArrowFunction(arg)) return extractExpressionFromArrowFunction(arg);
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
function extractExpressionFromArrowFunction(fn) {
|
|
128
|
+
const params = fn.parameters.map((p) => p.name.getText());
|
|
129
|
+
let body = fn.body;
|
|
130
|
+
if (ts.isBlock(body)) {
|
|
131
|
+
const returnStmt = body.statements.find(ts.isReturnStatement);
|
|
132
|
+
if (returnStmt?.expression) body = returnStmt.expression;
|
|
133
|
+
else return null;
|
|
134
|
+
}
|
|
135
|
+
if (ts.isTemplateExpression(body)) return reconstructExpressionFromTemplate(body, params);
|
|
136
|
+
if (ts.isNoSubstitutionTemplateLiteral(body)) return body.text;
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
function reconstructExpressionFromTemplate(template, paramNames) {
|
|
140
|
+
let result = template.head.text;
|
|
141
|
+
for (const span of template.templateSpans) {
|
|
142
|
+
if (ts.isIdentifier(span.expression) && paramNames.includes(span.expression.text)) result += "{string}";
|
|
143
|
+
else result += "{string}";
|
|
144
|
+
result += span.literal.text;
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
function extractDependencies(depsCall) {
|
|
149
|
+
const deps = {
|
|
150
|
+
given: {},
|
|
151
|
+
when: {},
|
|
152
|
+
then: {}
|
|
153
|
+
};
|
|
154
|
+
const arg = depsCall.arguments[0];
|
|
155
|
+
if (!arg || !ts.isObjectLiteralExpression(arg)) return deps;
|
|
156
|
+
for (const prop of arg.properties) {
|
|
157
|
+
if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name)) continue;
|
|
158
|
+
const phase = prop.name.text;
|
|
159
|
+
if (!deps[phase]) continue;
|
|
160
|
+
if (ts.isObjectLiteralExpression(prop.initializer)) {
|
|
161
|
+
for (const innerProp of prop.initializer.properties) if (ts.isPropertyAssignment(innerProp) && ts.isIdentifier(innerProp.name) && ts.isStringLiteral(innerProp.initializer)) {
|
|
162
|
+
const val = innerProp.initializer.text;
|
|
163
|
+
if (val === "required" || val === "optional") deps[phase][innerProp.name.text] = val;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return deps;
|
|
168
|
+
}
|
|
169
|
+
function extractProducedKeys(stepCall, checker) {
|
|
170
|
+
const callback = stepCall.arguments[0];
|
|
171
|
+
if (!callback) return [];
|
|
172
|
+
if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) return extractProducedKeysFromCallback(callback, checker);
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
function extractProducedKeysFromCallback(callback, checker) {
|
|
176
|
+
const body = callback.body;
|
|
177
|
+
if (!ts.isBlock(body)) return extractKeysFromExpression(body, checker);
|
|
178
|
+
const keys = /* @__PURE__ */ new Set();
|
|
179
|
+
function visitReturn(node) {
|
|
180
|
+
if (ts.isReturnStatement(node) && node.expression) for (const key of extractKeysFromExpression(node.expression, checker)) keys.add(key);
|
|
181
|
+
ts.forEachChild(node, visitReturn);
|
|
182
|
+
}
|
|
183
|
+
visitReturn(body);
|
|
184
|
+
return [...keys];
|
|
185
|
+
}
|
|
186
|
+
function extractKeysFromExpression(expr, checker) {
|
|
187
|
+
while (ts.isParenthesizedExpression(expr)) expr = expr.expression;
|
|
188
|
+
if (ts.isObjectLiteralExpression(expr)) return expr.properties.filter((p) => ts.isPropertyAssignment(p) || ts.isShorthandPropertyAssignment(p)).map((p) => p.name.getText()).filter(Boolean);
|
|
189
|
+
try {
|
|
190
|
+
return checker.getTypeAtLocation(expr).getProperties().map((p) => p.name).filter((n) => n !== "merge");
|
|
191
|
+
} catch {
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function resolveReExportedCall(chain, checker) {
|
|
196
|
+
const lastCall = chain[chain.length - 1];
|
|
197
|
+
if (!lastCall) return null;
|
|
198
|
+
const expr = lastCall.expression;
|
|
199
|
+
let identifier = null;
|
|
200
|
+
if (ts.isIdentifier(expr)) identifier = expr;
|
|
201
|
+
else if (ts.isPropertyAccessExpression(expr) && ts.isIdentifier(expr.expression)) identifier = expr.expression;
|
|
202
|
+
if (!identifier) return null;
|
|
203
|
+
const symbol = checker.getSymbolAtLocation(identifier);
|
|
204
|
+
if (!symbol) return null;
|
|
205
|
+
const decl = symbol.valueDeclaration;
|
|
206
|
+
if (!decl || !ts.isVariableDeclaration(decl) || !decl.initializer) return null;
|
|
207
|
+
const init = decl.initializer;
|
|
208
|
+
if (ts.isPropertyAccessExpression(init) && init.name.text === "statement") {
|
|
209
|
+
const callExpr = init.expression;
|
|
210
|
+
if (ts.isCallExpression(callExpr)) {
|
|
211
|
+
const callee = callExpr.expression;
|
|
212
|
+
if (ts.isIdentifier(callee) && BUILDER_NAMES[callee.text]) {
|
|
213
|
+
const expression = extractExpression(lastCall);
|
|
214
|
+
return {
|
|
215
|
+
stepType: BUILDER_NAMES[callee.text],
|
|
216
|
+
expression
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/analyzer/gherkinParser.ts
|
|
225
|
+
function parseFeatureFiles(filePaths) {
|
|
226
|
+
const scenarios = [];
|
|
227
|
+
for (const filePath of filePaths) {
|
|
228
|
+
const parsed = parseFeatureContent(fs.readFileSync(filePath, "utf-8"), filePath);
|
|
229
|
+
scenarios.push(...parsed);
|
|
230
|
+
}
|
|
231
|
+
return scenarios;
|
|
232
|
+
}
|
|
233
|
+
function parseFeatureContent(content, filePath) {
|
|
234
|
+
const feature = new Parser(new AstBuilder(messages.IdGenerator.uuid()), new GherkinClassicTokenMatcher()).parse(content).feature;
|
|
235
|
+
if (!feature) return [];
|
|
236
|
+
const featureBackground = [];
|
|
237
|
+
const scenarios = [];
|
|
238
|
+
for (const child of feature.children) {
|
|
239
|
+
if (child.background) featureBackground.push(...child.background.steps);
|
|
240
|
+
if (child.scenario) scenarios.push(...expandScenario(child.scenario, featureBackground, filePath));
|
|
241
|
+
if (child.rule) {
|
|
242
|
+
const ruleBackground = [...featureBackground];
|
|
243
|
+
for (const ruleChild of child.rule.children) {
|
|
244
|
+
if (ruleChild.background) ruleBackground.push(...ruleChild.background.steps);
|
|
245
|
+
if (ruleChild.scenario) scenarios.push(...expandScenario(ruleChild.scenario, ruleBackground, filePath));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return scenarios;
|
|
250
|
+
}
|
|
251
|
+
function expandScenario(scenario, backgroundSteps, filePath) {
|
|
252
|
+
if (!(scenario.examples.length > 0 && scenario.examples.some((e) => e.tableBody.length > 0))) {
|
|
253
|
+
const bgParsed = convertSteps(backgroundSteps);
|
|
254
|
+
const scenarioParsed = convertSteps(scenario.steps);
|
|
255
|
+
const allSteps = resolveEffectiveKeywords([...bgParsed, ...scenarioParsed]);
|
|
256
|
+
return [{
|
|
257
|
+
name: scenario.name,
|
|
258
|
+
file: filePath,
|
|
259
|
+
steps: allSteps
|
|
260
|
+
}];
|
|
261
|
+
}
|
|
262
|
+
const results = [];
|
|
263
|
+
for (const example of scenario.examples) {
|
|
264
|
+
if (!example.tableHeader || example.tableBody.length === 0) continue;
|
|
265
|
+
const headers = example.tableHeader.cells.map((c) => c.value);
|
|
266
|
+
for (const row of example.tableBody) {
|
|
267
|
+
const values = row.cells.map((c) => c.value);
|
|
268
|
+
const substitution = {};
|
|
269
|
+
headers.forEach((h, i) => {
|
|
270
|
+
substitution[h] = values[i];
|
|
271
|
+
});
|
|
272
|
+
const bgParsed = convertSteps(backgroundSteps);
|
|
273
|
+
const scenarioSteps = convertSteps(scenario.steps).map((step) => ({
|
|
274
|
+
...step,
|
|
275
|
+
text: substituteExampleValues(step.text, substitution)
|
|
276
|
+
}));
|
|
277
|
+
const allSteps = resolveEffectiveKeywords([...bgParsed, ...scenarioSteps]);
|
|
278
|
+
results.push({
|
|
279
|
+
name: `${scenario.name} (${values.join(", ")})`,
|
|
280
|
+
file: filePath,
|
|
281
|
+
steps: allSteps
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return results;
|
|
286
|
+
}
|
|
287
|
+
function convertSteps(steps) {
|
|
288
|
+
return steps.map((step) => ({
|
|
289
|
+
keyword: normalizeKeyword(step.keyword),
|
|
290
|
+
text: step.text,
|
|
291
|
+
line: step.location.line,
|
|
292
|
+
column: (step.location.column ?? 1) + step.keyword.length
|
|
293
|
+
}));
|
|
294
|
+
}
|
|
295
|
+
function normalizeKeyword(keyword) {
|
|
296
|
+
const trimmed = keyword.trim();
|
|
297
|
+
if (trimmed === "Given") return "Given";
|
|
298
|
+
if (trimmed === "When") return "When";
|
|
299
|
+
if (trimmed === "Then") return "Then";
|
|
300
|
+
if (trimmed === "And") return "And";
|
|
301
|
+
if (trimmed === "But") return "But";
|
|
302
|
+
return "Given";
|
|
303
|
+
}
|
|
304
|
+
function resolveEffectiveKeywords(steps) {
|
|
305
|
+
let lastEffective = "Given";
|
|
306
|
+
return steps.map((step) => {
|
|
307
|
+
let effectiveKeyword;
|
|
308
|
+
if (step.keyword === "And" || step.keyword === "But") effectiveKeyword = lastEffective;
|
|
309
|
+
else effectiveKeyword = step.keyword;
|
|
310
|
+
lastEffective = effectiveKeyword;
|
|
311
|
+
return {
|
|
312
|
+
...step,
|
|
313
|
+
effectiveKeyword
|
|
314
|
+
};
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function substituteExampleValues(text, substitution) {
|
|
318
|
+
let result = text;
|
|
319
|
+
for (const [key, value] of Object.entries(substitution)) result = result.replace(new RegExp(`<${key}>`, "g"), value);
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/analyzer/stepMatcher.ts
|
|
324
|
+
function compileDefinitions(definitions) {
|
|
325
|
+
const compiled = [];
|
|
326
|
+
for (const def of definitions) try {
|
|
327
|
+
const placeholder = "###PLACEHOLDER###";
|
|
328
|
+
const regexStr = def.expression.replace(/\{[^}]+\}/g, placeholder).replace(/[.*+?^$()|[\]\\]/g, "\\$&").replace(new RegExp(placeholder, "g"), "(.+)");
|
|
329
|
+
compiled.push({
|
|
330
|
+
regex: new RegExp(`^${regexStr}$`, "i"),
|
|
331
|
+
definition: def
|
|
332
|
+
});
|
|
333
|
+
} catch {}
|
|
334
|
+
return compiled;
|
|
335
|
+
}
|
|
336
|
+
function matchScenarioSteps(scenario, definitions) {
|
|
337
|
+
const compiled = compileDefinitions(definitions);
|
|
338
|
+
return scenario.steps.map((step) => {
|
|
339
|
+
const matches = findMatches(step.text, step.effectiveKeyword, compiled);
|
|
340
|
+
return {
|
|
341
|
+
...step,
|
|
342
|
+
definitions: matches
|
|
343
|
+
};
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function findMatchingDefinitions(text, effectiveKeyword, definitions) {
|
|
347
|
+
return findMatches(text, effectiveKeyword, compileDefinitions(definitions));
|
|
348
|
+
}
|
|
349
|
+
function findMatches(text, effectiveKeyword, compiled) {
|
|
350
|
+
const expectedStepType = {
|
|
351
|
+
Given: "given",
|
|
352
|
+
When: "when",
|
|
353
|
+
Then: "then"
|
|
354
|
+
}[effectiveKeyword];
|
|
355
|
+
const typedMatches = [];
|
|
356
|
+
for (const { regex, definition } of compiled) {
|
|
357
|
+
if (definition.stepType !== expectedStepType) continue;
|
|
358
|
+
if (regex.test(text)) typedMatches.push(definition);
|
|
359
|
+
}
|
|
360
|
+
if (typedMatches.length > 0) return typedMatches;
|
|
361
|
+
const fallbackMatches = [];
|
|
362
|
+
for (const { regex, definition } of compiled) if (regex.test(text)) fallbackMatches.push(definition);
|
|
363
|
+
return fallbackMatches;
|
|
364
|
+
}
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/analyzer/rules/index.ts
|
|
367
|
+
const defaultRules = [
|
|
368
|
+
{
|
|
369
|
+
name: "undefined-step",
|
|
370
|
+
check(scenario, matchedSteps) {
|
|
371
|
+
return matchedSteps.filter((step) => step.definitions.length === 0).map((step) => ({
|
|
372
|
+
file: scenario.file,
|
|
373
|
+
range: {
|
|
374
|
+
startLine: step.line,
|
|
375
|
+
startColumn: step.column,
|
|
376
|
+
endLine: step.line,
|
|
377
|
+
endColumn: step.column + step.text.length
|
|
378
|
+
},
|
|
379
|
+
severity: "error",
|
|
380
|
+
message: `Step "${step.text}" does not match any step definition`,
|
|
381
|
+
rule: "undefined-step",
|
|
382
|
+
source: "step-forge"
|
|
383
|
+
}));
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: "ambiguous-step",
|
|
388
|
+
check(scenario, matchedSteps) {
|
|
389
|
+
return matchedSteps.filter((step) => step.definitions.length > 1).map((step) => {
|
|
390
|
+
const locations = step.definitions.map((d) => `${d.sourceFile}:${d.line}`).join(", ");
|
|
391
|
+
return {
|
|
392
|
+
file: scenario.file,
|
|
393
|
+
range: {
|
|
394
|
+
startLine: step.line,
|
|
395
|
+
startColumn: step.column,
|
|
396
|
+
endLine: step.line,
|
|
397
|
+
endColumn: step.column + step.text.length
|
|
398
|
+
},
|
|
399
|
+
severity: "error",
|
|
400
|
+
message: `Step "${step.text}" matches multiple step definitions: ${locations}`,
|
|
401
|
+
rule: "ambiguous-step",
|
|
402
|
+
source: "step-forge"
|
|
403
|
+
};
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
name: "dependency-check",
|
|
409
|
+
check(scenario, matchedSteps) {
|
|
410
|
+
const diagnostics = [];
|
|
411
|
+
const produced = {
|
|
412
|
+
given: /* @__PURE__ */ new Set(),
|
|
413
|
+
when: /* @__PURE__ */ new Set(),
|
|
414
|
+
then: /* @__PURE__ */ new Set()
|
|
415
|
+
};
|
|
416
|
+
for (const step of matchedSteps) {
|
|
417
|
+
if (step.definitions.length !== 1) continue;
|
|
418
|
+
const { dependencies, produces, stepType } = step.definitions[0];
|
|
419
|
+
const missing = {};
|
|
420
|
+
for (const phase of [
|
|
421
|
+
"given",
|
|
422
|
+
"when",
|
|
423
|
+
"then"
|
|
424
|
+
]) for (const [key, requirement] of Object.entries(dependencies[phase])) if (requirement === "required" && !produced[phase].has(key)) {
|
|
425
|
+
if (!missing[phase]) missing[phase] = [];
|
|
426
|
+
missing[phase].push(key);
|
|
427
|
+
}
|
|
428
|
+
if (Object.keys(missing).length > 0) {
|
|
429
|
+
const message = "Missing required dependencies:\n" + Object.entries(missing).map(([phase, keys]) => `${phase.charAt(0).toUpperCase() + phase.slice(1)}: ${keys.map((k) => `${phase}.${k}`).join(", ")}`).join("\n");
|
|
430
|
+
diagnostics.push({
|
|
431
|
+
file: scenario.file,
|
|
432
|
+
range: {
|
|
433
|
+
startLine: step.line,
|
|
434
|
+
startColumn: step.column,
|
|
435
|
+
endLine: step.line,
|
|
436
|
+
endColumn: step.column + step.text.length
|
|
437
|
+
},
|
|
438
|
+
severity: "error",
|
|
439
|
+
message,
|
|
440
|
+
rule: "dependency-check",
|
|
441
|
+
source: "step-forge"
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
for (const key of produces) produced[stepType].add(key);
|
|
445
|
+
}
|
|
446
|
+
return diagnostics;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
];
|
|
450
|
+
function runRules(rules, scenario, matchedSteps) {
|
|
451
|
+
return rules.flatMap((rule) => rule.check(scenario, matchedSteps));
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/analyzer/index.ts
|
|
455
|
+
async function analyze(config, options) {
|
|
456
|
+
const rules = options?.rules ?? defaultRules;
|
|
457
|
+
const stepFilePaths = await resolveGlobs(config.stepFiles);
|
|
458
|
+
const featureFilePaths = await resolveGlobs(config.featureFiles);
|
|
459
|
+
if (stepFilePaths.length === 0) return [];
|
|
460
|
+
if (featureFilePaths.length === 0) return [];
|
|
461
|
+
const stepDefinitions = extractStepDefinitions(stepFilePaths, config.tsConfigPath);
|
|
462
|
+
const scenarios = parseFeatureFiles(featureFilePaths);
|
|
463
|
+
const diagnostics = [];
|
|
464
|
+
for (const scenario of scenarios) {
|
|
465
|
+
const scenarioDiags = runRules(rules, scenario, matchScenarioSteps(scenario, stepDefinitions));
|
|
466
|
+
diagnostics.push(...scenarioDiags);
|
|
467
|
+
}
|
|
468
|
+
return diagnostics;
|
|
469
|
+
}
|
|
470
|
+
async function resolveGlobs(patterns) {
|
|
471
|
+
const files = [];
|
|
472
|
+
for (const pattern of patterns) for await (const file of glob(pattern)) files.push(path.resolve(file));
|
|
473
|
+
return [...new Set(files)];
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
export { parseFeatureContent as a, matchScenarioSteps as i, defaultRules as n, parseFeatureFiles as o, findMatchingDefinitions as r, extractStepDefinitions as s, analyze as t };
|
|
477
|
+
|
|
478
|
+
//# sourceMappingURL=analyzer-QH03uejK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer-QH03uejK.js","names":[],"sources":["../../src/analyzer/stepExtractor.ts","../../src/analyzer/gherkinParser.ts","../../src/analyzer/stepMatcher.ts","../../src/analyzer/rules/ambiguousStepRule.ts","../../src/analyzer/rules/dependencyRule.ts","../../src/analyzer/rules/undefinedStepRule.ts","../../src/analyzer/rules/index.ts","../../src/analyzer/index.ts"],"sourcesContent":["import ts from \"typescript\";\nimport { StepDefinitionMeta } from \"./types.js\";\n\ntype StepType = \"given\" | \"when\" | \"then\";\n\nconst BUILDER_NAMES: Record<string, StepType> = {\n givenBuilder: \"given\",\n whenBuilder: \"when\",\n thenBuilder: \"then\",\n};\n\nexport function extractStepDefinitions(\n filePaths: string[],\n tsConfigPath?: string\n): StepDefinitionMeta[] {\n const configPath =\n tsConfigPath ?? ts.findConfigFile(process.cwd(), ts.sys.fileExists);\n let compilerOptions: ts.CompilerOptions = {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.Node10,\n strict: true,\n esModuleInterop: true,\n };\n\n if (configPath) {\n const configFile = ts.readConfigFile(configPath, ts.sys.readFile);\n if (!configFile.error) {\n const parsed = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n configPath.replace(/[/\\\\][^/\\\\]+$/, \"\")\n );\n compilerOptions = parsed.options;\n }\n }\n\n // Ensure noEmit so we don't write files\n compilerOptions.noEmit = true;\n\n const program = ts.createProgram(filePaths, compilerOptions);\n const checker = program.getTypeChecker();\n const results: StepDefinitionMeta[] = [];\n\n for (const filePath of filePaths) {\n const sourceFile = program.getSourceFile(filePath);\n if (!sourceFile) continue;\n const fileResults = extractFromSourceFile(sourceFile, checker);\n results.push(...fileResults);\n }\n\n return results;\n}\n\nfunction extractFromSourceFile(\n sourceFile: ts.SourceFile,\n checker: ts.TypeChecker\n): StepDefinitionMeta[] {\n const results: StepDefinitionMeta[] = [];\n\n function visit(node: ts.Node) {\n // Look for .register() call expressions\n if (\n ts.isCallExpression(node) &&\n ts.isPropertyAccessExpression(node.expression) &&\n node.expression.name.text === \"register\"\n ) {\n const meta = extractFromRegisterCall(node, sourceFile, checker);\n if (meta) {\n results.push(meta);\n }\n }\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n return results;\n}\n\nfunction extractFromRegisterCall(\n registerCall: ts.CallExpression,\n sourceFile: ts.SourceFile,\n checker: ts.TypeChecker\n): StepDefinitionMeta | null {\n // Walk backwards through the method chain to find all parts\n // Pattern: builder().statement(...).dependencies?(...).step(...).register()\n // Or: Variable(\"...\").dependencies?(...).step(...).register()\n\n const chain = collectCallChain(registerCall);\n\n let stepType: StepType | null = null;\n let expression: string | null = null;\n let dependencies: StepDefinitionMeta[\"dependencies\"] = {\n given: {},\n when: {},\n then: {},\n };\n let produces: string[] = [];\n\n for (const link of chain) {\n const name = getCallName(link);\n if (!name) continue;\n\n if (name === \"register\") {\n // Already at register, continue\n continue;\n }\n\n if (name === \"step\") {\n produces = extractProducedKeys(link, checker);\n continue;\n }\n\n if (name === \"dependencies\") {\n dependencies = extractDependencies(link);\n continue;\n }\n\n if (name === \"statement\") {\n expression = extractExpression(link);\n // Try to find the builder type by continuing up the chain\n continue;\n }\n\n // Check if this is a builder call like givenBuilder()\n if (BUILDER_NAMES[name]) {\n stepType = BUILDER_NAMES[name];\n continue;\n }\n }\n\n // If we didn't find the builder or expression in the chain, try the \"re-exported\" pattern:\n // const Given = givenBuilder<T>().statement;\n // Given(\"foo\").step(...).register()\n if (!stepType || !expression) {\n const reExport = resolveReExportedCall(chain, checker);\n if (reExport) {\n if (!stepType) stepType = reExport.stepType;\n if (!expression) expression = reExport.expression;\n }\n }\n\n if (!stepType || !expression) {\n return null;\n }\n\n const line =\n sourceFile.getLineAndCharacterOfPosition(registerCall.getStart()).line + 1;\n\n return {\n stepType,\n expression,\n dependencies,\n produces,\n sourceFile: sourceFile.fileName,\n line,\n };\n}\n\n/**\n * Collect all call expressions in the method chain, from register() back to the origin.\n */\nfunction collectCallChain(call: ts.CallExpression): ts.CallExpression[] {\n const chain: ts.CallExpression[] = [call];\n let current: ts.Expression = call.expression;\n\n while (true) {\n // Walk through PropertyAccessExpression to find the next call\n if (ts.isPropertyAccessExpression(current)) {\n current = current.expression;\n }\n\n if (ts.isCallExpression(current)) {\n chain.push(current);\n current = current.expression;\n } else {\n break;\n }\n }\n\n return chain;\n}\n\nfunction getCallName(call: ts.CallExpression): string | null {\n const expr = call.expression;\n\n // .method() pattern\n if (ts.isPropertyAccessExpression(expr)) {\n return expr.name.text;\n }\n\n // direct call: functionName()\n if (ts.isIdentifier(expr)) {\n return expr.text;\n }\n\n return null;\n}\n\nfunction extractExpression(statementCall: ts.CallExpression): string | null {\n const arg = statementCall.arguments[0];\n if (!arg) return null;\n\n // String literal: .statement(\"a user\")\n if (ts.isStringLiteral(arg)) {\n return arg.text;\n }\n\n // Arrow function with template literal: .statement((name: string) => `a user named ${name}`)\n if (ts.isArrowFunction(arg)) {\n return extractExpressionFromArrowFunction(arg);\n }\n\n return null;\n}\n\nfunction extractExpressionFromArrowFunction(\n fn: ts.ArrowFunction\n): string | null {\n const params = fn.parameters.map((p) => p.name.getText());\n\n // The body should be a template expression or string literal\n let body = fn.body;\n\n // If wrapped in a block with a return, unwrap\n if (ts.isBlock(body)) {\n const returnStmt = body.statements.find(ts.isReturnStatement);\n if (returnStmt?.expression) {\n body = returnStmt.expression;\n } else {\n return null;\n }\n }\n\n if (ts.isTemplateExpression(body)) {\n return reconstructExpressionFromTemplate(body, params);\n }\n\n if (ts.isNoSubstitutionTemplateLiteral(body)) {\n return body.text;\n }\n\n return null;\n}\n\nfunction reconstructExpressionFromTemplate(\n template: ts.TemplateExpression,\n paramNames: string[]\n): string {\n let result = template.head.text;\n\n for (const span of template.templateSpans) {\n if (ts.isIdentifier(span.expression) && paramNames.includes(span.expression.text)) {\n result += \"{string}\";\n } else {\n // Non-parameter expression, use {string} as fallback\n result += \"{string}\";\n }\n result += span.literal.text;\n }\n\n return result;\n}\n\nfunction extractDependencies(\n depsCall: ts.CallExpression\n): StepDefinitionMeta[\"dependencies\"] {\n const deps: StepDefinitionMeta[\"dependencies\"] = {\n given: {},\n when: {},\n then: {},\n };\n\n const arg = depsCall.arguments[0];\n if (!arg || !ts.isObjectLiteralExpression(arg)) return deps;\n\n for (const prop of arg.properties) {\n if (!ts.isPropertyAssignment(prop) || !ts.isIdentifier(prop.name))\n continue;\n\n const phase = prop.name.text as \"given\" | \"when\" | \"then\";\n if (!deps[phase]) continue;\n\n if (ts.isObjectLiteralExpression(prop.initializer)) {\n for (const innerProp of prop.initializer.properties) {\n if (\n ts.isPropertyAssignment(innerProp) &&\n ts.isIdentifier(innerProp.name) &&\n ts.isStringLiteral(innerProp.initializer)\n ) {\n const val = innerProp.initializer.text;\n if (val === \"required\" || val === \"optional\") {\n deps[phase][innerProp.name.text] = val;\n }\n }\n }\n }\n }\n\n return deps;\n}\n\nfunction extractProducedKeys(\n stepCall: ts.CallExpression,\n checker: ts.TypeChecker\n): string[] {\n const callback = stepCall.arguments[0];\n if (!callback) return [];\n\n // Try to get the return type of the callback by analyzing its body\n if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) {\n return extractProducedKeysFromCallback(callback, checker);\n }\n\n return [];\n}\n\nfunction extractProducedKeysFromCallback(\n callback: ts.ArrowFunction | ts.FunctionExpression,\n checker: ts.TypeChecker\n): string[] {\n const body = callback.body;\n\n // Concise arrow: () => ({ key: value })\n if (!ts.isBlock(body)) {\n return extractKeysFromExpression(body, checker);\n }\n\n // Block body: look at return statements\n const keys = new Set<string>();\n function visitReturn(node: ts.Node) {\n if (ts.isReturnStatement(node) && node.expression) {\n for (const key of extractKeysFromExpression(node.expression, checker)) {\n keys.add(key);\n }\n }\n ts.forEachChild(node, visitReturn);\n }\n visitReturn(body);\n return [...keys];\n}\n\nfunction extractKeysFromExpression(\n expr: ts.Expression,\n checker: ts.TypeChecker\n): string[] {\n // Unwrap parenthesized expressions\n while (ts.isParenthesizedExpression(expr)) {\n expr = expr.expression;\n }\n\n // Object literal: { user: ..., token: ... }\n if (ts.isObjectLiteralExpression(expr)) {\n return expr.properties\n .filter(\n (p): p is ts.PropertyAssignment | ts.ShorthandPropertyAssignment =>\n ts.isPropertyAssignment(p) || ts.isShorthandPropertyAssignment(p)\n )\n .map((p) => p.name.getText())\n .filter(Boolean);\n }\n\n // Try type checker as fallback\n try {\n const type = checker.getTypeAtLocation(expr);\n return type\n .getProperties()\n .map((p) => p.name)\n .filter((n) => n !== \"merge\");\n } catch {\n return [];\n }\n}\n\ninterface ReExportResult {\n stepType: StepType;\n expression: string | null;\n}\n\nfunction resolveReExportedCall(\n chain: ts.CallExpression[],\n checker: ts.TypeChecker\n): ReExportResult | null {\n // Look for the pattern: Variable(\"...\")... where Variable was assigned from builderType().statement\n // The last call in the chain (furthest from register) should be the variable call\n\n const lastCall = chain[chain.length - 1];\n if (!lastCall) return null;\n\n const expr = lastCall.expression;\n\n // If it's an identifier (like \"Given\", \"When\", \"Then\"), trace its declaration\n let identifier: ts.Identifier | null = null;\n if (ts.isIdentifier(expr)) {\n identifier = expr;\n } else if (\n ts.isPropertyAccessExpression(expr) &&\n ts.isIdentifier(expr.expression)\n ) {\n identifier = expr.expression;\n }\n\n if (!identifier) return null;\n\n const symbol = checker.getSymbolAtLocation(identifier);\n if (!symbol) return null;\n\n const decl = symbol.valueDeclaration;\n if (!decl || !ts.isVariableDeclaration(decl) || !decl.initializer)\n return null;\n\n // Check if initializer is builderType<T>().statement\n const init = decl.initializer;\n\n // Pattern: givenBuilder<T>().statement (PropertyAccessExpression)\n if (ts.isPropertyAccessExpression(init) && init.name.text === \"statement\") {\n const callExpr = init.expression;\n if (ts.isCallExpression(callExpr)) {\n const callee = callExpr.expression;\n if (ts.isIdentifier(callee) && BUILDER_NAMES[callee.text]) {\n // The lastCall IS the statement call — extract expression from it\n const expression = extractExpression(lastCall);\n return {\n stepType: BUILDER_NAMES[callee.text],\n expression,\n };\n }\n }\n }\n\n return null;\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\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(child.scenario, featureBackground, filePath)\n );\n }\n\n if (child.rule) {\n // Rules can have their own backgrounds\n const ruleBackground: messages.Step[] = [...featureBackground];\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(ruleChild.scenario, ruleBackground, filePath)\n );\n }\n }\n }\n }\n\n return scenarios;\n}\n\nfunction expandScenario(\n scenario: messages.Scenario,\n backgroundSteps: messages.Step[],\n filePath: string\n): ParsedScenario[] {\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 steps: allSteps,\n },\n ];\n }\n\n // Scenario Outline — expand with each example row\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\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: `${scenario.name} (${values.join(\", \")})`,\n file: filePath,\n steps: allSteps,\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","import { MatchedStep, ParsedScenario, StepDefinitionMeta } from \"./types.js\";\n\ninterface CompiledPattern {\n regex: RegExp;\n definition: StepDefinitionMeta;\n}\n\nfunction compileDefinitions(\n definitions: StepDefinitionMeta[]\n): CompiledPattern[] {\n const compiled: CompiledPattern[] = [];\n for (const def of definitions) {\n try {\n // Replace {paramType} placeholders with (.+) to match any value,\n // matching the Step Forge runtime behavior where all params use {string}\n // and values are coerced at runtime via typeCoercer.\n const placeholder = \"###PLACEHOLDER###\";\n const regexStr = def.expression\n .replace(/\\{[^}]+\\}/g, placeholder)\n .replace(/[.*+?^$()|[\\]\\\\]/g, \"\\\\$&\")\n .replace(new RegExp(placeholder, \"g\"), \"(.+)\");\n compiled.push({\n regex: new RegExp(`^${regexStr}$`, \"i\"),\n definition: def,\n });\n } catch {\n // Skip definitions with invalid expressions\n }\n }\n return compiled;\n}\n\nexport function matchScenarioSteps(\n scenario: ParsedScenario,\n definitions: StepDefinitionMeta[]\n): MatchedStep[] {\n const compiled = compileDefinitions(definitions);\n\n return scenario.steps.map((step) => {\n const matches = findMatches(step.text, step.effectiveKeyword, compiled);\n return {\n ...step,\n definitions: matches,\n };\n });\n}\n\nexport function findMatchingDefinitions(\n text: string,\n effectiveKeyword: \"Given\" | \"When\" | \"Then\",\n definitions: StepDefinitionMeta[]\n): StepDefinitionMeta[] {\n const compiled = compileDefinitions(definitions);\n return findMatches(text, effectiveKeyword, compiled);\n}\n\nfunction findMatches(\n text: string,\n effectiveKeyword: \"Given\" | \"When\" | \"Then\",\n compiled: CompiledPattern[]\n): StepDefinitionMeta[] {\n const keywordToStepType: Record<string, string> = {\n Given: \"given\",\n When: \"when\",\n Then: \"then\",\n };\n const expectedStepType = keywordToStepType[effectiveKeyword];\n\n // First try to match with the correct step type\n const typedMatches: StepDefinitionMeta[] = [];\n for (const { regex, definition } of compiled) {\n if (definition.stepType !== expectedStepType) continue;\n if (regex.test(text)) typedMatches.push(definition);\n }\n\n if (typedMatches.length > 0) return typedMatches;\n\n // Fallback: match any step type\n const fallbackMatches: StepDefinitionMeta[] = [];\n for (const { regex, definition } of compiled) {\n if (regex.test(text)) fallbackMatches.push(definition);\n }\n\n return fallbackMatches;\n}\n","import {\n AnalysisRule,\n Diagnostic,\n MatchedStep,\n ParsedScenario,\n} from \"../types.js\";\n\nexport const ambiguousStepRule: AnalysisRule = {\n name: \"ambiguous-step\",\n\n check(\n scenario: ParsedScenario,\n matchedSteps: MatchedStep[]\n ): Diagnostic[] {\n return matchedSteps\n .filter((step) => step.definitions.length > 1)\n .map((step) => {\n const locations = step.definitions\n .map((d) => `${d.sourceFile}:${d.line}`)\n .join(\", \");\n return {\n file: scenario.file,\n range: {\n startLine: step.line,\n startColumn: step.column,\n endLine: step.line,\n endColumn: step.column + step.text.length,\n },\n severity: \"error\" as const,\n message: `Step \"${step.text}\" matches multiple step definitions: ${locations}`,\n rule: \"ambiguous-step\",\n source: \"step-forge\" as const,\n };\n });\n },\n};\n","import {\n AnalysisRule,\n Diagnostic,\n MatchedStep,\n ParsedScenario,\n} from \"../types.js\";\n\nexport const dependencyRule: AnalysisRule = {\n name: \"dependency-check\",\n\n check(\n scenario: ParsedScenario,\n matchedSteps: MatchedStep[]\n ): Diagnostic[] {\n const diagnostics: Diagnostic[] = [];\n const produced = {\n given: new Set<string>(),\n when: new Set<string>(),\n then: new Set<string>(),\n };\n\n for (const step of matchedSteps) {\n if (step.definitions.length !== 1) continue;\n\n const { dependencies, produces, stepType } = step.definitions[0];\n\n // Collect all missing required dependencies for this step\n const missing: Record<string, string[]> = {};\n for (const phase of [\"given\", \"when\", \"then\"] as const) {\n for (const [key, requirement] of Object.entries(dependencies[phase])) {\n if (requirement === \"required\" && !produced[phase].has(key)) {\n if (!missing[phase]) {\n missing[phase] = [];\n }\n missing[phase].push(key);\n }\n }\n }\n\n if (Object.keys(missing).length > 0) {\n const lines = Object.entries(missing).map(\n ([phase, keys]) =>\n `${phase.charAt(0).toUpperCase() + phase.slice(1)}: ${keys.map((k) => `${phase}.${k}`).join(\", \")}`\n );\n const message =\n \"Missing required dependencies:\\n\" + lines.join(\"\\n\");\n\n diagnostics.push({\n file: scenario.file,\n range: {\n startLine: step.line,\n startColumn: step.column,\n endLine: step.line,\n endColumn: step.column + step.text.length,\n },\n severity: \"error\",\n message,\n rule: \"dependency-check\",\n source: \"step-forge\",\n });\n }\n\n // Add produced keys for this step\n for (const key of produces) {\n produced[stepType].add(key);\n }\n }\n\n return diagnostics;\n },\n};\n","import {\n AnalysisRule,\n Diagnostic,\n MatchedStep,\n ParsedScenario,\n} from \"../types.js\";\n\nexport const undefinedStepRule: AnalysisRule = {\n name: \"undefined-step\",\n\n check(\n scenario: ParsedScenario,\n matchedSteps: MatchedStep[]\n ): Diagnostic[] {\n return matchedSteps\n .filter((step) => step.definitions.length === 0)\n .map((step) => ({\n file: scenario.file,\n range: {\n startLine: step.line,\n startColumn: step.column,\n endLine: step.line,\n endColumn: step.column + step.text.length,\n },\n severity: \"error\" as const,\n message: `Step \"${step.text}\" does not match any step definition`,\n rule: \"undefined-step\",\n source: \"step-forge\" as const,\n }));\n },\n};\n","import {\n AnalysisRule,\n Diagnostic,\n MatchedStep,\n ParsedScenario,\n} from \"../types.js\";\nimport { ambiguousStepRule } from \"./ambiguousStepRule.js\";\nimport { dependencyRule } from \"./dependencyRule.js\";\nimport { undefinedStepRule } from \"./undefinedStepRule.js\";\n\nexport const defaultRules: AnalysisRule[] = [\n undefinedStepRule,\n ambiguousStepRule,\n dependencyRule,\n];\n\nexport function runRules(\n rules: AnalysisRule[],\n scenario: ParsedScenario,\n matchedSteps: MatchedStep[]\n): Diagnostic[] {\n return rules.flatMap((rule) => rule.check(scenario, matchedSteps));\n}\n","import { glob } from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { extractStepDefinitions } from \"./stepExtractor.js\";\nimport { parseFeatureFiles, parseFeatureContent } from \"./gherkinParser.js\";\nimport {\n matchScenarioSteps,\n findMatchingDefinitions,\n} from \"./stepMatcher.js\";\nimport { defaultRules, runRules } from \"./rules/index.js\";\nimport type {\n AnalyzerConfig,\n AnalysisRule,\n Diagnostic,\n StepDefinitionMeta,\n ParsedScenario,\n MatchedStep,\n ParsedStep,\n} from \"./types.js\";\n\nexport type {\n AnalyzerConfig,\n AnalysisRule,\n Diagnostic,\n StepDefinitionMeta,\n ParsedScenario,\n MatchedStep,\n ParsedStep,\n};\n\nexport {\n extractStepDefinitions,\n parseFeatureFiles,\n parseFeatureContent,\n matchScenarioSteps,\n findMatchingDefinitions,\n defaultRules,\n};\n\nexport interface AnalyzeOptions {\n rules?: AnalysisRule[];\n}\n\nexport async function analyze(\n config: AnalyzerConfig,\n options?: AnalyzeOptions\n): Promise<Diagnostic[]> {\n const rules = options?.rules ?? defaultRules;\n\n // 1. Resolve file globs to paths\n const stepFilePaths = await resolveGlobs(config.stepFiles);\n const featureFilePaths = await resolveGlobs(config.featureFiles);\n\n if (stepFilePaths.length === 0) {\n return [];\n }\n if (featureFilePaths.length === 0) {\n return [];\n }\n\n // 2. Extract step metadata from step files\n const stepDefinitions = extractStepDefinitions(\n stepFilePaths,\n config.tsConfigPath\n );\n\n // 3. Parse feature files\n const scenarios = parseFeatureFiles(featureFilePaths);\n\n // 4. For each scenario, match steps and run rules\n const diagnostics: Diagnostic[] = [];\n for (const scenario of scenarios) {\n const matchedSteps = matchScenarioSteps(scenario, stepDefinitions);\n const scenarioDiags = runRules(rules, scenario, matchedSteps);\n diagnostics.push(...scenarioDiags);\n }\n\n return diagnostics;\n}\n\nasync function resolveGlobs(patterns: string[]): Promise<string[]> {\n const files: string[] = [];\n for (const pattern of patterns) {\n for await (const file of glob(pattern)) {\n files.push(path.resolve(file));\n }\n }\n // Deduplicate\n return [...new Set(files)];\n}\n"],"mappings":";;;;;;;AAKA,MAAM,gBAA0C;CAC9C,cAAc;CACd,aAAa;CACb,aAAa;AACf;AAEA,SAAgB,uBACd,WACA,cACsB;CACtB,MAAM,aACJ,gBAAgB,GAAG,eAAe,QAAQ,IAAI,GAAG,GAAG,IAAI,U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AAC,GAAG,IAAI,IAAI,KAAK,CAAC;AAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as analyze } from "./analyzer-QH03uejK.js";
|
|
3
|
+
//#region src/analyzer/cli.ts
|
|
4
|
+
function parseArgs(args) {
|
|
5
|
+
const config = {
|
|
6
|
+
stepFiles: [],
|
|
7
|
+
featureFiles: []
|
|
8
|
+
};
|
|
9
|
+
for (let i = 0; i < args.length; i++) {
|
|
10
|
+
const arg = args[i];
|
|
11
|
+
const next = args[i + 1];
|
|
12
|
+
if ((arg === "--steps" || arg === "-s") && next) {
|
|
13
|
+
config.stepFiles.push(next);
|
|
14
|
+
i++;
|
|
15
|
+
} else if ((arg === "--features" || arg === "-f") && next) {
|
|
16
|
+
config.featureFiles.push(next);
|
|
17
|
+
i++;
|
|
18
|
+
} else if (arg === "--tsconfig" && next) {
|
|
19
|
+
config.tsConfigPath = next;
|
|
20
|
+
i++;
|
|
21
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
22
|
+
printUsage();
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
function printUsage() {
|
|
29
|
+
console.log(`Usage: step-forge-analyze [options]
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
-s, --steps <glob> Glob pattern for step definition files (repeatable)
|
|
33
|
+
-f, --features <glob> Glob pattern for feature files (repeatable)
|
|
34
|
+
--tsconfig <path> Path to tsconfig.json (default: auto-detect)
|
|
35
|
+
-h, --help Show this help message
|
|
36
|
+
|
|
37
|
+
Example:
|
|
38
|
+
step-forge-analyze --steps "features/steps/**/*.ts" --features "features/**/*.feature"
|
|
39
|
+
`);
|
|
40
|
+
}
|
|
41
|
+
function formatDiagnostic(diag) {
|
|
42
|
+
return `${`${diag.file}:${diag.range.startLine}:${diag.range.startColumn}`} - ${diag.severity}: ${diag.message}`;
|
|
43
|
+
}
|
|
44
|
+
async function main() {
|
|
45
|
+
const config = parseArgs(process.argv.slice(2));
|
|
46
|
+
if (config.stepFiles.length === 0 || config.featureFiles.length === 0) {
|
|
47
|
+
console.error("Error: Both --steps and --features are required.\n");
|
|
48
|
+
printUsage();
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const diagnostics = await analyze(config);
|
|
52
|
+
if (diagnostics.length === 0) {
|
|
53
|
+
console.log("No issues found.");
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
const errors = diagnostics.filter((d) => d.severity === "error");
|
|
57
|
+
const warnings = diagnostics.filter((d) => d.severity === "warning");
|
|
58
|
+
for (const diag of diagnostics) console.log(formatDiagnostic(diag));
|
|
59
|
+
console.log(`\nFound ${errors.length} error(s) and ${warnings.length} warning(s).`);
|
|
60
|
+
process.exit(errors.length > 0 ? 1 : 0);
|
|
61
|
+
}
|
|
62
|
+
if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("analyzer-cli.js") || process.argv[1]?.endsWith("analyzer-cli.ts")) main().catch((err) => {
|
|
63
|
+
console.error("Analyzer failed:", err);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
});
|
|
66
|
+
//#endregion
|
|
67
|
+
export {};
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=analyzer-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzer-cli.js","names":[],"sources":["../../src/analyzer/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { analyze } from \"./index.js\";\nimport type { AnalyzerConfig, Diagnostic } from \"./types.js\";\n\nfunction parseArgs(args: string[]): AnalyzerConfig {\n const config: AnalyzerConfig = {\n stepFiles: [],\n featureFiles: [],\n };\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n const next = args[i + 1];\n\n if ((arg === \"--steps\" || arg === \"-s\") && next) {\n config.stepFiles.push(next);\n i++;\n } else if ((arg === \"--features\" || arg === \"-f\") && next) {\n config.featureFiles.push(next);\n i++;\n } else if (arg === \"--tsconfig\" && next) {\n config.tsConfigPath = next;\n i++;\n } else if (arg === \"--help\" || arg === \"-h\") {\n printUsage();\n process.exit(0);\n }\n }\n\n return config;\n}\n\nfunction printUsage() {\n console.log(`Usage: step-forge-analyze [options]\n\nOptions:\n -s, --steps <glob> Glob pattern for step definition files (repeatable)\n -f, --features <glob> Glob pattern for feature files (repeatable)\n --tsconfig <path> Path to tsconfig.json (default: auto-detect)\n -h, --help Show this help message\n\nExample:\n step-forge-analyze --steps \"features/steps/**/*.ts\" --features \"features/**/*.feature\"\n`);\n}\n\nfunction formatDiagnostic(diag: Diagnostic): string {\n const location = `${diag.file}:${diag.range.startLine}:${diag.range.startColumn}`;\n return `${location} - ${diag.severity}: ${diag.message}`;\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n const config = parseArgs(args);\n\n if (config.stepFiles.length === 0 || config.featureFiles.length === 0) {\n console.error(\n \"Error: Both --steps and --features are required.\\n\"\n );\n printUsage();\n process.exit(1);\n }\n\n const diagnostics = await analyze(config);\n\n if (diagnostics.length === 0) {\n console.log(\"No issues found.\");\n process.exit(0);\n }\n\n const errors = diagnostics.filter((d) => d.severity === \"error\");\n const warnings = diagnostics.filter((d) => d.severity === \"warning\");\n\n for (const diag of diagnostics) {\n console.log(formatDiagnostic(diag));\n }\n\n console.log(\n `\\nFound ${errors.length} error(s) and ${warnings.length} warning(s).`\n );\n process.exit(errors.length > 0 ? 1 : 0);\n}\n\n// Only run when invoked directly (not when imported by Cucumber or other tools)\nconst isDirectRun =\n import.meta.url === `file://${process.argv[1]}` ||\n process.argv[1]?.endsWith(\"analyzer-cli.js\") ||\n process.argv[1]?.endsWith(\"analyzer-cli.ts\");\n\nif (isDirectRun) {\n main().catch((err) => {\n console.error(\"Analyzer failed:\", err);\n process.exit(1);\n });\n}\n"],"mappings":";;;AAKA,SAAS,UAAU,M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