executable-stories-formatters 0.6.1 → 0.7.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "executable-stories-formatters",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "Cucumber-compatible report formats (HTML, Markdown, JUnit XML, Cucumber JSON) for executable-stories test results.",
5
5
  "author": "Jag Reehal <jag@jagreehal.com>",
6
6
  "license": "MIT",
@@ -31,11 +31,14 @@
31
31
  }
32
32
  },
33
33
  "bin": {
34
- "executable-stories": "./dist/cli.js"
34
+ "executable-stories": "./dist/cli.js",
35
+ "intent": "./bin/intent.js"
35
36
  },
36
37
  "files": [
37
38
  "dist",
38
- "schemas"
39
+ "skills",
40
+ "schemas",
41
+ "bin"
39
42
  ],
40
43
  "engines": {
41
44
  "node": ">=22"
@@ -54,16 +57,16 @@
54
57
  ],
55
58
  "dependencies": {
56
59
  "@cucumber/html-formatter": "^23.0.0",
57
- "@cucumber/messages": "^32.0.1",
60
+ "@cucumber/messages": "^32.2.0",
58
61
  "ajv": "^8.18.0"
59
62
  },
60
63
  "devDependencies": {
61
64
  "@faker-js/faker": "^10.3.0",
62
- "@types/node": "^25.3.2",
65
+ "@types/node": "^25.5.0",
63
66
  "tsup": "^8.5.1",
64
67
  "tsx": "^4.21.0",
65
68
  "typescript": "~5.9.3",
66
- "vitest": "^4.0.18",
69
+ "vitest": "^4.1.0",
67
70
  "vitest-mock-extended": "^3.1.0"
68
71
  },
69
72
  "scripts": {
@@ -208,6 +208,19 @@
208
208
  "type": "array",
209
209
  "items": { "$ref": "#/$defs/DocEntry" },
210
210
  "description": "Rich documentation entries attached to this step."
211
+ },
212
+ "id": {
213
+ "type": "string",
214
+ "description": "Unique step identifier within the scenario (e.g., 'step-0')."
215
+ },
216
+ "wrapped": {
217
+ "type": "boolean",
218
+ "description": "Whether this step wraps a function call (Fn/Expect pattern)."
219
+ },
220
+ "durationMs": {
221
+ "type": "number",
222
+ "minimum": 0,
223
+ "description": "Step-level duration in milliseconds (from startTimer/endTimer)."
211
224
  }
212
225
  },
213
226
  "required": ["keyword", "text"],
@@ -0,0 +1,252 @@
1
+ ---
2
+ name: formatters-cli
3
+ description: >
4
+ executable-stories CLI: format and validate subcommands. Pipeline: RawRun
5
+ JSON from stdin or file, canonicalizeRun() normalization, 6 output formats
6
+ (HTML, Markdown, JUnit, Cucumber JSON/HTML/Messages). fn(args, deps)
7
+ dependency injection. Exit codes 0=success, 1=schema, 2=canonical,
8
+ 3=generation, 4=usage. ReportGenerator programmatic API. Aggregated and
9
+ colocated output modes. canonicalizeRun, assertValidRun, validateCanonicalRun.
10
+ type: core
11
+ library: executable-stories-formatters
12
+ library_version: "0.6.1"
13
+ sources:
14
+ - "jagreehal/executable-stories:packages/executable-stories-formatters/src/cli.ts"
15
+ - "jagreehal/executable-stories:packages/executable-stories-formatters/src/index.ts"
16
+ - "jagreehal/executable-stories:apps/docs-site/src/content/docs/formatters/formatters-api.md"
17
+ ---
18
+
19
+ # executable-stories-formatters — CLI & API
20
+
21
+ ## Setup
22
+
23
+ ```bash
24
+ npm install -D executable-stories-formatters
25
+ ```
26
+
27
+ ### CLI usage
28
+
29
+ ```bash
30
+ # Generate markdown from raw run JSON
31
+ executable-stories format raw-run.json --format markdown --output-dir docs
32
+
33
+ # Generate multiple formats
34
+ executable-stories format raw-run.json --format html,markdown,junit
35
+
36
+ # Read from stdin
37
+ cat raw-run.json | executable-stories format --stdin --format markdown
38
+
39
+ # Compare two canonical runs for review-friendly output
40
+ executable-stories compare baseline.json current.json \
41
+ --input-type canonical \
42
+ --format html,markdown \
43
+ --output-name review-diff
44
+
45
+ # Validate JSON against schema
46
+ executable-stories validate raw-run.json
47
+ ```
48
+
49
+ ### Programmatic usage
50
+
51
+ ```typescript
52
+ import {
53
+ canonicalizeRun,
54
+ ReportGenerator,
55
+ } from "executable-stories-formatters";
56
+
57
+ const rawRun = JSON.parse(await readFile("raw-run.json", "utf-8"));
58
+ const canonical = canonicalizeRun(rawRun);
59
+
60
+ const generator = new ReportGenerator({
61
+ formats: ["markdown", "html"],
62
+ outputDir: "docs",
63
+ outputName: "user-stories",
64
+ outputNameTimestamp: true, // optional: unique filenames per run (e.g. user-stories-1739123456.md)
65
+ sortTestCases: "id", // optional: stable order for diff-friendly reports
66
+ });
67
+
68
+ const outputs = await generator.generate(canonical);
69
+ // Map<OutputFormat, string[]> — file paths written per format
70
+ ```
71
+
72
+ ## Core Patterns
73
+
74
+ ### Three-layer pipeline
75
+
76
+ ```
77
+ Test code (story.given/when/then)
78
+ → Framework adapter (vitest/jest/playwright/cypress)
79
+ → RawRun JSON (schemaVersion: 1)
80
+ → canonicalizeRun() → TestRunResult
81
+ → Formatters (HTML, Markdown, JUnit, Cucumber JSON/HTML/Messages)
82
+ ```
83
+
84
+ ### Individual formatters
85
+
86
+ ```typescript
87
+ import {
88
+ canonicalizeRun,
89
+ MarkdownFormatter,
90
+ HtmlFormatter,
91
+ JUnitFormatter,
92
+ CucumberJsonFormatter,
93
+ } from "executable-stories-formatters";
94
+
95
+ const canonical = canonicalizeRun(rawRun);
96
+
97
+ const md = new MarkdownFormatter().format(canonical);
98
+ const html = new HtmlFormatter().format(canonical);
99
+ const junit = new JUnitFormatter().format(canonical);
100
+ const cucumberJson = new CucumberJsonFormatter().formatToString(canonical);
101
+ ```
102
+
103
+ ### CLI flags
104
+
105
+ ```bash
106
+ # Output control
107
+ --format html,markdown,junit,cucumber-json,cucumber-html,cucumber-messages
108
+ --output-dir reports # Base directory (default: reports)
109
+ --output-name test-results # Base filename (default: test-results)
110
+ --output-name-timestamp # Append run timestamp (UTC seconds) to filename for before/after diffs
111
+ --sort-test-cases id|source|none # Deterministic scenario order (default: none). Use id for diff-friendly output
112
+ --input-type raw # raw | canonical | ndjson
113
+
114
+ # Filtering
115
+ --include "test/api/**" # Glob patterns to include
116
+ --exclude "test/fixtures/**" # Glob patterns to exclude
117
+
118
+ # HTML options
119
+ --html-title "Test Report"
120
+ --html-no-syntax-highlighting
121
+ --html-no-mermaid
122
+ --html-no-markdown
123
+
124
+ # Story synthesis
125
+ --synthesize-stories # Enabled by default
126
+ --no-synthesize-stories # Disable
127
+
128
+ # Machine output
129
+ --json-summary # Print JSON summary to stdout
130
+ --emit-canonical path.json # Write canonical JSON
131
+ ```
132
+
133
+ ### Validation
134
+
135
+ ```typescript
136
+ import {
137
+ canonicalizeRun,
138
+ validateCanonicalRun,
139
+ assertValidRun,
140
+ } from "executable-stories-formatters";
141
+
142
+ const canonical = canonicalizeRun(rawRun);
143
+
144
+ // Returns { valid: boolean, errors: string[] }
145
+ const result = validateCanonicalRun(canonical);
146
+
147
+ // Throws if invalid
148
+ assertValidRun(canonical);
149
+ ```
150
+
151
+ ### Before/after diffs (evolution of tests)
152
+
153
+ To compare reports across runs (e.g. in CI or locally), use timestamped filenames and deterministic ordering so diffs show real changes instead of random reordering from parallel test execution:
154
+
155
+ ```bash
156
+ executable-stories format raw-run.json --format markdown,html \
157
+ --output-name-timestamp \
158
+ --sort-test-cases id
159
+ ```
160
+
161
+ - `--output-name-timestamp`: appends run start time in UTC seconds (e.g. `test-results-1739123456.md`), so each run produces a unique, chronologically sortable file.
162
+ - `--sort-test-cases id`: sorts scenarios by deterministic id (hash of source file + scenario name) so report content order is stable across runs.
163
+
164
+ Programmatic: set `outputNameTimestamp: true` and `sortTestCases: "id"` (or `"source"` for file/line order) on `FormatterOptions`.
165
+
166
+ For first-class run comparisons, use the dedicated compare subcommand:
167
+
168
+ ```bash
169
+ executable-stories compare baseline.json current.json \
170
+ --input-type canonical \
171
+ --format html,markdown \
172
+ --output-dir reports \
173
+ --output-name test-results-diff
174
+ ```
175
+
176
+ - Generates a standalone HTML review report with filter chips for `Regressed`, `Fixed`, `Added`, `Removed`, and `Changed`.
177
+ - Generates Markdown with per-scenario before/after summaries for PR discussion or artifact storage.
178
+ - Use canonical input when you already persist prior runs; raw and ndjson inputs are also supported as long as both files use the same `--input-type`.
179
+
180
+ ### Notifications
181
+
182
+ ```bash
183
+ executable-stories format raw-run.json \
184
+ --format markdown \
185
+ --slack-webhook "$SLACK_WEBHOOK_URL" \
186
+ --notify on-failure \
187
+ --report-url "https://ci.example.com/reports" \
188
+ --max-failed-tests 5
189
+ ```
190
+
191
+ ## Common Mistakes
192
+
193
+ ### HIGH Passing invalid RawRun JSON
194
+
195
+ Wrong:
196
+
197
+ ```json
198
+ { "tests": [{ "name": "my test" }] }
199
+ ```
200
+
201
+ Correct:
202
+
203
+ ```json
204
+ {
205
+ "schemaVersion": 1,
206
+ "metadata": { "startedAt": "2024-01-01T00:00:00Z" },
207
+ "testCases": [
208
+ {
209
+ "id": "test-1",
210
+ "name": "my test",
211
+ "sourceFile": "test/example.test.ts",
212
+ "status": "passed"
213
+ }
214
+ ]
215
+ }
216
+ ```
217
+
218
+ The CLI validates against the RawRun schema. Invalid input exits with code 1. The `schemaVersion`, `metadata`, and `testCases` fields are required.
219
+
220
+ Source: packages/executable-stories-formatters/src/cli.ts
221
+
222
+ ### MEDIUM Tests without story metadata silently filtered
223
+
224
+ ```typescript
225
+ // This test has no story.init() — it will be excluded from reports
226
+ it("adds numbers", () => {
227
+ expect(add(2, 3)).toBe(5);
228
+ });
229
+ ```
230
+
231
+ `canonicalizeRun()` filters out test cases where `story == null` by default. Use `--synthesize-stories` (enabled by default) to include non-story tests with synthesized metadata, or add `story.init()` to your tests.
232
+
233
+ Source: packages/executable-stories-formatters/src/index.ts
234
+
235
+ ### MEDIUM Exit codes not checked in CI
236
+
237
+ ```bash
238
+ # Wrong — ignores failures
239
+ executable-stories format raw-run.json --format markdown || true
240
+ ```
241
+
242
+ ```bash
243
+ # Correct — CI fails on error
244
+ executable-stories format raw-run.json --format markdown
245
+ # Exit 0: success
246
+ # Exit 1: schema validation failure
247
+ # Exit 2: canonical validation failure
248
+ # Exit 3: formatter/generation failure
249
+ # Exit 4: bad arguments
250
+ ```
251
+
252
+ Source: packages/executable-stories-formatters/src/cli.ts