@step-forge/step-forge 0.0.20 → 0.0.21

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/vitest.d.ts DELETED
@@ -1,74 +0,0 @@
1
- //#region src/runtime/vitest.d.ts
2
- interface StepForgeOptions {
3
- /**
4
- * Globs (relative to the Vite root) for step-definition modules.
5
- * Defaults to `**​/*.steps.ts`.
6
- */
7
- steps?: string | string[];
8
- /**
9
- * Module that default-exports a world factory `() => world`, resolved
10
- * relative to the Vite root. When omitted, each scenario gets a fresh
11
- * `BasicWorld`.
12
- */
13
- world?: string;
14
- /**
15
- * Feature-file glob(s) to register as test files. Defaults to
16
- * `**​/*.feature`. Accepts an array to scope several exact files or patterns
17
- * (e.g. running real features while excluding analyzer fixtures).
18
- */
19
- features?: string | string[];
20
- /**
21
- * Advanced: module specifier the generated tests import the runtime from.
22
- * Defaults to the published `@step-forge/step-forge/runtime` entry; override
23
- * only when consuming the library from source (e.g. this repo's own tests).
24
- */
25
- runtimeModule?: string;
26
- /**
27
- * Advanced: module specifier for the library core (used for the default
28
- * `BasicWorld`). Defaults to `@step-forge/step-forge`.
29
- */
30
- coreModule?: string;
31
- }
32
- /** Minimal Vite plugin shape (avoids a hard dependency on vite's types). */
33
- interface VitePlugin {
34
- name: string;
35
- enforce?: "pre" | "post";
36
- config?: () => unknown;
37
- configResolved?: (config: {
38
- root: string;
39
- }) => void;
40
- transform?: (code: string, id: string) => Promise<{
41
- code: string;
42
- map: null;
43
- } | undefined>;
44
- }
45
- /**
46
- * Vite/Vitest plugin: compiles each `.feature` file into a test module so
47
- * scenarios show up as native Vitest tests (watch mode, --ui, per-scenario
48
- * tasks, the lot). The transform injects imports of the step modules so that
49
- * (a) steps self-register into the same registry the engine reads, and
50
- * (b) Vite's HMR graph invalidates the feature test when a step file changes.
51
- */
52
- declare function stepForge(options?: StepForgeOptions): VitePlugin;
53
- /**
54
- * One-line Vitest config preset. Drop this in `vitest.config.ts`:
55
- *
56
- * ```ts
57
- * import { defineStepForgeConfig } from "@step-forge/step-forge/vitest";
58
- * export default defineStepForgeConfig({ world: "./support/world.ts" });
59
- * ```
60
- *
61
- * Runs `**​/*.feature` as native tests, auto-discovers `**​/*.steps.ts`, and
62
- * defaults the world to `BasicWorld`. Override any Vitest option via `test`.
63
- */
64
- declare function defineStepForgeConfig(options?: StepForgeOptions & {
65
- test?: Record<string, unknown>;
66
- }): {
67
- plugins: VitePlugin[];
68
- test: {
69
- include: string[];
70
- };
71
- };
72
- //#endregion
73
- export { StepForgeOptions, defineStepForgeConfig, stepForge };
74
- //# sourceMappingURL=vitest.d.ts.map
package/dist/vitest.js DELETED
@@ -1,136 +0,0 @@
1
- import { t as parseFeatureContent } from "./gherkinParser-Dp2d7JNr.js";
2
- import { glob } from "node:fs/promises";
3
- import * as path from "node:path";
4
- //#region src/runtime/vitest.ts
5
- const DEFAULT_STEPS = "**/*.steps.ts";
6
- const DEFAULT_FEATURES = "**/*.feature";
7
- const DEFAULT_RUNTIME_MODULE = "@step-forge/step-forge/runtime";
8
- const DEFAULT_CORE_MODULE = "@step-forge/step-forge";
9
- function toArray(value) {
10
- return Array.isArray(value) ? value : [value];
11
- }
12
- /**
13
- * Map a scenario's Gherkin tags onto the Vitest test variant. `@skip` wins over
14
- * `@only` (a scenario explicitly skipped stays skipped even if also `@only`ed),
15
- * and everything else is a plain `test`.
16
- */
17
- function testFn(tags) {
18
- if (tags.includes("@skip")) return "test.skip";
19
- if (tags.includes("@only")) return "test.only";
20
- return "test";
21
- }
22
- /** One `runScenario` test line for the scenario at `__scenarios[index]`. */
23
- function testLine(scenario, index, indent) {
24
- return `${indent}${testFn(scenario.tags)}(${JSON.stringify(scenario.name)}, () => runScenario(__scenarios[${index}], globalRegistry, __makeWorld));`;
25
- }
26
- /**
27
- * Emit the test bodies for a feature. Plain scenarios become one `test` each;
28
- * consecutive rows expanded from the same `Scenario Outline` are wrapped in a
29
- * `describe` named after the outline, so they read as one labelled group with a
30
- * `test` per example row (and each row keeps its own `@skip`/`@only`).
31
- */
32
- function generateTests(scenarios) {
33
- const lines = [];
34
- let i = 0;
35
- while (i < scenarios.length) {
36
- const outlineName = scenarios[i].outline?.name;
37
- if (outlineName === void 0) {
38
- lines.push(testLine(scenarios[i], i, " "));
39
- i += 1;
40
- continue;
41
- }
42
- lines.push(` describe(${JSON.stringify(outlineName)}, () => {`);
43
- while (i < scenarios.length && scenarios[i].outline?.name === outlineName) {
44
- lines.push(testLine(scenarios[i], i, " "));
45
- i += 1;
46
- }
47
- lines.push(` });`);
48
- }
49
- return lines.join("\n");
50
- }
51
- function toSpecifier(p) {
52
- return path.isAbsolute(p) ? p.split(path.sep).join("/") : p;
53
- }
54
- async function resolveSteps(steps, root) {
55
- const patterns = Array.isArray(steps) ? steps : [steps];
56
- const files = /* @__PURE__ */ new Set();
57
- for (const pattern of patterns) for await (const file of glob(pattern, { cwd: root })) files.add(path.resolve(root, file));
58
- return [...files];
59
- }
60
- /**
61
- * Vite/Vitest plugin: compiles each `.feature` file into a test module so
62
- * scenarios show up as native Vitest tests (watch mode, --ui, per-scenario
63
- * tasks, the lot). The transform injects imports of the step modules so that
64
- * (a) steps self-register into the same registry the engine reads, and
65
- * (b) Vite's HMR graph invalidates the feature test when a step file changes.
66
- */
67
- function stepForge(options = {}) {
68
- const featuresGlobs = toArray(options.features ?? DEFAULT_FEATURES);
69
- const stepsGlob = options.steps ?? DEFAULT_STEPS;
70
- const runtimeModule = options.runtimeModule ?? DEFAULT_RUNTIME_MODULE;
71
- const coreModule = options.coreModule ?? DEFAULT_CORE_MODULE;
72
- let root = process.cwd();
73
- return {
74
- name: "step-forge",
75
- enforce: "pre",
76
- config() {
77
- return { test: { include: featuresGlobs } };
78
- },
79
- configResolved(config) {
80
- root = config.root;
81
- },
82
- async transform(code, id) {
83
- if (!id.endsWith(".feature")) return;
84
- const scenarios = parseFeatureContent(code, id);
85
- const featureName = /^\s*Feature:\s*(.+)$/m.exec(code)?.[1]?.trim() ?? path.basename(id);
86
- const stepImports = (await resolveSteps(stepsGlob, root)).map((f) => `import ${JSON.stringify(toSpecifier(f))};`).join("\n");
87
- const worldImport = options.world ? `import __makeWorld from ${JSON.stringify(toSpecifier(path.resolve(root, options.world)))};` : `import { BasicWorld } from ${JSON.stringify(coreModule)};\nconst __makeWorld = () => new BasicWorld();`;
88
- const tests = generateTests(scenarios);
89
- return {
90
- code: `
91
- import { describe, test, beforeAll, afterAll } from "vitest";
92
- import { runScenario, globalRegistry, runHooks, ensureGlobalHooks } from ${JSON.stringify(runtimeModule)};
93
- ${worldImport}
94
- ${stepImports}
95
-
96
- const __scenarios = ${JSON.stringify(scenarios)};
97
-
98
- describe(${JSON.stringify(featureName)}, () => {
99
- // Global before-hooks fire once per worker, ahead of feature hooks.
100
- beforeAll(() => ensureGlobalHooks());
101
- beforeAll(() => runHooks("feature", "before"));
102
- afterAll(() => runHooks("feature", "after"));
103
- ${tests}
104
- });
105
- `,
106
- map: null
107
- };
108
- }
109
- };
110
- }
111
- /**
112
- * One-line Vitest config preset. Drop this in `vitest.config.ts`:
113
- *
114
- * ```ts
115
- * import { defineStepForgeConfig } from "@step-forge/step-forge/vitest";
116
- * export default defineStepForgeConfig({ world: "./support/world.ts" });
117
- * ```
118
- *
119
- * Runs `**​/*.feature` as native tests, auto-discovers `**​/*.steps.ts`, and
120
- * defaults the world to `BasicWorld`. Override any Vitest option via `test`.
121
- */
122
- function defineStepForgeConfig(options = {}) {
123
- const { test, ...pluginOptions } = options;
124
- const featuresGlobs = toArray(pluginOptions.features ?? DEFAULT_FEATURES);
125
- return {
126
- plugins: [stepForge(pluginOptions)],
127
- test: {
128
- include: featuresGlobs,
129
- ...test
130
- }
131
- };
132
- }
133
- //#endregion
134
- export { defineStepForgeConfig, stepForge };
135
-
136
- //# sourceMappingURL=vitest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest.js","names":[],"sources":["../../src/runtime/vitest.ts"],"sourcesContent":["import { glob } from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { parseFeatureContent } from \"../analyzer/gherkinParser\";\nimport { ParsedScenario } from \"../analyzer/types\";\n\nexport interface StepForgeOptions {\n /**\n * Globs (relative to the Vite root) for step-definition modules.\n * Defaults to `**​/*.steps.ts`.\n */\n steps?: string | string[];\n /**\n * Module that default-exports a world factory `() => world`, resolved\n * relative to the Vite root. When omitted, each scenario gets a fresh\n * `BasicWorld`.\n */\n world?: string;\n /**\n * Feature-file glob(s) to register as test files. Defaults to\n * `**​/*.feature`. Accepts an array to scope several exact files or patterns\n * (e.g. running real features while excluding analyzer fixtures).\n */\n features?: string | string[];\n /**\n * Advanced: module specifier the generated tests import the runtime from.\n * Defaults to the published `@step-forge/step-forge/runtime` entry; override\n * only when consuming the library from source (e.g. this repo's own tests).\n */\n runtimeModule?: string;\n /**\n * Advanced: module specifier for the library core (used for the default\n * `BasicWorld`). Defaults to `@step-forge/step-forge`.\n */\n coreModule?: string;\n}\n\n/** Minimal Vite plugin shape (avoids a hard dependency on vite's types). */\ninterface VitePlugin {\n name: string;\n enforce?: \"pre\" | \"post\";\n config?: () => unknown;\n configResolved?: (config: { root: string }) => void;\n transform?: (\n code: string,\n id: string\n ) => Promise<{ code: string; map: null } | undefined>;\n}\n\nconst DEFAULT_STEPS = \"**/*.steps.ts\";\nconst DEFAULT_FEATURES = \"**/*.feature\";\nconst DEFAULT_RUNTIME_MODULE = \"@step-forge/step-forge/runtime\";\nconst DEFAULT_CORE_MODULE = \"@step-forge/step-forge\";\n\nfunction toArray<T>(value: T | T[]): T[] {\n return Array.isArray(value) ? value : [value];\n}\n\n/**\n * Map a scenario's Gherkin tags onto the Vitest test variant. `@skip` wins over\n * `@only` (a scenario explicitly skipped stays skipped even if also `@only`ed),\n * and everything else is a plain `test`.\n */\nfunction testFn(tags: string[]): string {\n if (tags.includes(\"@skip\")) return \"test.skip\";\n if (tags.includes(\"@only\")) return \"test.only\";\n return \"test\";\n}\n\n/** One `runScenario` test line for the scenario at `__scenarios[index]`. */\nfunction testLine(\n scenario: ParsedScenario,\n index: number,\n indent: string\n): string {\n return (\n `${indent}${testFn(scenario.tags)}(${JSON.stringify(scenario.name)}, () => ` +\n `runScenario(__scenarios[${index}], globalRegistry, __makeWorld));`\n );\n}\n\n/**\n * Emit the test bodies for a feature. Plain scenarios become one `test` each;\n * consecutive rows expanded from the same `Scenario Outline` are wrapped in a\n * `describe` named after the outline, so they read as one labelled group with a\n * `test` per example row (and each row keeps its own `@skip`/`@only`).\n */\nfunction generateTests(scenarios: ParsedScenario[]): string {\n const lines: string[] = [];\n let i = 0;\n while (i < scenarios.length) {\n const outlineName = scenarios[i].outline?.name;\n if (outlineName === undefined) {\n lines.push(testLine(scenarios[i], i, \" \"));\n i += 1;\n continue;\n }\n lines.push(` describe(${JSON.stringify(outlineName)}, () => {`);\n while (i < scenarios.length && scenarios[i].outline?.name === outlineName) {\n lines.push(testLine(scenarios[i], i, \" \"));\n i += 1;\n }\n lines.push(` });`);\n }\n return lines.join(\"\\n\");\n}\n\nfunction toSpecifier(p: string): string {\n // Absolute filesystem paths must be POSIX-style for the generated imports;\n // bare package specifiers are emitted verbatim.\n return path.isAbsolute(p) ? p.split(path.sep).join(\"/\") : p;\n}\n\nasync function resolveSteps(\n steps: string | string[],\n root: string\n): Promise<string[]> {\n const patterns = Array.isArray(steps) ? steps : [steps];\n const files = new Set<string>();\n for (const pattern of patterns) {\n for await (const file of glob(pattern, { cwd: root })) {\n files.add(path.resolve(root, file));\n }\n }\n return [...files];\n}\n\n/**\n * Vite/Vitest plugin: compiles each `.feature` file into a test module so\n * scenarios show up as native Vitest tests (watch mode, --ui, per-scenario\n * tasks, the lot). The transform injects imports of the step modules so that\n * (a) steps self-register into the same registry the engine reads, and\n * (b) Vite's HMR graph invalidates the feature test when a step file changes.\n */\nexport function stepForge(options: StepForgeOptions = {}): VitePlugin {\n const featuresGlobs = toArray(options.features ?? DEFAULT_FEATURES);\n const stepsGlob = options.steps ?? DEFAULT_STEPS;\n const runtimeModule = options.runtimeModule ?? DEFAULT_RUNTIME_MODULE;\n const coreModule = options.coreModule ?? DEFAULT_CORE_MODULE;\n let root = process.cwd();\n\n return {\n name: \"step-forge\",\n enforce: \"pre\",\n config() {\n return { test: { include: featuresGlobs } };\n },\n configResolved(config) {\n root = config.root;\n },\n async transform(code, id) {\n if (!id.endsWith(\".feature\")) return;\n\n const scenarios = parseFeatureContent(code, id);\n const featureName =\n /^\\s*Feature:\\s*(.+)$/m.exec(code)?.[1]?.trim() ?? path.basename(id);\n const stepFiles = await resolveSteps(stepsGlob, root);\n\n const stepImports = stepFiles\n .map(f => `import ${JSON.stringify(toSpecifier(f))};`)\n .join(\"\\n\");\n\n // World factory: an explicit `world` module, or a fresh BasicWorld.\n const worldImport = options.world\n ? `import __makeWorld from ${JSON.stringify(\n toSpecifier(path.resolve(root, options.world))\n )};`\n : `import { BasicWorld } from ${JSON.stringify(coreModule)};\\n` +\n `const __makeWorld = () => new BasicWorld();`;\n\n const tests = generateTests(scenarios);\n\n const generated = `\nimport { describe, test, beforeAll, afterAll } from \"vitest\";\nimport { runScenario, globalRegistry, runHooks, ensureGlobalHooks } from ${JSON.stringify(\n runtimeModule\n )};\n${worldImport}\n${stepImports}\n\nconst __scenarios = ${JSON.stringify(scenarios)};\n\ndescribe(${JSON.stringify(featureName)}, () => {\n // Global before-hooks fire once per worker, ahead of feature hooks.\n beforeAll(() => ensureGlobalHooks());\n beforeAll(() => runHooks(\"feature\", \"before\"));\n afterAll(() => runHooks(\"feature\", \"after\"));\n${tests}\n});\n`;\n return { code: generated, map: null };\n },\n };\n}\n\n/**\n * One-line Vitest config preset. Drop this in `vitest.config.ts`:\n *\n * ```ts\n * import { defineStepForgeConfig } from \"@step-forge/step-forge/vitest\";\n * export default defineStepForgeConfig({ world: \"./support/world.ts\" });\n * ```\n *\n * Runs `**​/*.feature` as native tests, auto-discovers `**​/*.steps.ts`, and\n * defaults the world to `BasicWorld`. Override any Vitest option via `test`.\n */\nexport function defineStepForgeConfig(\n options: StepForgeOptions & { test?: Record<string, unknown> } = {}\n) {\n const { test, ...pluginOptions } = options;\n const featuresGlobs = toArray(pluginOptions.features ?? DEFAULT_FEATURES);\n return {\n plugins: [stepForge(pluginOptions)],\n test: { include: featuresGlobs, ...test },\n };\n}\n"],"mappings":";;;;AAgDA,MAAM,gBAAgB;AACtB,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AAC/B,MAAM,sBAAsB;AAE5B,SAAS,QAAW,OAAqB;CACvC,OAAO,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,KAAK;AAC9C;;;;;;AAOA,SAAS,OAAO,MAAwB;CACtC,IAAI,KAAK,SAAS,OAAO,GAAG,OAAO;CACnC,IAAI,KAAK,SAAS,OAAO,GAAG,OAAO;CACnC,OAAO;AACT;;AAGA,SAAS,SACP,UACA,OACA,QACQ;CACR,OACE,GAAG,SAAS,OAAO,SAAS,IAAI,EAAE,GAAG,KAAK,UAAU,SAAS,IAAI,EAAE,kCACxC,MAAM;AAErC;;;;;;;AAQA,SAAS,cAAc,WAAqC;CAC1D,MAAM,QAAkB,CAAC;CACzB,IAAI,IAAI;CACR,OAAO,IAAI,UAAU,QAAQ;EAC3B,MAAM,cAAc,UAAU,EAAE,CAAC,SAAS;EAC1C,IAAI,gBAAgB,KAAA,GAAW;GAC7B,MAAM,KAAK,SAAS,UAAU,IAAI,GAAG,IAAI,CAAC;GAC1C,KAAK;GACL;EACF;EACA,MAAM,KAAK,cAAc,KAAK,UAAU,WAAW,EAAE,UAAU;EAC/D,OAAO,IAAI,UAAU,UAAU,UAAU,EAAE,CAAC,SAAS,SAAS,aAAa;GACzE,MAAM,KAAK,SAAS,UAAU,IAAI,GAAG,MAAM,CAAC;GAC5C,KAAK;EACP;EACA,MAAM,KAAK,OAAO;CACpB;CACA,OAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,YAAY,GAAmB;CAGtC,OAAO,KAAK,WAAW,CAAC,IAAI,EAAE,MAAM,KA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