@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
package/dist/cli.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.cjs","names":["path","userFrames","relativeFrame","relativeLocation","BasicWorld","path","globFiles","compileRegistry","globalRegistry","parseFeatureFiles","runHooksParallel","globalHookRegistry","runHooks","runScenario","path"],"sources":["../../src/runtime/config.ts","../../src/runtime/filter.ts","../../src/runtime/reporters.ts","../../src/runtime/runner.ts","../../src/runtime/cli.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { access } from \"node:fs/promises\";\n\n/**\n * User-facing runner configuration. The same shape is accepted from a\n * `step-forge.config.ts` file (default export) and from CLI flags, with flags\n * taking precedence. Everything is optional; {@link resolveConfig} fills in\n * defaults.\n */\nexport interface RunnerOptions {\n /** Feature-file glob(s), relative to `cwd`. Defaults to every `.feature` file. */\n features?: string | string[];\n /** Step-module glob(s), relative to `cwd`. Defaults to every `.steps.ts` file. */\n steps?: string | string[];\n /**\n * Module that default-exports a world factory `() => world`, relative to\n * `cwd`. When omitted each scenario gets a fresh `BasicWorld`.\n */\n world?: string;\n /**\n * Max scenarios in flight at once. Defaults to `1` (serial), matching\n * Cucumber's default execution model — scenarios often share module-level\n * state via hooks, which only holds under serial execution. Raise it to opt\n * into parallelism for isolated, I/O-bound suites.\n */\n concurrency?: number;\n /** Reporter name. Default `pretty`. */\n reporter?: \"pretty\" | \"progress\";\n /**\n * Verbose output: report every scenario (pass, fail, skip) instead of only\n * failures. Passed to whichever reporter is active. Default `false`.\n */\n verbose?: boolean;\n /** Only run scenarios whose name matches this (string → substring/regex). */\n name?: string;\n /** Cucumber tag expression, e.g. `@smoke and not @wip`. */\n tags?: string;\n}\n\n/** Fully-resolved config: no optionals, globs kept as arrays, paths absolute. */\nexport interface ResolvedConfig {\n cwd: string;\n features: string[];\n steps: string[];\n world?: string;\n concurrency: number;\n reporter: \"pretty\" | \"progress\";\n verbose: boolean;\n name?: string;\n tags?: string;\n}\n\nconst DEFAULT_FEATURES = \"**/*.feature\";\nconst DEFAULT_STEPS = \"**/*.steps.ts\";\nconst CONFIG_BASENAMES = [\n \"step-forge.config.ts\",\n \"step-forge.config.mts\",\n \"step-forge.config.js\",\n \"step-forge.config.mjs\",\n];\n\nfunction toArray<T>(value: T | T[] | undefined): T[] {\n if (value === undefined) return [];\n return Array.isArray(value) ? value : [value];\n}\n\nasync function exists(p: string): Promise<boolean> {\n try {\n await access(p);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Locate and import a `step-forge.config.*` file from `cwd`, returning its\n * default export (or `{}` if none is present). Imported by absolute file URL so\n * Bun transpiles the TypeScript config natively.\n */\nexport async function loadConfigFile(cwd: string): Promise<RunnerOptions> {\n for (const basename of CONFIG_BASENAMES) {\n const candidate = path.join(cwd, basename);\n if (!(await exists(candidate))) continue;\n const mod = await import(pathToFileURL(candidate).href);\n return (mod.default ?? mod) as RunnerOptions;\n }\n return {};\n}\n\n/**\n * Merge file config with CLI overrides and apply defaults. CLI overrides win\n * field-by-field; array globs are normalised to arrays and default when neither\n * source provides them.\n */\nexport function resolveConfig(\n cwd: string,\n file: RunnerOptions,\n cli: RunnerOptions\n): ResolvedConfig {\n const pick = <K extends keyof RunnerOptions>(key: K): RunnerOptions[K] =>\n cli[key] ?? file[key];\n\n const features = toArray(pick(\"features\"));\n const steps = toArray(pick(\"steps\"));\n\n return {\n cwd,\n features: features.length ? features : [DEFAULT_FEATURES],\n steps: steps.length ? steps : [DEFAULT_STEPS],\n world: pick(\"world\"),\n concurrency: pick(\"concurrency\") ?? 1,\n reporter: pick(\"reporter\") ?? \"pretty\",\n verbose: pick(\"verbose\") ?? false,\n name: pick(\"name\"),\n tags: pick(\"tags\"),\n };\n}\n","import { ParsedScenario } from \"../analyzer/types\";\n\n/**\n * A predicate over a scenario's tags, compiled from a Cucumber tag expression.\n * Supports `and`, `or`, `not`, parentheses, and bare `@tag` atoms — the common\n * subset of Cucumber's tag-expression language. Kept dependency-free; swap for\n * `@cucumber/tag-expressions` if fuller parity is needed.\n */\nexport type TagPredicate = (tags: readonly string[]) => boolean;\n\n/** Tokenise a tag expression into atoms, operators, and parentheses. */\nfunction tokenize(expr: string): string[] {\n const tokens: string[] = [];\n const re = /\\s*(\\(|\\)|@[^\\s()]+|\\band\\b|\\bor\\b|\\bnot\\b)\\s*/gy;\n let index = 0;\n while (index < expr.length) {\n re.lastIndex = index;\n const m = re.exec(expr);\n if (!m || m.index !== index) {\n throw new Error(`Invalid tag expression near: ${expr.slice(index)}`);\n }\n tokens.push(m[1]);\n index = re.lastIndex;\n }\n return tokens;\n}\n\n/**\n * Compile a tag expression into a predicate via recursive descent\n * (or → and → not → primary). Throws on malformed input so a bad `--tags` flag\n * fails loudly rather than silently matching nothing.\n */\nexport function compileTagExpression(expr: string): TagPredicate {\n const tokens = tokenize(expr);\n let pos = 0;\n\n const peek = () => tokens[pos];\n const next = () => tokens[pos++];\n\n const parseOr = (): TagPredicate => {\n let left = parseAnd();\n while (peek() === \"or\") {\n next();\n const right = parseAnd();\n const l = left;\n left = tags => l(tags) || right(tags);\n }\n return left;\n };\n\n const parseAnd = (): TagPredicate => {\n let left = parseNot();\n while (peek() === \"and\") {\n next();\n const right = parseNot();\n const l = left;\n left = tags => l(tags) && right(tags);\n }\n return left;\n };\n\n const parseNot = (): TagPredicate => {\n if (peek() === \"not\") {\n next();\n const operand = parseNot();\n return tags => !operand(tags);\n }\n return parsePrimary();\n };\n\n const parsePrimary = (): TagPredicate => {\n const token = next();\n if (token === \"(\") {\n const inner = parseOr();\n if (next() !== \")\") throw new Error(\"Unbalanced parentheses in tags\");\n return inner;\n }\n if (token === undefined || !token.startsWith(\"@\")) {\n throw new Error(`Expected a tag, got: ${token ?? \"end of input\"}`);\n }\n return tags => tags.includes(token);\n };\n\n const predicate = parseOr();\n if (pos !== tokens.length) {\n throw new Error(`Unexpected token in tag expression: ${peek()}`);\n }\n return predicate;\n}\n\nexport interface SelectOptions {\n /** Substring or `/regex/flags` match against the scenario (or outline) name. */\n name?: string;\n /** Cucumber tag expression. */\n tags?: string;\n}\n\n/** Parse a `/pattern/flags` string into a RegExp, else treat it as a substring. */\nfunction toNameMatcher(name: string): (candidate: string) => boolean {\n const delim = /^\\/(.*)\\/([a-z]*)$/.exec(name);\n if (delim) {\n const re = new RegExp(delim[1], delim[2]);\n return candidate => re.test(candidate);\n }\n return candidate => candidate.includes(name);\n}\n\n/**\n * Narrow scenarios by name and tags, then apply `@only` focus. `@skip` is *not*\n * applied here — skipped scenarios stay in the set so the runner can report them\n * as skipped rather than silently dropping them. Returns scenarios in input\n * order.\n *\n * `@only` semantics mirror the Vitest plugin: if any surviving scenario is\n * tagged `@only` (and not `@skip`), the run is focused to just those.\n */\nexport function selectScenarios(\n scenarios: ParsedScenario[],\n options: SelectOptions\n): ParsedScenario[] {\n let selected = scenarios;\n\n if (options.name) {\n const matches = toNameMatcher(options.name);\n selected = selected.filter(\n s => matches(s.name) || (s.outline ? matches(s.outline.name) : false)\n );\n }\n\n if (options.tags) {\n const predicate = compileTagExpression(options.tags);\n selected = selected.filter(s => predicate(s.tags));\n }\n\n const focused = selected.filter(\n s => s.tags.includes(\"@only\") && !s.tags.includes(\"@skip\")\n );\n return focused.length ? focused : selected;\n}\n","import { relative } from \"node:path\";\nimport { relativeFrame, relativeLocation, userFrames } from \"../sourceLocation\";\nimport { ScenarioResult, StepResult } from \"./engine\";\n\n/**\n * A reporter observes the run. `onScenarioEnd` fires as each scenario finishes\n * (completion order, non-deterministic under concurrency); `onComplete` fires\n * once with every result for the end-of-run output.\n *\n * Every reporter accepts a `verbose` flag: without it a reporter reports only\n * failures (plus a summary); with it, it reports every scenario. A reporter may\n * render the same either way — `verbose` is a request, not a requirement.\n */\nexport interface Reporter {\n onScenarioEnd?(result: ScenarioResult): void;\n onComplete(results: ScenarioResult[], durationMs: number): void;\n}\n\nexport interface ReporterOptions {\n cwd?: string;\n verbose?: boolean;\n}\n\n// --- ANSI colouring -------------------------------------------------------\nconst useColor =\n !process.env.NO_COLOR && (process.stdout.isTTY ?? false) === true;\n\nconst wrap = (open: number, close: number) => (s: string) =>\n useColor ? `\\x1b[${open}m${s}\\x1b[${close}m` : s;\n\nconst c = {\n green: wrap(32, 39),\n red: wrap(31, 39),\n yellow: wrap(33, 39),\n dim: wrap(2, 22),\n bold: wrap(1, 22),\n};\n\nconst STATUS_MARK: Record<StepResult[\"status\"], string> = {\n passed: c.green(\"✓\"),\n failed: c.red(\"✗\"),\n skipped: c.yellow(\"-\"),\n};\n\n/** ✓ / ✗ / - for a whole scenario (skipped = every step skipped). */\nfunction scenarioMark(result: ScenarioResult): string {\n if (result.status === \"failed\") return c.red(\"✗\");\n if (result.steps.every(s => s.status === \"skipped\")) return c.yellow(\"-\");\n return c.green(\"✓\");\n}\n\n/** Dot per scenario for the live heartbeat: `.` pass / `F` fail / `-` skip. */\nfunction scenarioDot(result: ScenarioResult): string {\n if (result.status === \"failed\") return c.red(\"F\");\n if (result.steps.every(s => s.status === \"skipped\")) return c.yellow(\"-\");\n return c.green(\".\");\n}\n\n/** Indent every non-empty line of a block by `pad` spaces. */\nfunction indent(text: string, pad: number): string {\n const prefix = \" \".repeat(pad);\n return text\n .split(\"\\n\")\n .map(line => (line ? prefix + line : line))\n .join(\"\\n\");\n}\n\n/**\n * The error, trimmed to user frames: `Name: message` followed by only the\n * caller's own stack frames (library/engine and `node_modules` frames removed),\n * source-mapped by Bun to the original `.ts`. Falls back to just the message\n * when nothing user-owned is left (e.g. an undefined-step error).\n */\nfunction renderError(error: Error, cwd: string): string {\n const header = `${error.name}: ${error.message}`;\n const frames = userFrames(error.stack).map(\n f => ` at ${relativeFrame(f, cwd)}`\n );\n return frames.length ? `${header}\\n${frames.join(\"\\n\")}` : header;\n}\n\n/**\n * The detail block shown beneath a failing step: the `.feature` line, the step\n * definition location, and the trimmed error — the two coordinates that make a\n * failure easy to chase (where in the feature, which step definition).\n */\nfunction failureDetail(\n stepResult: StepResult,\n result: ScenarioResult,\n cwd: string\n): string {\n const lines = [\n `feature: ${relative(cwd, result.scenario.file)}:${stepResult.step.line}`,\n ];\n if (stepResult.source) {\n lines.push(`defined: ${relativeLocation(stepResult.source, cwd)}`);\n }\n if (stepResult.error) lines.push(renderError(stepResult.error, cwd));\n return indent(c.red(lines.join(\"\\n\")), 6);\n}\n\n/**\n * One scenario as a Cucumber-style block: a marked header with its `.feature`\n * location, then each step with its mark (and, in `verbose`, the step\n * definition location as a trailing comment). A failing step is followed by its\n * failure detail; a scenario-level error (a failing hook, no step to blame) is\n * appended at the end.\n */\nfunction renderScenario(\n result: ScenarioResult,\n cwd: string,\n opts: { stepSource: boolean }\n): string {\n const label = result.scenario.outline\n ? `${result.scenario.outline.name} › ${result.scenario.name}`\n : result.scenario.name;\n const lines: string[] = [`${scenarioMark(result)} ${c.bold(label)}`];\n\n const loc = result.scenario.line\n ? `${relative(cwd, result.scenario.file)}:${result.scenario.line}`\n : relative(cwd, result.scenario.file);\n lines.push(indent(c.dim(loc), 4));\n lines.push(\"\");\n\n for (const step of result.scenario.steps) {\n const sr = result.steps.find(s => s.step === step);\n const status = sr?.status ?? \"skipped\";\n const comment =\n opts.stepSource && sr?.source\n ? c.dim(` # ${relativeLocation(sr.source, cwd)}`)\n : \"\";\n lines.push(\n ` ${STATUS_MARK[status]} ${c.dim(step.effectiveKeyword)} ${step.text}${comment}`\n );\n if (sr?.status === \"failed\") lines.push(failureDetail(sr, result, cwd));\n }\n\n // A hook failure has no failing step; surface its error at scenario level.\n const stepFailed = result.steps.some(s => s.status === \"failed\");\n if (result.error && !stepFailed) {\n lines.push(indent(c.red(renderError(result.error, cwd)), 4));\n }\n\n return lines.join(\"\\n\");\n}\n\n// --- Summary --------------------------------------------------------------\ninterface Totals {\n scenarios: { passed: number; failed: number; skipped: number };\n steps: { passed: number; failed: number; skipped: number };\n}\n\nfunction tally(results: ScenarioResult[]): Totals {\n const totals: Totals = {\n scenarios: { passed: 0, failed: 0, skipped: 0 },\n steps: { passed: 0, failed: 0, skipped: 0 },\n };\n for (const result of results) {\n if (result.status === \"failed\") totals.scenarios.failed++;\n else if (result.steps.every(s => s.status === \"skipped\"))\n totals.scenarios.skipped++;\n else totals.scenarios.passed++;\n for (const step of result.steps) totals.steps[step.status]++;\n }\n return totals;\n}\n\nfunction renderSummary(results: ScenarioResult[], durationMs: number): string {\n const t = tally(results);\n const scenarioTotal =\n t.scenarios.passed + t.scenarios.failed + t.scenarios.skipped;\n const stepTotal = t.steps.passed + t.steps.failed + t.steps.skipped;\n\n const part = (n: number, label: string, color: (s: string) => string) =>\n n > 0 ? color(`${n} ${label}`) : null;\n\n const line = (\n total: number,\n noun: string,\n counts: { passed: number; failed: number; skipped: number }\n ) => {\n const parts = [\n part(counts.passed, \"passed\", c.green),\n part(counts.failed, \"failed\", c.red),\n part(counts.skipped, \"skipped\", c.yellow),\n ].filter((x): x is string => x !== null);\n return `${total} ${noun}${total === 1 ? \"\" : \"s\"} (${parts.join(\", \")})`;\n };\n\n return [\n line(scenarioTotal, \"scenario\", t.scenarios),\n line(stepTotal, \"step\", t.steps),\n c.dim(`${(durationMs / 1000).toFixed(2)}s`),\n ].join(\"\\n\");\n}\n\nfunction write(text: string): void {\n process.stdout.write(text);\n}\n\n/** Feature-grouped tree of every scenario (used by `--verbose`). */\nfunction renderFullTree(results: ScenarioResult[], cwd: string): string {\n const groups = new Map<string, ScenarioResult[]>();\n for (const r of results) {\n const bucket = groups.get(r.scenario.file) ?? [];\n bucket.push(r);\n groups.set(r.scenario.file, bucket);\n }\n const out: string[] = [];\n for (const [file, group] of groups) {\n out.push(c.bold(`Feature: ${relative(cwd, file)}`), \"\");\n for (const r of group)\n out.push(indent(renderScenario(r, cwd, { stepSource: true }), 2), \"\");\n }\n return out.join(\"\\n\");\n}\n\n/** The failing scenarios only (used by the default, non-verbose output). */\nfunction renderFailures(results: ScenarioResult[], cwd: string): string {\n const failed = results.filter(r => r.status === \"failed\");\n if (!failed.length) return \"\";\n return (\n failed\n .map(r => renderScenario(r, cwd, { stepSource: false }))\n .join(\"\\n\\n\") + \"\\n\\n\"\n );\n}\n\n/**\n * Default reporter. Non-verbose: a dot per scenario as a heartbeat, then the\n * failing scenarios in Cucumber-style detail, then the summary. Verbose: the\n * full feature → scenario → step tree instead of just failures.\n */\nexport function prettyReporter(opts: ReporterOptions = {}): Reporter {\n const cwd = opts.cwd ?? process.cwd();\n const verbose = opts.verbose ?? false;\n return {\n onScenarioEnd(result) {\n if (!verbose) write(scenarioDot(result));\n },\n onComplete(results, durationMs) {\n const body = verbose\n ? `\\n${renderFullTree(results, cwd)}\\n`\n : `\\n\\n${renderFailures(results, cwd)}`;\n write(`${body}${renderSummary(results, durationMs)}\\n`);\n },\n };\n}\n\n/**\n * Compact reporter: a dot per scenario, then failures in detail and the\n * summary. Always minimal — `verbose` is accepted for interface parity but does\n * not expand the output (use `pretty --verbose` for the full tree).\n */\nexport function progressReporter(opts: ReporterOptions = {}): Reporter {\n const cwd = opts.cwd ?? process.cwd();\n return {\n onScenarioEnd(result) {\n write(scenarioDot(result));\n },\n onComplete(results, durationMs) {\n write(\n `\\n\\n${renderFailures(results, cwd)}${renderSummary(results, durationMs)}\\n`\n );\n },\n };\n}\n\nexport function makeReporter(\n name: \"pretty\" | \"progress\",\n opts: ReporterOptions = {}\n): Reporter {\n return name === \"progress\" ? progressReporter(opts) : prettyReporter(opts);\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport { ParsedScenario } from \"../analyzer/types\";\nimport { parseFeatureFiles } from \"../analyzer/gherkinParser\";\nimport { globFiles } from \"../globFiles\";\nimport { BasicWorld, MergeableWorld } from \"../world\";\nimport {\n compileRegistry,\n CompiledStep,\n runScenario,\n ScenarioResult,\n} from \"./engine\";\nimport { globalHookRegistry, runHooks, runHooksParallel } from \"./hooks\";\nimport { globalRegistry } from \"./registry\";\nimport { selectScenarios } from \"./filter\";\nimport { makeReporter, Reporter } from \"./reporters\";\nimport { ResolvedConfig } from \"./config\";\n\ntype WorldFactory = () => MergeableWorld<any, any, any>;\n\n/**\n * Import every step-definition module so its `.step(...)` calls self-register\n * into the shared `globalRegistry`. Imported by file URL so Bun transpiles the\n * TypeScript natively.\n */\nasync function importSteps(files: string[]): Promise<void> {\n for (const file of files) {\n await import(pathToFileURL(file).href);\n }\n}\n\n/** Load the configured world factory, or default to a fresh `BasicWorld`. */\nasync function loadWorldFactory(\n world: string | undefined,\n cwd: string\n): Promise<WorldFactory> {\n if (!world) return () => new BasicWorld();\n const resolved = path.resolve(cwd, world);\n const mod = await import(pathToFileURL(resolved).href);\n const factory = mod.default ?? mod;\n if (typeof factory !== \"function\") {\n throw new Error(\n `World module ${world} must default-export a factory function () => world`\n );\n }\n return factory as WorldFactory;\n}\n\n/** A scenario carrying `@skip` never runs: report it with all steps skipped. */\nfunction skippedResult(scenario: ParsedScenario): ScenarioResult {\n return {\n scenario,\n status: \"passed\",\n steps: scenario.steps.map(step => ({ step, status: \"skipped\" as const })),\n };\n}\n\n/**\n * Run `items` through `worker`, at most `limit` in flight. Results come back in\n * input order even though completion order is not deterministic. A minimal\n * dependency-free pool — the whole point of the single-process model.\n */\nasync function runPool<T, R>(\n items: T[],\n limit: number,\n worker: (item: T, index: number) => Promise<R>\n): Promise<R[]> {\n const results = new Array<R>(items.length);\n let cursor = 0;\n const runNext = async (): Promise<void> => {\n while (cursor < items.length) {\n const index = cursor++;\n results[index] = await worker(items[index], index);\n }\n };\n const workers = Array.from(\n { length: Math.min(Math.max(1, limit), items.length) },\n runNext\n );\n await Promise.all(workers);\n return results;\n}\n\nexport interface RunResult {\n results: ScenarioResult[];\n passed: boolean;\n durationMs: number;\n}\n\n/**\n * Execute a whole run end to end: discover and import steps, load the world,\n * parse and select scenarios, then run them concurrently against a\n * compiled-once step table with global/feature hooks around the batch. Never\n * throws for test failures — inspect `RunResult.passed`.\n */\nexport async function run(\n config: ResolvedConfig,\n reporter: Reporter = makeReporter(config.reporter, {\n cwd: config.cwd,\n verbose: config.verbose,\n })\n): Promise<RunResult> {\n const start =\n typeof performance !== \"undefined\" ? performance.now() : Date.now();\n\n const [featureFiles, stepFiles] = await Promise.all([\n globFiles(config.features, config.cwd),\n globFiles(config.steps, config.cwd),\n ]);\n\n await importSteps(stepFiles);\n const makeWorld = await loadWorldFactory(config.world, config.cwd);\n\n const compiled: CompiledStep[] = compileRegistry(globalRegistry);\n const allScenarios = parseFeatureFiles(featureFiles);\n const selected = selectScenarios(allScenarios, {\n name: config.name,\n tags: config.tags,\n });\n\n // Global `beforeAll` hooks run once, in parallel, before any scenario starts;\n // feature before/after bracket the whole batch inside them. (Hooks aren't\n // file-scoped in the registry, so per-file bracketing would be meaningless\n // under concurrent execution.)\n await runHooksParallel(\"global\", \"before\", globalHookRegistry);\n await runHooks(\"feature\", \"before\", globalHookRegistry);\n\n const results = await runPool(\n selected,\n config.concurrency,\n async scenario => {\n const result = scenario.tags.includes(\"@skip\")\n ? skippedResult(scenario)\n : await runScenario(scenario, compiled, makeWorld, globalHookRegistry);\n reporter.onScenarioEnd?.(result);\n return result;\n }\n );\n\n await runHooks(\"feature\", \"after\", globalHookRegistry);\n // Global `afterAll` hooks run once, in parallel, after every scenario is done.\n await runHooksParallel(\"global\", \"after\", globalHookRegistry);\n\n const durationMs =\n (typeof performance !== \"undefined\" ? performance.now() : Date.now()) -\n start;\n reporter.onComplete(results, durationMs);\n\n return {\n results,\n passed: results.every(r => r.status !== \"failed\"),\n durationMs,\n };\n}\n","#!/usr/bin/env bun\nimport { parseArgs } from \"node:util\";\nimport * as path from \"node:path\";\nimport { loadConfigFile, resolveConfig, RunnerOptions } from \"./config\";\nimport { run } from \"./runner\";\n\nconst HELP = `step-forge — native TypeScript runner for Gherkin step definitions\n\nUsage:\n step-forge [options] [feature globs...]\n\nOptions:\n -t, --tags <expr> Tag expression, e.g. \"@smoke and not @wip\"\n -n, --name <pattern> Only scenarios whose name matches (substring or /regex/)\n -s, --steps <glob> Step-definition module glob (repeatable)\n -w, --world <module> World factory module (default export () => world)\n -c, --concurrency <n> Max scenarios in flight (default: 1, i.e. serial)\n -r, --reporter <name> \"pretty\" (default) or \"progress\"\n -v, --verbose Report every scenario, not just failures\n --config <path> Config file directory (default: cwd)\n -h, --help Show this help\n\nPositional arguments are feature globs and override the configured features.\n`;\n\n/** Parse argv into config overrides. Positional args become feature globs. */\nfunction parseCli(argv: string[]): { cwd: string; overrides: RunnerOptions } {\n const { values, positionals } = parseArgs({\n args: argv,\n allowPositionals: true,\n options: {\n tags: { type: \"string\", short: \"t\" },\n name: { type: \"string\", short: \"n\" },\n steps: { type: \"string\", short: \"s\", multiple: true },\n world: { type: \"string\", short: \"w\" },\n concurrency: { type: \"string\", short: \"c\" },\n reporter: { type: \"string\", short: \"r\" },\n verbose: { type: \"boolean\", short: \"v\" },\n config: { type: \"string\" },\n help: { type: \"boolean\", short: \"h\" },\n },\n });\n\n if (values.help) {\n process.stdout.write(HELP);\n process.exit(0);\n }\n\n const overrides: RunnerOptions = {};\n if (positionals.length) overrides.features = positionals;\n if (values.tags) overrides.tags = values.tags;\n if (values.name) overrides.name = values.name;\n if (values.steps) overrides.steps = values.steps;\n if (values.world) overrides.world = values.world;\n if (values.verbose) overrides.verbose = true;\n if (values.reporter) {\n if (values.reporter !== \"pretty\" && values.reporter !== \"progress\") {\n throw new Error(`Unknown reporter: ${values.reporter}`);\n }\n overrides.reporter = values.reporter;\n }\n if (values.concurrency !== undefined) {\n const n = Number(values.concurrency);\n if (!Number.isInteger(n) || n < 1) {\n throw new Error(`--concurrency must be a positive integer`);\n }\n overrides.concurrency = n;\n }\n\n const cwd = values.config\n ? path.resolve(process.cwd(), values.config)\n : process.cwd();\n return { cwd, overrides };\n}\n\nasync function main(): Promise<void> {\n const { cwd, overrides } = parseCli(process.argv.slice(2));\n const fileConfig = await loadConfigFile(cwd);\n const config = resolveConfig(cwd, fileConfig, overrides);\n const { passed } = await run(config);\n process.exitCode = passed ? 0 : 1;\n}\n\nmain().catch(err => {\n process.stderr.write(`${err instanceof Error ? err.stack : String(err)}\\n`);\n process.exitCode = 1;\n});\n"],"mappings":";;;;;;;;;;AAqDA,MAAM,mBAAmB;AACzB,MAAM,gBAAgB;AACtB,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;AACF;AAEA,SAAS,QAAW,OAAiC;CACnD,IAAI,UAAU,KAAA,GAAW,OAAO,CAAC;CACjC,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAC9C;AAEA,eAAe,OAAO,GAA6B;CACjD,IAAI;EACF,OAAA,GAAA,iBAAA,OAAA,CAAa,CAAC;EACd,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;;;;AAOA,eAAsB,eAAe,KAAqC;CACxE,KAAK,MAAM,YAAY,kBAAkB;EACvC,MAAM,YAAYA,UAAK,KAAK,KAAK,QAAQ;EACzC,IAAI,CAAE,MAAM,OAAO,SAAS,GAAI;EAChC,MAAM,MAAM,MAAM,QAAA,GAAA,SAAA,cAAA,CAAqB,SAAS,CAAC,CAAC;EAClD,OAAQ,IAAI,WAAW;CACzB;CACA,OAAO,CAAC;AACV;;;;;;AAOA,SAAgB,cACd,KACA,MACA,KACgB;CAChB,MAAM,QAAuC,QAC3C,IAAI,QAAQ,KAAK;CAEnB,MAAM,WAAW,QAAQ,KAAK,UAAU,CAAC;CACzC,MAAM,QAAQ,QAAQ,KAAK,OAAO,CAAC;CAEnC,OAAO;EACL;EACA,UAAU,SAAS,SAAS,WAAW,CAAC,gBAAgB;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I,OAAO,aAAa,YAAY,OAAO,aAAa,YACtD,MAAM,IAAI,MAAM,qBAAqB,OAAO,UAAU;EAExD,UAAU,WAAW,OAAO;CAC9B;CACA,IAAI,OAAO,gBAAgB,KAAA,GAAW;EACpC,MAAM,IAAI,OAAO,OAAO,WAAW;EACnC,IAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,GAC9B,MAAM,IAAI,MAAM,0CAA0C;EAE5D,UAAU,cAAc;CAC1B;CAKA,OAAO;EAAE,KAHG,OAAO,SACfG,UAAK,QAAQ,QAAQ,IAAI,GAAG,OAAO,MAAM,IACzC,QAAQ,IAAI;EACF;CAAU;AAC1B;AAEA,eAAe,OAAsB;CACnC,MAAM,EAAE,KAAK,cAAc,SAAS,QAAQ,KAAK,MAAM,CAAC,CAAC;CAGzD,MAAM,EAAE,WAAW,MAAM,IADV,cAAc,KAAK,MADT,eAAe,GAAG,GACG,SACZ,CAAC;CACnC,QAAQ,WAAW,SAAS,IAAI;AAClC;AAEA,KAAK,CAAC,CAAC,OAAM,QAAO;CAClB,QAAQ,OAAO,MAAM,GAAG,eAAe,QAAQ,IAAI,QAAQ,OAAO,GAAG,EAAE,GAAG;CAC1E,QAAQ,WAAW;AACrB,CAAC"}
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { i as runHooksParallel, n as globalHookRegistry, o as globalRegistry, r as runHooks } from "./hooks-BDCMKeNq.js";
|
|
3
|
+
import { c as userFrames, i as BasicWorld, n as parseFeatureFiles, o as relativeFrame, r as globFiles, s as relativeLocation } from "./gherkinParser-NcttZgN4.js";
|
|
4
|
+
import { i as runScenario, r as compileRegistry } from "./engine-DPVLEHBi.js";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { relative } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
import { access } from "node:fs/promises";
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
//#region src/runtime/config.ts
|
|
11
|
+
const DEFAULT_FEATURES = "**/*.feature";
|
|
12
|
+
const DEFAULT_STEPS = "**/*.steps.ts";
|
|
13
|
+
const CONFIG_BASENAMES = [
|
|
14
|
+
"step-forge.config.ts",
|
|
15
|
+
"step-forge.config.mts",
|
|
16
|
+
"step-forge.config.js",
|
|
17
|
+
"step-forge.config.mjs"
|
|
18
|
+
];
|
|
19
|
+
function toArray(value) {
|
|
20
|
+
if (value === void 0) return [];
|
|
21
|
+
return Array.isArray(value) ? value : [value];
|
|
22
|
+
}
|
|
23
|
+
async function exists(p) {
|
|
24
|
+
try {
|
|
25
|
+
await access(p);
|
|
26
|
+
return true;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Locate and import a `step-forge.config.*` file from `cwd`, returning its
|
|
33
|
+
* default export (or `{}` if none is present). Imported by absolute file URL so
|
|
34
|
+
* Bun transpiles the TypeScript config natively.
|
|
35
|
+
*/
|
|
36
|
+
async function loadConfigFile(cwd) {
|
|
37
|
+
for (const basename of CONFIG_BASENAMES) {
|
|
38
|
+
const candidate = path.join(cwd, basename);
|
|
39
|
+
if (!await exists(candidate)) continue;
|
|
40
|
+
const mod = await import(pathToFileURL(candidate).href);
|
|
41
|
+
return mod.default ?? mod;
|
|
42
|
+
}
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Merge file config with CLI overrides and apply defaults. CLI overrides win
|
|
47
|
+
* field-by-field; array globs are normalised to arrays and default when neither
|
|
48
|
+
* source provides them.
|
|
49
|
+
*/
|
|
50
|
+
function resolveConfig(cwd, file, cli) {
|
|
51
|
+
const pick = (key) => cli[key] ?? file[key];
|
|
52
|
+
const features = toArray(pick("features"));
|
|
53
|
+
const steps = toArray(pick("steps"));
|
|
54
|
+
return {
|
|
55
|
+
cwd,
|
|
56
|
+
features: features.length ? features : [DEFAULT_FEATURES],
|
|
57
|
+
steps: steps.length ? steps : [DEFAULT_STEPS],
|
|
58
|
+
world: pick("world"),
|
|
59
|
+
concurrency: pick("concurrency") ?? 1,
|
|
60
|
+
reporter: pick("reporter") ?? "pretty",
|
|
61
|
+
verbose: pick("verbose") ?? false,
|
|
62
|
+
name: pick("name"),
|
|
63
|
+
tags: pick("tags")
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/runtime/filter.ts
|
|
68
|
+
/** Tokenise a tag expression into atoms, operators, and parentheses. */
|
|
69
|
+
function tokenize(expr) {
|
|
70
|
+
const tokens = [];
|
|
71
|
+
const re = /\s*(\(|\)|@[^\s()]+|\band\b|\bor\b|\bnot\b)\s*/gy;
|
|
72
|
+
let index = 0;
|
|
73
|
+
while (index < expr.length) {
|
|
74
|
+
re.lastIndex = index;
|
|
75
|
+
const m = re.exec(expr);
|
|
76
|
+
if (!m || m.index !== index) throw new Error(`Invalid tag expression near: ${expr.slice(index)}`);
|
|
77
|
+
tokens.push(m[1]);
|
|
78
|
+
index = re.lastIndex;
|
|
79
|
+
}
|
|
80
|
+
return tokens;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Compile a tag expression into a predicate via recursive descent
|
|
84
|
+
* (or → and → not → primary). Throws on malformed input so a bad `--tags` flag
|
|
85
|
+
* fails loudly rather than silently matching nothing.
|
|
86
|
+
*/
|
|
87
|
+
function compileTagExpression(expr) {
|
|
88
|
+
const tokens = tokenize(expr);
|
|
89
|
+
let pos = 0;
|
|
90
|
+
const peek = () => tokens[pos];
|
|
91
|
+
const next = () => tokens[pos++];
|
|
92
|
+
const parseOr = () => {
|
|
93
|
+
let left = parseAnd();
|
|
94
|
+
while (peek() === "or") {
|
|
95
|
+
next();
|
|
96
|
+
const right = parseAnd();
|
|
97
|
+
const l = left;
|
|
98
|
+
left = (tags) => l(tags) || right(tags);
|
|
99
|
+
}
|
|
100
|
+
return left;
|
|
101
|
+
};
|
|
102
|
+
const parseAnd = () => {
|
|
103
|
+
let left = parseNot();
|
|
104
|
+
while (peek() === "and") {
|
|
105
|
+
next();
|
|
106
|
+
const right = parseNot();
|
|
107
|
+
const l = left;
|
|
108
|
+
left = (tags) => l(tags) && right(tags);
|
|
109
|
+
}
|
|
110
|
+
return left;
|
|
111
|
+
};
|
|
112
|
+
const parseNot = () => {
|
|
113
|
+
if (peek() === "not") {
|
|
114
|
+
next();
|
|
115
|
+
const operand = parseNot();
|
|
116
|
+
return (tags) => !operand(tags);
|
|
117
|
+
}
|
|
118
|
+
return parsePrimary();
|
|
119
|
+
};
|
|
120
|
+
const parsePrimary = () => {
|
|
121
|
+
const token = next();
|
|
122
|
+
if (token === "(") {
|
|
123
|
+
const inner = parseOr();
|
|
124
|
+
if (next() !== ")") throw new Error("Unbalanced parentheses in tags");
|
|
125
|
+
return inner;
|
|
126
|
+
}
|
|
127
|
+
if (token === void 0 || !token.startsWith("@")) throw new Error(`Expected a tag, got: ${token ?? "end of input"}`);
|
|
128
|
+
return (tags) => tags.includes(token);
|
|
129
|
+
};
|
|
130
|
+
const predicate = parseOr();
|
|
131
|
+
if (pos !== tokens.length) throw new Error(`Unexpected token in tag expression: ${peek()}`);
|
|
132
|
+
return predicate;
|
|
133
|
+
}
|
|
134
|
+
/** Parse a `/pattern/flags` string into a RegExp, else treat it as a substring. */
|
|
135
|
+
function toNameMatcher(name) {
|
|
136
|
+
const delim = /^\/(.*)\/([a-z]*)$/.exec(name);
|
|
137
|
+
if (delim) {
|
|
138
|
+
const re = new RegExp(delim[1], delim[2]);
|
|
139
|
+
return (candidate) => re.test(candidate);
|
|
140
|
+
}
|
|
141
|
+
return (candidate) => candidate.includes(name);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Narrow scenarios by name and tags, then apply `@only` focus. `@skip` is *not*
|
|
145
|
+
* applied here — skipped scenarios stay in the set so the runner can report them
|
|
146
|
+
* as skipped rather than silently dropping them. Returns scenarios in input
|
|
147
|
+
* order.
|
|
148
|
+
*
|
|
149
|
+
* `@only` semantics mirror the Vitest plugin: if any surviving scenario is
|
|
150
|
+
* tagged `@only` (and not `@skip`), the run is focused to just those.
|
|
151
|
+
*/
|
|
152
|
+
function selectScenarios(scenarios, options) {
|
|
153
|
+
let selected = scenarios;
|
|
154
|
+
if (options.name) {
|
|
155
|
+
const matches = toNameMatcher(options.name);
|
|
156
|
+
selected = selected.filter((s) => matches(s.name) || (s.outline ? matches(s.outline.name) : false));
|
|
157
|
+
}
|
|
158
|
+
if (options.tags) {
|
|
159
|
+
const predicate = compileTagExpression(options.tags);
|
|
160
|
+
selected = selected.filter((s) => predicate(s.tags));
|
|
161
|
+
}
|
|
162
|
+
const focused = selected.filter((s) => s.tags.includes("@only") && !s.tags.includes("@skip"));
|
|
163
|
+
return focused.length ? focused : selected;
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/runtime/reporters.ts
|
|
167
|
+
const useColor = !process.env.NO_COLOR && (process.stdout.isTTY ?? false) === true;
|
|
168
|
+
const wrap = (open, close) => (s) => useColor ? `\x1b[${open}m${s}\x1b[${close}m` : s;
|
|
169
|
+
const c = {
|
|
170
|
+
green: wrap(32, 39),
|
|
171
|
+
red: wrap(31, 39),
|
|
172
|
+
yellow: wrap(33, 39),
|
|
173
|
+
dim: wrap(2, 22),
|
|
174
|
+
bold: wrap(1, 22)
|
|
175
|
+
};
|
|
176
|
+
const STATUS_MARK = {
|
|
177
|
+
passed: c.green("✓"),
|
|
178
|
+
failed: c.red("✗"),
|
|
179
|
+
skipped: c.yellow("-")
|
|
180
|
+
};
|
|
181
|
+
/** ✓ / ✗ / - for a whole scenario (skipped = every step skipped). */
|
|
182
|
+
function scenarioMark(result) {
|
|
183
|
+
if (result.status === "failed") return c.red("✗");
|
|
184
|
+
if (result.steps.every((s) => s.status === "skipped")) return c.yellow("-");
|
|
185
|
+
return c.green("✓");
|
|
186
|
+
}
|
|
187
|
+
/** Dot per scenario for the live heartbeat: `.` pass / `F` fail / `-` skip. */
|
|
188
|
+
function scenarioDot(result) {
|
|
189
|
+
if (result.status === "failed") return c.red("F");
|
|
190
|
+
if (result.steps.every((s) => s.status === "skipped")) return c.yellow("-");
|
|
191
|
+
return c.green(".");
|
|
192
|
+
}
|
|
193
|
+
/** Indent every non-empty line of a block by `pad` spaces. */
|
|
194
|
+
function indent(text, pad) {
|
|
195
|
+
const prefix = " ".repeat(pad);
|
|
196
|
+
return text.split("\n").map((line) => line ? prefix + line : line).join("\n");
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The error, trimmed to user frames: `Name: message` followed by only the
|
|
200
|
+
* caller's own stack frames (library/engine and `node_modules` frames removed),
|
|
201
|
+
* source-mapped by Bun to the original `.ts`. Falls back to just the message
|
|
202
|
+
* when nothing user-owned is left (e.g. an undefined-step error).
|
|
203
|
+
*/
|
|
204
|
+
function renderError(error, cwd) {
|
|
205
|
+
const header = `${error.name}: ${error.message}`;
|
|
206
|
+
const frames = userFrames(error.stack).map((f) => ` at ${relativeFrame(f, cwd)}`);
|
|
207
|
+
return frames.length ? `${header}\n${frames.join("\n")}` : header;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The detail block shown beneath a failing step: the `.feature` line, the step
|
|
211
|
+
* definition location, and the trimmed error — the two coordinates that make a
|
|
212
|
+
* failure easy to chase (where in the feature, which step definition).
|
|
213
|
+
*/
|
|
214
|
+
function failureDetail(stepResult, result, cwd) {
|
|
215
|
+
const lines = [`feature: ${relative(cwd, result.scenario.file)}:${stepResult.step.line}`];
|
|
216
|
+
if (stepResult.source) lines.push(`defined: ${relativeLocation(stepResult.source, cwd)}`);
|
|
217
|
+
if (stepResult.error) lines.push(renderError(stepResult.error, cwd));
|
|
218
|
+
return indent(c.red(lines.join("\n")), 6);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* One scenario as a Cucumber-style block: a marked header with its `.feature`
|
|
222
|
+
* location, then each step with its mark (and, in `verbose`, the step
|
|
223
|
+
* definition location as a trailing comment). A failing step is followed by its
|
|
224
|
+
* failure detail; a scenario-level error (a failing hook, no step to blame) is
|
|
225
|
+
* appended at the end.
|
|
226
|
+
*/
|
|
227
|
+
function renderScenario(result, cwd, opts) {
|
|
228
|
+
const label = result.scenario.outline ? `${result.scenario.outline.name} › ${result.scenario.name}` : result.scenario.name;
|
|
229
|
+
const lines = [`${scenarioMark(result)} ${c.bold(label)}`];
|
|
230
|
+
const loc = result.scenario.line ? `${relative(cwd, result.scenario.file)}:${result.scenario.line}` : relative(cwd, result.scenario.file);
|
|
231
|
+
lines.push(indent(c.dim(loc), 4));
|
|
232
|
+
lines.push("");
|
|
233
|
+
for (const step of result.scenario.steps) {
|
|
234
|
+
const sr = result.steps.find((s) => s.step === step);
|
|
235
|
+
const status = sr?.status ?? "skipped";
|
|
236
|
+
const comment = opts.stepSource && sr?.source ? c.dim(` # ${relativeLocation(sr.source, cwd)}`) : "";
|
|
237
|
+
lines.push(` ${STATUS_MARK[status]} ${c.dim(step.effectiveKeyword)} ${step.text}${comment}`);
|
|
238
|
+
if (sr?.status === "failed") lines.push(failureDetail(sr, result, cwd));
|
|
239
|
+
}
|
|
240
|
+
const stepFailed = result.steps.some((s) => s.status === "failed");
|
|
241
|
+
if (result.error && !stepFailed) lines.push(indent(c.red(renderError(result.error, cwd)), 4));
|
|
242
|
+
return lines.join("\n");
|
|
243
|
+
}
|
|
244
|
+
function tally(results) {
|
|
245
|
+
const totals = {
|
|
246
|
+
scenarios: {
|
|
247
|
+
passed: 0,
|
|
248
|
+
failed: 0,
|
|
249
|
+
skipped: 0
|
|
250
|
+
},
|
|
251
|
+
steps: {
|
|
252
|
+
passed: 0,
|
|
253
|
+
failed: 0,
|
|
254
|
+
skipped: 0
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
for (const result of results) {
|
|
258
|
+
if (result.status === "failed") totals.scenarios.failed++;
|
|
259
|
+
else if (result.steps.every((s) => s.status === "skipped")) totals.scenarios.skipped++;
|
|
260
|
+
else totals.scenarios.passed++;
|
|
261
|
+
for (const step of result.steps) totals.steps[step.status]++;
|
|
262
|
+
}
|
|
263
|
+
return totals;
|
|
264
|
+
}
|
|
265
|
+
function renderSummary(results, durationMs) {
|
|
266
|
+
const t = tally(results);
|
|
267
|
+
const scenarioTotal = t.scenarios.passed + t.scenarios.failed + t.scenarios.skipped;
|
|
268
|
+
const stepTotal = t.steps.passed + t.steps.failed + t.steps.skipped;
|
|
269
|
+
const part = (n, label, color) => n > 0 ? color(`${n} ${label}`) : null;
|
|
270
|
+
const line = (total, noun, counts) => {
|
|
271
|
+
const parts = [
|
|
272
|
+
part(counts.passed, "passed", c.green),
|
|
273
|
+
part(counts.failed, "failed", c.red),
|
|
274
|
+
part(counts.skipped, "skipped", c.yellow)
|
|
275
|
+
].filter((x) => x !== null);
|
|
276
|
+
return `${total} ${noun}${total === 1 ? "" : "s"} (${parts.join(", ")})`;
|
|
277
|
+
};
|
|
278
|
+
return [
|
|
279
|
+
line(scenarioTotal, "scenario", t.scenarios),
|
|
280
|
+
line(stepTotal, "step", t.steps),
|
|
281
|
+
c.dim(`${(durationMs / 1e3).toFixed(2)}s`)
|
|
282
|
+
].join("\n");
|
|
283
|
+
}
|
|
284
|
+
function write(text) {
|
|
285
|
+
process.stdout.write(text);
|
|
286
|
+
}
|
|
287
|
+
/** Feature-grouped tree of every scenario (used by `--verbose`). */
|
|
288
|
+
function renderFullTree(results, cwd) {
|
|
289
|
+
const groups = /* @__PURE__ */ new Map();
|
|
290
|
+
for (const r of results) {
|
|
291
|
+
const bucket = groups.get(r.scenario.file) ?? [];
|
|
292
|
+
bucket.push(r);
|
|
293
|
+
groups.set(r.scenario.file, bucket);
|
|
294
|
+
}
|
|
295
|
+
const out = [];
|
|
296
|
+
for (const [file, group] of groups) {
|
|
297
|
+
out.push(c.bold(`Feature: ${relative(cwd, file)}`), "");
|
|
298
|
+
for (const r of group) out.push(indent(renderScenario(r, cwd, { stepSource: true }), 2), "");
|
|
299
|
+
}
|
|
300
|
+
return out.join("\n");
|
|
301
|
+
}
|
|
302
|
+
/** The failing scenarios only (used by the default, non-verbose output). */
|
|
303
|
+
function renderFailures(results, cwd) {
|
|
304
|
+
const failed = results.filter((r) => r.status === "failed");
|
|
305
|
+
if (!failed.length) return "";
|
|
306
|
+
return failed.map((r) => renderScenario(r, cwd, { stepSource: false })).join("\n\n") + "\n\n";
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Default reporter. Non-verbose: a dot per scenario as a heartbeat, then the
|
|
310
|
+
* failing scenarios in Cucumber-style detail, then the summary. Verbose: the
|
|
311
|
+
* full feature → scenario → step tree instead of just failures.
|
|
312
|
+
*/
|
|
313
|
+
function prettyReporter(opts = {}) {
|
|
314
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
315
|
+
const verbose = opts.verbose ?? false;
|
|
316
|
+
return {
|
|
317
|
+
onScenarioEnd(result) {
|
|
318
|
+
if (!verbose) write(scenarioDot(result));
|
|
319
|
+
},
|
|
320
|
+
onComplete(results, durationMs) {
|
|
321
|
+
write(`${verbose ? `\n${renderFullTree(results, cwd)}\n` : `\n\n${renderFailures(results, cwd)}`}${renderSummary(results, durationMs)}\n`);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Compact reporter: a dot per scenario, then failures in detail and the
|
|
327
|
+
* summary. Always minimal — `verbose` is accepted for interface parity but does
|
|
328
|
+
* not expand the output (use `pretty --verbose` for the full tree).
|
|
329
|
+
*/
|
|
330
|
+
function progressReporter(opts = {}) {
|
|
331
|
+
const cwd = opts.cwd ?? process.cwd();
|
|
332
|
+
return {
|
|
333
|
+
onScenarioEnd(result) {
|
|
334
|
+
write(scenarioDot(result));
|
|
335
|
+
},
|
|
336
|
+
onComplete(results, durationMs) {
|
|
337
|
+
write(`\n\n${renderFailures(results, cwd)}${renderSummary(results, durationMs)}\n`);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function makeReporter(name, opts = {}) {
|
|
342
|
+
return name === "progress" ? progressReporter(opts) : prettyReporter(opts);
|
|
343
|
+
}
|
|
344
|
+
//#endregion
|
|
345
|
+
//#region src/runtime/runner.ts
|
|
346
|
+
/**
|
|
347
|
+
* Import every step-definition module so its `.step(...)` calls self-register
|
|
348
|
+
* into the shared `globalRegistry`. Imported by file URL so Bun transpiles the
|
|
349
|
+
* TypeScript natively.
|
|
350
|
+
*/
|
|
351
|
+
async function importSteps(files) {
|
|
352
|
+
for (const file of files) await import(pathToFileURL(file).href);
|
|
353
|
+
}
|
|
354
|
+
/** Load the configured world factory, or default to a fresh `BasicWorld`. */
|
|
355
|
+
async function loadWorldFactory(world, cwd) {
|
|
356
|
+
if (!world) return () => new BasicWorld();
|
|
357
|
+
const mod = await import(pathToFileURL(path.resolve(cwd, world)).href);
|
|
358
|
+
const factory = mod.default ?? mod;
|
|
359
|
+
if (typeof factory !== "function") throw new Error(`World module ${world} must default-export a factory function () => world`);
|
|
360
|
+
return factory;
|
|
361
|
+
}
|
|
362
|
+
/** A scenario carrying `@skip` never runs: report it with all steps skipped. */
|
|
363
|
+
function skippedResult(scenario) {
|
|
364
|
+
return {
|
|
365
|
+
scenario,
|
|
366
|
+
status: "passed",
|
|
367
|
+
steps: scenario.steps.map((step) => ({
|
|
368
|
+
step,
|
|
369
|
+
status: "skipped"
|
|
370
|
+
}))
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Run `items` through `worker`, at most `limit` in flight. Results come back in
|
|
375
|
+
* input order even though completion order is not deterministic. A minimal
|
|
376
|
+
* dependency-free pool — the whole point of the single-process model.
|
|
377
|
+
*/
|
|
378
|
+
async function runPool(items, limit, worker) {
|
|
379
|
+
const results = new Array(items.length);
|
|
380
|
+
let cursor = 0;
|
|
381
|
+
const runNext = async () => {
|
|
382
|
+
while (cursor < items.length) {
|
|
383
|
+
const index = cursor++;
|
|
384
|
+
results[index] = await worker(items[index], index);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const workers = Array.from({ length: Math.min(Math.max(1, limit), items.length) }, runNext);
|
|
388
|
+
await Promise.all(workers);
|
|
389
|
+
return results;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Execute a whole run end to end: discover and import steps, load the world,
|
|
393
|
+
* parse and select scenarios, then run them concurrently against a
|
|
394
|
+
* compiled-once step table with global/feature hooks around the batch. Never
|
|
395
|
+
* throws for test failures — inspect `RunResult.passed`.
|
|
396
|
+
*/
|
|
397
|
+
async function run(config, reporter = makeReporter(config.reporter, {
|
|
398
|
+
cwd: config.cwd,
|
|
399
|
+
verbose: config.verbose
|
|
400
|
+
})) {
|
|
401
|
+
const start = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
402
|
+
const [featureFiles, stepFiles] = await Promise.all([globFiles(config.features, config.cwd), globFiles(config.steps, config.cwd)]);
|
|
403
|
+
await importSteps(stepFiles);
|
|
404
|
+
const makeWorld = await loadWorldFactory(config.world, config.cwd);
|
|
405
|
+
const compiled = compileRegistry(globalRegistry);
|
|
406
|
+
const selected = selectScenarios(parseFeatureFiles(featureFiles), {
|
|
407
|
+
name: config.name,
|
|
408
|
+
tags: config.tags
|
|
409
|
+
});
|
|
410
|
+
await runHooksParallel("global", "before", globalHookRegistry);
|
|
411
|
+
await runHooks("feature", "before", globalHookRegistry);
|
|
412
|
+
const results = await runPool(selected, config.concurrency, async (scenario) => {
|
|
413
|
+
const result = scenario.tags.includes("@skip") ? skippedResult(scenario) : await runScenario(scenario, compiled, makeWorld, globalHookRegistry);
|
|
414
|
+
reporter.onScenarioEnd?.(result);
|
|
415
|
+
return result;
|
|
416
|
+
});
|
|
417
|
+
await runHooks("feature", "after", globalHookRegistry);
|
|
418
|
+
await runHooksParallel("global", "after", globalHookRegistry);
|
|
419
|
+
const durationMs = (typeof performance !== "undefined" ? performance.now() : Date.now()) - start;
|
|
420
|
+
reporter.onComplete(results, durationMs);
|
|
421
|
+
return {
|
|
422
|
+
results,
|
|
423
|
+
passed: results.every((r) => r.status !== "failed"),
|
|
424
|
+
durationMs
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
//#endregion
|
|
428
|
+
//#region src/runtime/cli.ts
|
|
429
|
+
const HELP = `step-forge — native TypeScript runner for Gherkin step definitions
|
|
430
|
+
|
|
431
|
+
Usage:
|
|
432
|
+
step-forge [options] [feature globs...]
|
|
433
|
+
|
|
434
|
+
Options:
|
|
435
|
+
-t, --tags <expr> Tag expression, e.g. "@smoke and not @wip"
|
|
436
|
+
-n, --name <pattern> Only scenarios whose name matches (substring or /regex/)
|
|
437
|
+
-s, --steps <glob> Step-definition module glob (repeatable)
|
|
438
|
+
-w, --world <module> World factory module (default export () => world)
|
|
439
|
+
-c, --concurrency <n> Max scenarios in flight (default: 1, i.e. serial)
|
|
440
|
+
-r, --reporter <name> "pretty" (default) or "progress"
|
|
441
|
+
-v, --verbose Report every scenario, not just failures
|
|
442
|
+
--config <path> Config file directory (default: cwd)
|
|
443
|
+
-h, --help Show this help
|
|
444
|
+
|
|
445
|
+
Positional arguments are feature globs and override the configured features.
|
|
446
|
+
`;
|
|
447
|
+
/** Parse argv into config overrides. Positional args become feature globs. */
|
|
448
|
+
function parseCli(argv) {
|
|
449
|
+
const { values, positionals } = parseArgs({
|
|
450
|
+
args: argv,
|
|
451
|
+
allowPositionals: true,
|
|
452
|
+
options: {
|
|
453
|
+
tags: {
|
|
454
|
+
type: "string",
|
|
455
|
+
short: "t"
|
|
456
|
+
},
|
|
457
|
+
name: {
|
|
458
|
+
type: "string",
|
|
459
|
+
short: "n"
|
|
460
|
+
},
|
|
461
|
+
steps: {
|
|
462
|
+
type: "string",
|
|
463
|
+
short: "s",
|
|
464
|
+
multiple: true
|
|
465
|
+
},
|
|
466
|
+
world: {
|
|
467
|
+
type: "string",
|
|
468
|
+
short: "w"
|
|
469
|
+
},
|
|
470
|
+
concurrency: {
|
|
471
|
+
type: "string",
|
|
472
|
+
short: "c"
|
|
473
|
+
},
|
|
474
|
+
reporter: {
|
|
475
|
+
type: "string",
|
|
476
|
+
short: "r"
|
|
477
|
+
},
|
|
478
|
+
verbose: {
|
|
479
|
+
type: "boolean",
|
|
480
|
+
short: "v"
|
|
481
|
+
},
|
|
482
|
+
config: { type: "string" },
|
|
483
|
+
help: {
|
|
484
|
+
type: "boolean",
|
|
485
|
+
short: "h"
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
if (values.help) {
|
|
490
|
+
process.stdout.write(HELP);
|
|
491
|
+
process.exit(0);
|
|
492
|
+
}
|
|
493
|
+
const overrides = {};
|
|
494
|
+
if (positionals.length) overrides.features = positionals;
|
|
495
|
+
if (values.tags) overrides.tags = values.tags;
|
|
496
|
+
if (values.name) overrides.name = values.name;
|
|
497
|
+
if (values.steps) overrides.steps = values.steps;
|
|
498
|
+
if (values.world) overrides.world = values.world;
|
|
499
|
+
if (values.verbose) overrides.verbose = true;
|
|
500
|
+
if (values.reporter) {
|
|
501
|
+
if (values.reporter !== "pretty" && values.reporter !== "progress") throw new Error(`Unknown reporter: ${values.reporter}`);
|
|
502
|
+
overrides.reporter = values.reporter;
|
|
503
|
+
}
|
|
504
|
+
if (values.concurrency !== void 0) {
|
|
505
|
+
const n = Number(values.concurrency);
|
|
506
|
+
if (!Number.isInteger(n) || n < 1) throw new Error(`--concurrency must be a positive integer`);
|
|
507
|
+
overrides.concurrency = n;
|
|
508
|
+
}
|
|
509
|
+
return {
|
|
510
|
+
cwd: values.config ? path.resolve(process.cwd(), values.config) : process.cwd(),
|
|
511
|
+
overrides
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
async function main() {
|
|
515
|
+
const { cwd, overrides } = parseCli(process.argv.slice(2));
|
|
516
|
+
const { passed } = await run(resolveConfig(cwd, await loadConfigFile(cwd), overrides));
|
|
517
|
+
process.exitCode = passed ? 0 : 1;
|
|
518
|
+
}
|
|
519
|
+
main().catch((err) => {
|
|
520
|
+
process.stderr.write(`${err instanceof Error ? err.stack : String(err)}\n`);
|
|
521
|
+
process.exitCode = 1;
|
|
522
|
+
});
|
|
523
|
+
//#endregion
|
|
524
|
+
export {};
|
|
525
|
+
|
|
526
|
+
//# sourceMappingURL=cli.js.map
|