executable-stories-formatters 0.6.1 → 0.6.2
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 +6 -3
- package/skills/formatters-cli/SKILL.md +213 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "executable-stories-formatters",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
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
|
-
"
|
|
39
|
+
"skills",
|
|
40
|
+
"schemas",
|
|
41
|
+
"bin"
|
|
39
42
|
],
|
|
40
43
|
"engines": {
|
|
41
44
|
"node": ">=22"
|
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
# Validate JSON against schema
|
|
40
|
+
executable-stories validate raw-run.json
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Programmatic usage
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import {
|
|
47
|
+
canonicalizeRun,
|
|
48
|
+
ReportGenerator,
|
|
49
|
+
} from "executable-stories-formatters";
|
|
50
|
+
|
|
51
|
+
const rawRun = JSON.parse(await readFile("raw-run.json", "utf-8"));
|
|
52
|
+
const canonical = canonicalizeRun(rawRun);
|
|
53
|
+
|
|
54
|
+
const generator = new ReportGenerator({
|
|
55
|
+
formats: ["markdown", "html"],
|
|
56
|
+
outputDir: "docs",
|
|
57
|
+
outputName: "user-stories",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const outputs = await generator.generate(canonical);
|
|
61
|
+
// Map<OutputFormat, string[]> — file paths written per format
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Core Patterns
|
|
65
|
+
|
|
66
|
+
### Three-layer pipeline
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
Test code (story.given/when/then)
|
|
70
|
+
→ Framework adapter (vitest/jest/playwright/cypress)
|
|
71
|
+
→ RawRun JSON (schemaVersion: 1)
|
|
72
|
+
→ canonicalizeRun() → TestRunResult
|
|
73
|
+
→ Formatters (HTML, Markdown, JUnit, Cucumber JSON/HTML/Messages)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Individual formatters
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import {
|
|
80
|
+
canonicalizeRun,
|
|
81
|
+
MarkdownFormatter,
|
|
82
|
+
HtmlFormatter,
|
|
83
|
+
JUnitFormatter,
|
|
84
|
+
CucumberJsonFormatter,
|
|
85
|
+
} from "executable-stories-formatters";
|
|
86
|
+
|
|
87
|
+
const canonical = canonicalizeRun(rawRun);
|
|
88
|
+
|
|
89
|
+
const md = new MarkdownFormatter().format(canonical);
|
|
90
|
+
const html = new HtmlFormatter().format(canonical);
|
|
91
|
+
const junit = new JUnitFormatter().format(canonical);
|
|
92
|
+
const cucumberJson = new CucumberJsonFormatter().formatToString(canonical);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### CLI flags
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Output control
|
|
99
|
+
--format html,markdown,junit,cucumber-json,cucumber-html,cucumber-messages
|
|
100
|
+
--output-dir reports # Base directory (default: reports)
|
|
101
|
+
--output-name test-results # Base filename (default: test-results)
|
|
102
|
+
--input-type raw # raw | canonical | ndjson
|
|
103
|
+
|
|
104
|
+
# Filtering
|
|
105
|
+
--include "test/api/**" # Glob patterns to include
|
|
106
|
+
--exclude "test/fixtures/**" # Glob patterns to exclude
|
|
107
|
+
|
|
108
|
+
# HTML options
|
|
109
|
+
--html-title "Test Report"
|
|
110
|
+
--html-no-syntax-highlighting
|
|
111
|
+
--html-no-mermaid
|
|
112
|
+
--html-no-markdown
|
|
113
|
+
|
|
114
|
+
# Story synthesis
|
|
115
|
+
--synthesize-stories # Enabled by default
|
|
116
|
+
--no-synthesize-stories # Disable
|
|
117
|
+
|
|
118
|
+
# Machine output
|
|
119
|
+
--json-summary # Print JSON summary to stdout
|
|
120
|
+
--emit-canonical path.json # Write canonical JSON
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Validation
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import {
|
|
127
|
+
canonicalizeRun,
|
|
128
|
+
validateCanonicalRun,
|
|
129
|
+
assertValidRun,
|
|
130
|
+
} from "executable-stories-formatters";
|
|
131
|
+
|
|
132
|
+
const canonical = canonicalizeRun(rawRun);
|
|
133
|
+
|
|
134
|
+
// Returns { valid: boolean, errors: string[] }
|
|
135
|
+
const result = validateCanonicalRun(canonical);
|
|
136
|
+
|
|
137
|
+
// Throws if invalid
|
|
138
|
+
assertValidRun(canonical);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Notifications
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
executable-stories format raw-run.json \
|
|
145
|
+
--format markdown \
|
|
146
|
+
--slack-webhook "$SLACK_WEBHOOK_URL" \
|
|
147
|
+
--notify on-failure \
|
|
148
|
+
--report-url "https://ci.example.com/reports" \
|
|
149
|
+
--max-failed-tests 5
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Common Mistakes
|
|
153
|
+
|
|
154
|
+
### HIGH Passing invalid RawRun JSON
|
|
155
|
+
|
|
156
|
+
Wrong:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{ "tests": [{ "name": "my test" }] }
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Correct:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{
|
|
166
|
+
"schemaVersion": 1,
|
|
167
|
+
"metadata": { "startedAt": "2024-01-01T00:00:00Z" },
|
|
168
|
+
"testCases": [
|
|
169
|
+
{
|
|
170
|
+
"id": "test-1",
|
|
171
|
+
"name": "my test",
|
|
172
|
+
"sourceFile": "test/example.test.ts",
|
|
173
|
+
"status": "passed"
|
|
174
|
+
}
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
The CLI validates against the RawRun schema. Invalid input exits with code 1. The `schemaVersion`, `metadata`, and `testCases` fields are required.
|
|
180
|
+
|
|
181
|
+
Source: packages/executable-stories-formatters/src/cli.ts
|
|
182
|
+
|
|
183
|
+
### MEDIUM Tests without story metadata silently filtered
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// This test has no story.init() — it will be excluded from reports
|
|
187
|
+
it("adds numbers", () => {
|
|
188
|
+
expect(add(2, 3)).toBe(5);
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`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.
|
|
193
|
+
|
|
194
|
+
Source: packages/executable-stories-formatters/src/index.ts
|
|
195
|
+
|
|
196
|
+
### MEDIUM Exit codes not checked in CI
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Wrong — ignores failures
|
|
200
|
+
executable-stories format raw-run.json --format markdown || true
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Correct — CI fails on error
|
|
205
|
+
executable-stories format raw-run.json --format markdown
|
|
206
|
+
# Exit 0: success
|
|
207
|
+
# Exit 1: schema validation failure
|
|
208
|
+
# Exit 2: canonical validation failure
|
|
209
|
+
# Exit 3: formatter/generation failure
|
|
210
|
+
# Exit 4: bad arguments
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Source: packages/executable-stories-formatters/src/cli.ts
|