executable-stories-formatters 0.1.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.
@@ -0,0 +1,378 @@
1
+ /**
2
+ * Story types — the shared vocabulary for all framework adapters.
3
+ *
4
+ * These types were previously in executable-stories-core.
5
+ * They now live in formatters so every adapter can import them
6
+ * from the same place that defines RawRun (the output contract).
7
+ */
8
+ /** BDD step keywords for scenario documentation */
9
+ type StepKeyword = "Given" | "When" | "Then" | "And" | "But";
10
+ /** Step execution mode for docs rendering */
11
+ type StepMode = "normal" | "skip" | "only" | "todo" | "fails" | "concurrent";
12
+ /** Phase tracks when the doc entry was added */
13
+ type DocPhase = "static" | "runtime";
14
+ /** Union type for all documentation entry kinds */
15
+ type DocEntry = {
16
+ kind: "note";
17
+ text: string;
18
+ phase: DocPhase;
19
+ } | {
20
+ kind: "tag";
21
+ names: string[];
22
+ phase: DocPhase;
23
+ } | {
24
+ kind: "kv";
25
+ label: string;
26
+ value: unknown;
27
+ phase: DocPhase;
28
+ } | {
29
+ kind: "code";
30
+ label: string;
31
+ content: string;
32
+ lang?: string;
33
+ phase: DocPhase;
34
+ } | {
35
+ kind: "table";
36
+ label: string;
37
+ columns: string[];
38
+ rows: string[][];
39
+ phase: DocPhase;
40
+ } | {
41
+ kind: "link";
42
+ label: string;
43
+ url: string;
44
+ phase: DocPhase;
45
+ } | {
46
+ kind: "section";
47
+ title: string;
48
+ markdown: string;
49
+ phase: DocPhase;
50
+ } | {
51
+ kind: "mermaid";
52
+ code: string;
53
+ title?: string;
54
+ phase: DocPhase;
55
+ } | {
56
+ kind: "screenshot";
57
+ path: string;
58
+ alt?: string;
59
+ phase: DocPhase;
60
+ } | {
61
+ kind: "custom";
62
+ type: string;
63
+ data: unknown;
64
+ phase: DocPhase;
65
+ };
66
+ /**
67
+ * A single step in a scenario with its documentation entries.
68
+ */
69
+ interface StoryStep {
70
+ /** Stable internal ID (auto-generated at creation, e.g., "step-0") */
71
+ id?: string;
72
+ /** The BDD keyword (Given, When, Then, And, But) */
73
+ keyword: StepKeyword;
74
+ /** The step description text */
75
+ text: string;
76
+ /** Step execution mode for docs rendering */
77
+ mode?: StepMode;
78
+ /** Rich documentation entries attached to this step */
79
+ docs?: DocEntry[];
80
+ /** Opt-in step duration in milliseconds */
81
+ durationMs?: number;
82
+ /** Whether this step wrapped a function body (step.fn / step.step) vs a text marker */
83
+ wrapped?: boolean;
84
+ }
85
+ /**
86
+ * Metadata for a complete scenario, attached to test metadata.
87
+ * Used by reporters to generate documentation.
88
+ */
89
+ interface StoryMeta {
90
+ /** The scenario title (from test name) */
91
+ scenario: string;
92
+ /** All steps in this scenario */
93
+ steps: StoryStep[];
94
+ /** Tags for filtering and categorization */
95
+ tags?: string[];
96
+ /** Ticket/issue references (normalized to array) */
97
+ tickets?: string[];
98
+ /** User-defined metadata */
99
+ meta?: Record<string, unknown>;
100
+ /** Parent describe/suite names for hierarchical grouping */
101
+ suitePath?: string[];
102
+ /** Story-level docs (before any steps) */
103
+ docs?: DocEntry[];
104
+ /** Order in which story.init() was called (for source ordering) */
105
+ sourceOrder?: number;
106
+ }
107
+ /** Key used to store StoryMeta in test metadata */
108
+ declare const STORY_META_KEY = "story";
109
+
110
+ /**
111
+ * Raw types for Layer 1: Framework Adapters.
112
+ *
113
+ * These types are permissive and gather best-effort data from each framework.
114
+ * The ACL (Layer 2) will normalize these into strict canonical types.
115
+ */
116
+
117
+ /** Permissive status from any framework */
118
+ type RawStatus = "pass" | "fail" | "skip" | "todo" | "pending" | "timeout" | "interrupted" | "unknown";
119
+ /** Raw attachment - don't decide inline vs link yet */
120
+ interface RawAttachment {
121
+ name: string;
122
+ mediaType: string;
123
+ /** File reference (path on disk) */
124
+ path?: string;
125
+ /** Inline content */
126
+ body?: string;
127
+ /** Content encoding */
128
+ encoding?: "BASE64" | "IDENTITY";
129
+ /** Character set (default: "utf-8" when IDENTITY + text) */
130
+ charset?: string;
131
+ /** Actual artifact name (distinct from logical label) */
132
+ fileName?: string;
133
+ /** Size in bytes (for embed vs link decision) */
134
+ byteLength?: number;
135
+ /** Step index (undefined = test-case level) */
136
+ stepIndex?: number;
137
+ /** Stable step ID, preferred over stepIndex by converter */
138
+ stepId?: string;
139
+ }
140
+ /** Raw step event from framework (if available) */
141
+ interface RawStepEvent {
142
+ index?: number;
143
+ title?: string;
144
+ status?: RawStatus;
145
+ durationMs?: number;
146
+ errorMessage?: string;
147
+ }
148
+ /** Raw test case - best-effort data gathering */
149
+ interface RawTestCase {
150
+ /** Framework's test ID */
151
+ externalId?: string;
152
+ /** Test title/name */
153
+ title?: string;
154
+ /** Full title path (describe blocks + test name) */
155
+ titlePath?: string[];
156
+ /** Story metadata from test */
157
+ story?: StoryMeta;
158
+ /** Source file path */
159
+ sourceFile?: string;
160
+ /** Source line number (1-based) */
161
+ sourceLine?: number;
162
+ /** Test status */
163
+ status: RawStatus;
164
+ /** Duration in milliseconds */
165
+ durationMs?: number;
166
+ /** Error information */
167
+ error?: {
168
+ message?: string;
169
+ stack?: string;
170
+ };
171
+ /** Step-level info if framework provides it */
172
+ stepEvents?: RawStepEvent[];
173
+ /** Attachments (screenshots, logs, etc.) */
174
+ attachments?: RawAttachment[];
175
+ /** Framework-specific metadata (kept for debugging) */
176
+ meta?: Record<string, unknown>;
177
+ /** Retry attempt number (0-based) */
178
+ retry?: number;
179
+ /** Total retry count configured */
180
+ retries?: number;
181
+ /** Playwright project name */
182
+ projectName?: string;
183
+ }
184
+ /** CI environment info */
185
+ interface RawCIInfo {
186
+ name: string;
187
+ url?: string;
188
+ buildNumber?: string;
189
+ }
190
+ /** Raw run - all framework data gathered */
191
+ interface RawRun {
192
+ /** All test cases from the run */
193
+ testCases: RawTestCase[];
194
+ /** Run start time (epoch ms) */
195
+ startedAtMs?: number;
196
+ /** Run finish time (epoch ms) */
197
+ finishedAtMs?: number;
198
+ /** Project root directory */
199
+ projectRoot: string;
200
+ /** Package version */
201
+ packageVersion?: string;
202
+ /** Git commit SHA */
203
+ gitSha?: string;
204
+ /** CI environment info */
205
+ ci?: RawCIInfo;
206
+ }
207
+
208
+ /**
209
+ * Jest Adapter - Layer 1.
210
+ *
211
+ * Transforms Jest test results and story reports into RawRun.
212
+ */
213
+
214
+ /** Jest test result shape (subset of what Jest provides) */
215
+ interface JestTestResult {
216
+ fullName: string;
217
+ status: "passed" | "failed" | "pending" | "todo";
218
+ duration?: number;
219
+ failureMessages?: string[];
220
+ }
221
+ /** Jest file result shape */
222
+ interface JestFileResult {
223
+ testFilePath: string;
224
+ testResults: JestTestResult[];
225
+ }
226
+ /** Jest aggregated result shape */
227
+ interface JestAggregatedResult {
228
+ testResults: JestFileResult[];
229
+ startTime?: number;
230
+ }
231
+ /** Story file report written by story.init() */
232
+ interface StoryFileReport {
233
+ testFilePath: string;
234
+ scenarios: StoryMeta[];
235
+ }
236
+ /** Options for Jest adapter */
237
+ interface JestAdapterOptions {
238
+ /** Project root directory */
239
+ projectRoot?: string;
240
+ /** Package version */
241
+ packageVersion?: string;
242
+ /** Git SHA */
243
+ gitSha?: string;
244
+ }
245
+ /**
246
+ * Adapt Jest results and story reports to RawRun.
247
+ *
248
+ * @param jestResults - Jest aggregated results
249
+ * @param storyReports - Story reports from story.init()
250
+ * @param options - Adapter options
251
+ * @returns RawRun for ACL processing
252
+ */
253
+ declare function adaptJestRun(jestResults: JestAggregatedResult, storyReports: StoryFileReport[], options?: JestAdapterOptions): RawRun;
254
+
255
+ /**
256
+ * Vitest Adapter - Layer 1.
257
+ *
258
+ * Transforms Vitest test results into RawRun.
259
+ */
260
+
261
+ /** Vitest test state */
262
+ type VitestState = "passed" | "failed" | "skipped" | "pending";
263
+ /** Vitest serialized error */
264
+ interface VitestSerializedError {
265
+ message?: string;
266
+ stack?: string;
267
+ diff?: string;
268
+ }
269
+ /** Vitest test result shape */
270
+ interface VitestTestResult {
271
+ state?: VitestState;
272
+ duration?: number;
273
+ errors?: VitestSerializedError[];
274
+ }
275
+ /** Vitest test case shape (minimal) */
276
+ interface VitestTestCase {
277
+ name: string;
278
+ meta: () => Record<string, unknown>;
279
+ result: () => VitestTestResult | undefined;
280
+ }
281
+ /** Vitest test module shape (minimal) */
282
+ interface VitestTestModule {
283
+ moduleId?: string;
284
+ relativeModuleId?: string;
285
+ children?: {
286
+ allTests: () => Iterable<VitestTestCase>;
287
+ };
288
+ }
289
+ /** Options for Vitest adapter */
290
+ interface VitestAdapterOptions {
291
+ /** Project root directory */
292
+ projectRoot?: string;
293
+ /** Package version */
294
+ packageVersion?: string;
295
+ /** Git SHA */
296
+ gitSha?: string;
297
+ /** Start time (epoch ms) */
298
+ startedAtMs?: number;
299
+ }
300
+ /**
301
+ * Adapt Vitest test modules to RawRun.
302
+ *
303
+ * @param testModules - Vitest test modules
304
+ * @param options - Adapter options
305
+ * @returns RawRun for ACL processing
306
+ */
307
+ declare function adaptVitestRun(testModules: ReadonlyArray<VitestTestModule>, options?: VitestAdapterOptions): RawRun;
308
+
309
+ /**
310
+ * Playwright Adapter - Layer 1.
311
+ *
312
+ * Transforms Playwright test results into RawRun.
313
+ */
314
+
315
+ /** Playwright test status */
316
+ type PlaywrightStatus = "passed" | "failed" | "skipped" | "timedOut" | "interrupted";
317
+ /** Playwright test error */
318
+ interface PlaywrightError {
319
+ message?: string;
320
+ stack?: string;
321
+ }
322
+ /** Playwright attachment */
323
+ interface PlaywrightAttachment {
324
+ name: string;
325
+ contentType: string;
326
+ path?: string;
327
+ body?: Buffer;
328
+ }
329
+ /** Playwright test result */
330
+ interface PlaywrightTestResult {
331
+ status: PlaywrightStatus;
332
+ duration: number;
333
+ errors: PlaywrightError[];
334
+ attachments: PlaywrightAttachment[];
335
+ retry: number;
336
+ }
337
+ /** Playwright test case annotation */
338
+ interface PlaywrightAnnotation {
339
+ type: string;
340
+ description?: string;
341
+ }
342
+ /** Playwright test location */
343
+ interface PlaywrightLocation {
344
+ file: string;
345
+ line: number;
346
+ column: number;
347
+ }
348
+ /** Playwright test case shape (minimal) */
349
+ interface PlaywrightTestCase {
350
+ title: string;
351
+ titlePath: () => string[];
352
+ annotations: PlaywrightAnnotation[];
353
+ location: PlaywrightLocation;
354
+ retries: number;
355
+ }
356
+ /** Options for Playwright adapter */
357
+ interface PlaywrightAdapterOptions {
358
+ /** Project root directory */
359
+ projectRoot?: string;
360
+ /** Package version */
361
+ packageVersion?: string;
362
+ /** Git SHA */
363
+ gitSha?: string;
364
+ /** Start time (epoch ms) */
365
+ startedAtMs?: number;
366
+ /** Playwright project name */
367
+ projectName?: string;
368
+ }
369
+ /**
370
+ * Adapt Playwright test results to RawRun.
371
+ *
372
+ * @param testResults - Array of [testCase, result] tuples
373
+ * @param options - Adapter options
374
+ * @returns RawRun for ACL processing
375
+ */
376
+ declare function adaptPlaywrightRun(testResults: Array<[PlaywrightTestCase, PlaywrightTestResult]>, options?: PlaywrightAdapterOptions): RawRun;
377
+
378
+ export { type VitestTestCase as A, type VitestTestModule as B, type VitestTestResult as C, type DocEntry as D, type JestAdapterOptions as J, type PlaywrightAdapterOptions as P, type RawStatus as R, type StoryMeta as S, type VitestAdapterOptions as V, type StoryStep as a, type RawAttachment as b, type RawRun as c, type RawCIInfo as d, adaptJestRun as e, adaptPlaywrightRun as f, adaptVitestRun as g, type DocPhase as h, type JestAggregatedResult as i, type JestFileResult as j, type JestTestResult as k, type PlaywrightAnnotation as l, type PlaywrightAttachment as m, type PlaywrightError as n, type PlaywrightLocation as o, type PlaywrightStatus as p, type PlaywrightTestCase as q, type PlaywrightTestResult as r, type RawStepEvent as s, type RawTestCase as t, STORY_META_KEY as u, type StepKeyword as v, type StepMode as w, type StoryFileReport as x, type VitestSerializedError as y, type VitestState as z };