executable-stories-playwright 8.1.4 → 8.2.1

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/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _playwright_test from '@playwright/test';
2
- import { TestInfo, PlaywrightTestArgs, PlaywrightTestOptions } from '@playwright/test';
2
+ import { TestInfo, PlaywrightTestArgs, PlaywrightTestOptions, TestStepInfo } from '@playwright/test';
3
+ export { TestStepInfo } from '@playwright/test';
3
4
  import * as executable_stories_formatters from 'executable-stories-formatters';
4
5
  import { DocEntry, StepKeyword } from 'executable-stories-formatters';
5
6
  export { DocEntry, NormalizedTicket, StepKeyword, StoryMeta, StoryStep } from 'executable-stories-formatters';
@@ -78,6 +79,15 @@ interface StoryOptions {
78
79
  /** Playwright fixtures (first argument of the test callback). When set, step callbacks receive this as their first argument. */
79
80
  fixtures?: unknown;
80
81
  }
82
+ /** Options for story.console() – captures page console messages as a doc entry. */
83
+ interface ConsoleOptions {
84
+ /** The Playwright Page object (typed as unknown to avoid importing Page here). */
85
+ page: unknown;
86
+ /** Label shown above the console output block. Defaults to "Console". */
87
+ label?: string;
88
+ /** Also capture page errors (uncaught exceptions). Defaults to false. */
89
+ includeErrors?: boolean;
90
+ }
81
91
  /** Options for story.attach(). */
82
92
  interface AttachmentOptions {
83
93
  name: string;
@@ -134,67 +144,67 @@ declare const story: {
134
144
  given: {
135
145
  (text: string, docs?: StoryDocs): void;
136
146
  (text: string, children: DocEntry[]): void;
137
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
147
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
138
148
  };
139
149
  when: {
140
150
  (text: string, docs?: StoryDocs): void;
141
151
  (text: string, children: DocEntry[]): void;
142
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
152
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
143
153
  };
144
154
  then: {
145
155
  (text: string, docs?: StoryDocs): void;
146
156
  (text: string, children: DocEntry[]): void;
147
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
157
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
148
158
  };
149
159
  and: {
150
160
  (text: string, docs?: StoryDocs): void;
151
161
  (text: string, children: DocEntry[]): void;
152
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
162
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
153
163
  };
154
164
  but: {
155
165
  (text: string, docs?: StoryDocs): void;
156
166
  (text: string, children: DocEntry[]): void;
157
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
167
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
158
168
  };
159
169
  arrange: {
160
170
  (text: string, docs?: StoryDocs): void;
161
171
  (text: string, children: DocEntry[]): void;
162
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
172
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
163
173
  };
164
174
  act: {
165
175
  (text: string, docs?: StoryDocs): void;
166
176
  (text: string, children: DocEntry[]): void;
167
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
177
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
168
178
  };
169
179
  assert: {
170
180
  (text: string, docs?: StoryDocs): void;
171
181
  (text: string, children: DocEntry[]): void;
172
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
182
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
173
183
  };
174
184
  setup: {
175
185
  (text: string, docs?: StoryDocs): void;
176
186
  (text: string, children: DocEntry[]): void;
177
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
187
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
178
188
  };
179
189
  context: {
180
190
  (text: string, docs?: StoryDocs): void;
181
191
  (text: string, children: DocEntry[]): void;
182
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
192
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
183
193
  };
184
194
  execute: {
185
195
  (text: string, docs?: StoryDocs): void;
186
196
  (text: string, children: DocEntry[]): void;
187
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
197
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
188
198
  };
189
199
  action: {
190
200
  (text: string, docs?: StoryDocs): void;
191
201
  (text: string, children: DocEntry[]): void;
192
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
202
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
193
203
  };
194
204
  verify: {
195
205
  (text: string, docs?: StoryDocs): void;
196
206
  (text: string, children: DocEntry[]): void;
197
- <T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;
207
+ <T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;
198
208
  };
199
209
  note(text: string, children?: DocEntry[]): DocEntry;
200
210
  tag(name: string | string[], children?: DocEntry[]): DocEntry;
@@ -207,6 +217,21 @@ declare const story: {
207
217
  mermaid(options: MermaidOptions, children?: DocEntry[]): DocEntry;
208
218
  screenshot(options: ScreenshotOptions, children?: DocEntry[]): DocEntry;
209
219
  custom(options: CustomOptions, children?: DocEntry[]): DocEntry;
220
+ /**
221
+ * Snapshot the current page console messages (and optionally page errors)
222
+ * and attach them as a code doc entry.
223
+ *
224
+ * Uses page.consoleMessages() and page.pageErrors() introduced in Playwright v1.56.
225
+ * Safe to call on any Playwright version – silently produces empty output if the
226
+ * APIs are not present.
227
+ *
228
+ * @example
229
+ * story.when('the form is submitted', async ({ page }) => {
230
+ * await page.click('#submit');
231
+ * story.console({ page, label: 'Submit console output' });
232
+ * });
233
+ */
234
+ console(options: ConsoleOptions, children?: DocEntry[]): DocEntry;
210
235
  attach: typeof playwrightAttach;
211
236
  attachSpans(spans: ReadonlyArray<Record<string, unknown>>): void;
212
237
  startTimer(): number;
@@ -219,27 +244,27 @@ type Story = typeof story;
219
244
  declare const given: {
220
245
  (text: string, docs?: StoryDocs): void;
221
246
  (text: string, children: executable_stories_formatters.DocEntry[]): void;
222
- <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>) => T): T;
247
+ <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>, step?: _playwright_test.TestStepInfo) => T): T;
223
248
  };
224
249
  declare const when: {
225
250
  (text: string, docs?: StoryDocs): void;
226
251
  (text: string, children: executable_stories_formatters.DocEntry[]): void;
227
- <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>) => T): T;
252
+ <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>, step?: _playwright_test.TestStepInfo) => T): T;
228
253
  };
229
254
  declare const then: {
230
255
  (text: string, docs?: StoryDocs): void;
231
256
  (text: string, children: executable_stories_formatters.DocEntry[]): void;
232
- <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>) => T): T;
257
+ <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>, step?: _playwright_test.TestStepInfo) => T): T;
233
258
  };
234
259
  declare const and: {
235
260
  (text: string, docs?: StoryDocs): void;
236
261
  (text: string, children: executable_stories_formatters.DocEntry[]): void;
237
- <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>) => T): T;
262
+ <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>, step?: _playwright_test.TestStepInfo) => T): T;
238
263
  };
239
264
  declare const but: {
240
265
  (text: string, docs?: StoryDocs): void;
241
266
  (text: string, children: executable_stories_formatters.DocEntry[]): void;
242
- <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>) => T): T;
267
+ <T>(text: string, body: (fixtures: _playwright_test.PlaywrightTestArgs & _playwright_test.PlaywrightTestOptions & Record<string, unknown>, step?: _playwright_test.TestStepInfo) => T): T;
243
268
  };
244
269
 
245
- export { type CodeOptions, type CustomOptions, type JsonOptions, type KvOptions, type LinkOptions, type MermaidOptions, type ScreenshotOptions, type SectionOptions, type Story, type StoryDocs, type StoryOptions, type TableOptions, type TicketInput, and, but, given, story, then, when };
270
+ export { type AttachmentOptions, type CodeOptions, type ConsoleOptions, type CustomOptions, type JsonOptions, type KvOptions, type LinkOptions, type MermaidOptions, type ScreenshotOptions, type SectionOptions, type Story, type StoryDocs, type StoryOptions, type TableOptions, type TicketInput, and, but, given, story, then, when };
package/dist/index.js CHANGED
@@ -4,6 +4,41 @@ import {
4
4
  tryGetActiveOtelContext,
5
5
  resolveTraceUrl
6
6
  } from "executable-stories-formatters";
7
+
8
+ // src/step-runner.ts
9
+ import { test } from "@playwright/test";
10
+ async function runStep(label, body, fixtures) {
11
+ const page = fixtures.page;
12
+ const context = fixtures.context ?? (typeof page?.context === "function" ? page.context() : void 0);
13
+ const screencast = page?.screencast;
14
+ if (screencast?.showChapter) {
15
+ try {
16
+ await screencast.showChapter(label);
17
+ } catch {
18
+ }
19
+ }
20
+ return test.step(label, async (stepInfo) => {
21
+ const tracing = context?.tracing;
22
+ if (tracing?.group) {
23
+ let bodyInvoked = false;
24
+ try {
25
+ return await tracing.group(label, async () => {
26
+ bodyInvoked = true;
27
+ return body(fixtures, stepInfo);
28
+ });
29
+ } catch (e) {
30
+ if (bodyInvoked) throw e;
31
+ return body(fixtures, stepInfo);
32
+ }
33
+ }
34
+ return body(fixtures, stepInfo);
35
+ });
36
+ }
37
+ function isAsyncFunction(fn2) {
38
+ return typeof fn2 === "function" && fn2.constructor?.name === "AsyncFunction";
39
+ }
40
+
41
+ // src/story-api.ts
7
42
  var activeContext = null;
8
43
  var activeTestInfo = null;
9
44
  var sourceOrderCounter = 0;
@@ -169,7 +204,29 @@ function createStepMarker(keyword) {
169
204
  }
170
205
  if (!isCallback) return;
171
206
  const body = docsOrBody;
207
+ const label = `${step.keyword}: ${text}`;
172
208
  const start = performance.now();
209
+ if (ctx.fixtures !== void 0 && (isAsyncFunction(body) || body.length >= 2)) {
210
+ const fixtures = ctx.fixtures;
211
+ const result = runStep(
212
+ label,
213
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
214
+ body,
215
+ fixtures
216
+ );
217
+ return result.then(
218
+ (val) => {
219
+ step.durationMs = performance.now() - start;
220
+ syncAnnotationToTest();
221
+ return val;
222
+ },
223
+ (err) => {
224
+ step.durationMs = performance.now() - start;
225
+ syncAnnotationToTest();
226
+ throw err;
227
+ }
228
+ );
229
+ }
173
230
  try {
174
231
  const result = ctx.fixtures !== void 0 ? body(ctx.fixtures) : body();
175
232
  if (result instanceof Promise) {
@@ -252,6 +309,9 @@ function init(first, second, third) {
252
309
  type: "story-meta",
253
310
  description: JSON.stringify(meta)
254
311
  });
312
+ for (const tag of options?.tags ?? []) {
313
+ testInfo.annotations.push({ type: "tag", description: tag });
314
+ }
255
315
  activeContext = {
256
316
  meta,
257
317
  currentStep: null,
@@ -386,6 +446,45 @@ var story = {
386
446
  custom(options, children) {
387
447
  return attachDoc({ kind: "custom", type: options.type, data: options.data, phase: "runtime" }, children);
388
448
  },
449
+ // ── Feature: Console capture (v1.56) ────────────────────────────────────
450
+ /**
451
+ * Snapshot the current page console messages (and optionally page errors)
452
+ * and attach them as a code doc entry.
453
+ *
454
+ * Uses page.consoleMessages() and page.pageErrors() introduced in Playwright v1.56.
455
+ * Safe to call on any Playwright version – silently produces empty output if the
456
+ * APIs are not present.
457
+ *
458
+ * @example
459
+ * story.when('the form is submitted', async ({ page }) => {
460
+ * await page.click('#submit');
461
+ * story.console({ page, label: 'Submit console output' });
462
+ * });
463
+ */
464
+ console(options, children) {
465
+ const p = options.page;
466
+ const lines = [];
467
+ if (typeof p?.consoleMessages === "function") {
468
+ for (const msg of p.consoleMessages()) {
469
+ lines.push(`[${msg.type()}] ${msg.text()}`);
470
+ }
471
+ }
472
+ if (options.includeErrors === true && typeof p?.pageErrors === "function") {
473
+ for (const err of p.pageErrors()) {
474
+ lines.push(`[error] ${err.message}`);
475
+ }
476
+ }
477
+ return attachDoc(
478
+ {
479
+ kind: "code",
480
+ label: options.label ?? "Console",
481
+ content: lines.length > 0 ? lines.join("\n") : "(no console output)",
482
+ lang: "log",
483
+ phase: "runtime"
484
+ },
485
+ children
486
+ );
487
+ },
389
488
  // Attachments
390
489
  attach: playwrightAttach,
391
490
  // OTel span attachment
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/story-api.ts","../src/index.ts"],"sourcesContent":["/**\n * Playwright story.* API for executable-stories.\n *\n * Uses native Playwright test() with opt-in documentation:\n *\n * @example\n * ```ts\n * import { test, expect } from '@playwright/test';\n * import { story } from 'executable-stories-playwright';\n *\n * test.describe('Calculator', () => {\n * test('adds two numbers', async ({ page }, testInfo) => {\n * story.init(testInfo);\n *\n * story.given('two numbers 5 and 3');\n * const a = 5;\n * const b = 3;\n *\n * story.when('I add them together');\n * const result = a + b;\n *\n * story.then('the result is 8');\n * expect(result).toBe(8);\n * });\n * });\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { TestInfo, PlaywrightTestArgs, PlaywrightTestOptions } from '@playwright/test';\nimport {\n tryGetActiveOtelContext,\n resolveTraceUrl,\n} from 'executable-stories-formatters';\nimport type {\n StepKeyword,\n StoryMeta,\n StoryStep,\n DocEntry,\n NormalizedTicket,\n TicketInput,\n} from './types';\nimport type {\n StoryDocs,\n StoryOptions,\n AttachmentOptions,\n ScopedAttachment,\n KvOptions,\n JsonOptions,\n CodeOptions,\n TableOptions,\n LinkOptions,\n SectionOptions,\n MermaidOptions,\n ScreenshotOptions,\n CustomOptions,\n} from './types';\n\n// Re-export types for consumers\nexport type {\n StoryMeta,\n StoryStep,\n DocEntry,\n StepKeyword,\n StoryDocs,\n StoryOptions,\n AttachmentOptions,\n} from './types';\n\n// ============================================================================\n// Internal types\n// ============================================================================\n\n/** Fixture type for step callbacks: Playwright test args + options; custom extend() fixtures as unknown. */\ntype PlaywrightFixtures = PlaywrightTestArgs & PlaywrightTestOptions & Record<string, unknown>;\n\ninterface TimerEntry {\n start: number;\n stepIndex?: number;\n stepId?: string;\n consumed: boolean;\n}\n\ninterface StoryContext {\n meta: StoryMeta;\n currentStep: StoryStep | null;\n stepCounter: number;\n attachments: ScopedAttachment[];\n activeTimers: Map<number, TimerEntry>;\n timerCounter: number;\n fixtures?: Record<string, unknown>;\n}\n\n// ============================================================================\n// Playwright-specific context\n// ============================================================================\n\n/** Active story context - set by story.init() */\nlet activeContext: StoryContext | null = null;\n\n/** Reference to testInfo for attaching metadata */\nlet activeTestInfo: TestInfo | null = null;\n\n/** Counter to track source order of stories (increments on each story.init call) */\nlet sourceOrderCounter = 0;\n\n/**\n * Get the current story context. Throws if story.init() wasn't called.\n */\nfunction getContext(): StoryContext {\n if (!activeContext) {\n throw new Error(\n \"story.init(testInfo) must be called first. Use: test('name', async ({ page }, testInfo) => { story.init(testInfo); ... });\",\n );\n }\n return activeContext;\n}\n\n// ============================================================================\n// Helper functions (inlined from core)\n// ============================================================================\n\nfunction normalizeTickets(\n ticket: TicketInput | TicketInput[] | undefined,\n): NormalizedTicket[] | undefined {\n if (!ticket) return undefined;\n const arr = Array.isArray(ticket) ? ticket : [ticket];\n return arr.map((t) => (typeof t === 'string' ? { id: t } : t));\n}\n\nfunction convertStoryDocsToEntries(docs: StoryDocs): DocEntry[] {\n const entries: DocEntry[] = [];\n\n if (docs.note) {\n entries.push({ kind: 'note', text: docs.note, phase: 'runtime' });\n }\n if (docs.tag) {\n const names = Array.isArray(docs.tag) ? docs.tag : [docs.tag];\n entries.push({ kind: 'tag', names, phase: 'runtime' });\n }\n if (docs.kv) {\n for (const [label, value] of Object.entries(docs.kv)) {\n entries.push({ kind: 'kv', label, value, phase: 'runtime' });\n }\n }\n if (docs.code) {\n entries.push({\n kind: 'code',\n label: docs.code.label,\n content: docs.code.content,\n lang: docs.code.lang,\n phase: 'runtime',\n });\n }\n if (docs.json) {\n entries.push({\n kind: 'code',\n label: docs.json.label,\n content: JSON.stringify(docs.json.value, null, 2),\n lang: 'json',\n phase: 'runtime',\n });\n }\n if (docs.table) {\n entries.push({\n kind: 'table',\n label: docs.table.label,\n columns: docs.table.columns,\n rows: docs.table.rows,\n phase: 'runtime',\n });\n }\n if (docs.link) {\n entries.push({\n kind: 'link',\n label: docs.link.label,\n url: docs.link.url,\n phase: 'runtime',\n });\n }\n if (docs.section) {\n entries.push({\n kind: 'section',\n title: docs.section.title,\n markdown: docs.section.markdown,\n phase: 'runtime',\n });\n }\n if (docs.mermaid) {\n entries.push({\n kind: 'mermaid',\n code: docs.mermaid.code,\n title: docs.mermaid.title,\n phase: 'runtime',\n });\n }\n if (docs.screenshot) {\n entries.push({\n kind: 'screenshot',\n path: docs.screenshot.path,\n alt: docs.screenshot.alt,\n phase: 'runtime',\n });\n }\n if (docs.custom) {\n entries.push({\n kind: 'custom',\n type: docs.custom.type,\n data: docs.custom.data,\n phase: 'runtime',\n });\n }\n\n return entries;\n}\n\nfunction attachDoc(entry: DocEntry, children?: DocEntry[]): DocEntry {\n const ctx = getContext();\n if (children && children.length > 0) {\n entry.children = children;\n const childSet = new Set<DocEntry>(children);\n const filterDocs = (docs: DocEntry[]) => docs.filter((d) => !childSet.has(d));\n // Remove children from ALL containers (story-level + every step)\n ctx.meta.docs = filterDocs(ctx.meta.docs ?? []);\n for (const step of ctx.meta.steps) {\n if (step.docs) step.docs = filterDocs(step.docs);\n }\n }\n if (ctx.currentStep) {\n ctx.currentStep.docs ??= [];\n ctx.currentStep.docs.push(entry);\n } else {\n ctx.meta.docs ??= [];\n ctx.meta.docs.push(entry);\n }\n syncAnnotationToTest();\n return entry;\n}\n\n// ============================================================================\n// Suite path extraction\n// ============================================================================\n\n/**\n * Extract the suite path from testInfo.titlePath.\n * Playwright's titlePath includes: [projectName, ...describeTitles, testTitle]\n * We want just the describe titles (excluding project and test name).\n */\nfunction extractSuitePath(testInfo: TestInfo): string[] | undefined {\n const titlePath = testInfo.titlePath;\n if (titlePath.length <= 2) {\n return undefined;\n }\n const suitePath = titlePath.slice(1, -1);\n return suitePath.length > 0 ? suitePath : undefined;\n}\n\n// ============================================================================\n// Step markers\n// ============================================================================\n\nfunction createStepMarker(keyword: StepKeyword) {\n function stepMarker(text: string, docs?: StoryDocs): void;\n function stepMarker(text: string, children: DocEntry[]): void;\n function stepMarker<T>(text: string, body: (fixtures: PlaywrightFixtures) => T): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function stepMarker<T>(text: string, docsOrBody?: StoryDocs | DocEntry[] | ((...args: any[]) => T)): T | void {\n const ctx = getContext();\n const isCallback = typeof docsOrBody === 'function';\n const isChildrenArray = Array.isArray(docsOrBody);\n\n const resolvedKeyword: StepKeyword =\n (keyword === 'Given' || keyword === 'When' || keyword === 'Then') &&\n ctx.meta.steps.some((s) => s.keyword === keyword)\n ? 'And'\n : keyword;\n\n let stepDocs: DocEntry[] = [];\n if (!isCallback && !isChildrenArray && docsOrBody) {\n stepDocs = convertStoryDocsToEntries(docsOrBody as StoryDocs);\n }\n\n const step: StoryStep = {\n id: `step-${ctx.stepCounter++}`,\n keyword: resolvedKeyword,\n text,\n docs: stepDocs,\n ...(isCallback ? { wrapped: true } : {}),\n };\n\n ctx.meta.steps.push(step);\n ctx.currentStep = step;\n syncAnnotationToTest();\n\n // Handle DocEntry[] children: attach as step docs and deduplicate from story-level\n if (isChildrenArray) {\n const children = docsOrBody as DocEntry[];\n if (children.length > 0) {\n const childSet = new Set<DocEntry>(children);\n // Deduplicate from story-level docs\n ctx.meta.docs = (ctx.meta.docs ?? []).filter((d) => !childSet.has(d));\n // Deduplicate from step docs of earlier steps\n for (const prevStep of ctx.meta.steps) {\n if (prevStep !== step && prevStep.docs) {\n prevStep.docs = prevStep.docs.filter((d) => !childSet.has(d));\n }\n }\n step.docs = [...(step.docs ?? []), ...children];\n }\n syncAnnotationToTest();\n return;\n }\n\n if (!isCallback) return;\n\n const body = docsOrBody as (fixtures?: PlaywrightFixtures) => T;\n const start = performance.now();\n\n try {\n const result = ctx.fixtures !== undefined ? body(ctx.fixtures as PlaywrightFixtures) : body();\n if (result instanceof Promise) {\n return result.then(\n (val) => { step.durationMs = performance.now() - start; syncAnnotationToTest(); return val; },\n (err) => { step.durationMs = performance.now() - start; syncAnnotationToTest(); throw err; },\n ) as T;\n }\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n return result;\n } catch (err) {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n throw err;\n }\n }\n return stepMarker;\n}\n\n// ============================================================================\n// story.init() - Playwright-specific\n// ============================================================================\n\nfunction isTestInfo(x: unknown): x is TestInfo {\n return (\n typeof x === 'object' &&\n x !== null &&\n 'title' in x &&\n 'annotations' in x &&\n Array.isArray((x as TestInfo).annotations)\n );\n}\n\n/** init(testInfo) or init(fixtures, testInfo) or init(testInfo, { fixtures }). */\nfunction init(\n first: TestInfo | unknown,\n second?: StoryOptions | TestInfo,\n third?: StoryOptions,\n): void {\n let testInfo: TestInfo;\n let options: StoryOptions | undefined;\n let fixtures: unknown;\n\n if (second !== undefined && isTestInfo(second)) {\n fixtures = first;\n testInfo = second;\n options = third;\n } else {\n testInfo = first as TestInfo;\n options = second;\n fixtures = options?.fixtures;\n }\n\n const meta: StoryMeta = {\n scenario: testInfo.title,\n steps: [],\n suitePath: extractSuitePath(testInfo),\n tags: options?.tags,\n tickets: normalizeTickets(options?.ticket),\n meta: options?.meta,\n sourceOrder: sourceOrderCounter++,\n };\n\n // OTel bridge: detect active span, flow data bidirectionally\n const otelCtx = tryGetActiveOtelContext();\n if (otelCtx) {\n // OTel -> Story: capture traceId in structured meta\n meta.meta = { ...meta.meta, otel: { traceId: otelCtx.traceId, spanId: otelCtx.spanId } };\n\n // OTel -> Story: inject human-readable doc entries\n meta.docs = meta.docs ?? [];\n meta.docs.push({ kind: 'kv', label: 'Trace ID', value: otelCtx.traceId, phase: 'runtime' });\n\n const template = options?.traceUrlTemplate ?? process.env.OTEL_TRACE_URL_TEMPLATE;\n const url = resolveTraceUrl(template, otelCtx.traceId);\n if (url) {\n meta.docs.push({ kind: 'link', label: 'View Trace', url, phase: 'runtime' });\n }\n\n // Story -> OTel: enrich active span with story attributes\n try {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const reqUrl = import.meta.url\n ?? (typeof __filename !== 'undefined' ? `file://${__filename}` : undefined);\n const req = createRequire(reqUrl!);\n const api = req('@opentelemetry/api');\n const span = api.trace?.getActiveSpan?.();\n if (span) {\n span.setAttribute('story.scenario', testInfo.title);\n if (options?.tags?.length) span.setAttribute('story.tags', options.tags);\n if (options?.ticket) {\n const tickets = Array.isArray(options.ticket) ? options.ticket : [options.ticket];\n span.setAttribute('story.tickets', tickets.map((t) => typeof t === 'string' ? t : t.id));\n }\n }\n } catch { /* OTel not available */ }\n }\n\n testInfo.annotations.push({\n type: 'story-meta',\n description: JSON.stringify(meta),\n });\n\n activeContext = {\n meta,\n currentStep: null,\n stepCounter: 0,\n attachments: [],\n activeTimers: new Map(),\n timerCounter: 0,\n fixtures: fixtures as Record<string, unknown> | undefined,\n };\n activeTestInfo = testInfo;\n}\n\n/**\n * Update the story-meta annotation on testInfo with the current meta (including steps).\n * Called after each step/doc so the reporter sees the full story in onTestEnd.\n */\nfunction syncAnnotationToTest(): void {\n if (!activeTestInfo || !activeContext) return;\n const annotation = activeTestInfo.annotations.find(\n (a) => a.type === 'story-meta',\n );\n if (annotation) {\n annotation.description = JSON.stringify(activeContext.meta);\n }\n}\n\n// ============================================================================\n// story.fn() and story.expect()\n// ============================================================================\n\n/**\n * Wrap a function as a step with timing and error capture.\n * Records the step with `wrapped: true` and `durationMs`.\n */\nfunction fn<T>(keyword: StepKeyword, text: string, body: (fixtures: PlaywrightFixtures) => T): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction fn<T>(keyword: StepKeyword, text: string, body: (...args: any[]) => T): T {\n const ctx = getContext();\n const resolvedKeyword: StepKeyword =\n (keyword === 'Given' || keyword === 'When' || keyword === 'Then') &&\n ctx.meta.steps.some((s) => s.keyword === keyword)\n ? 'And'\n : keyword;\n const step: StoryStep = {\n id: `step-${ctx.stepCounter++}`,\n keyword: resolvedKeyword,\n text,\n docs: [],\n wrapped: true,\n };\n ctx.meta.steps.push(step);\n ctx.currentStep = step;\n syncAnnotationToTest();\n\n const start = performance.now();\n try {\n const result = ctx.fixtures !== undefined ? body(ctx.fixtures as PlaywrightFixtures) : body();\n if (result instanceof Promise) {\n return result.then(\n (val) => {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n return val;\n },\n (err) => {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n throw err;\n },\n ) as T;\n }\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n return result;\n } catch (err) {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n throw err;\n }\n}\n\n/**\n * Wrap an assertion as a Then step with timing and error capture.\n * Shorthand for `story.fn('Then', text, body)`.\n */\nfunction storyExpect<T>(text: string, body: () => T): T {\n return fn('Then', text, body);\n}\n\n// ============================================================================\n// Playwright-specific attach\n// ============================================================================\n\nfunction playwrightAttach(options: AttachmentOptions): void {\n const ctx = getContext();\n const stepIndex = ctx.currentStep\n ? ctx.meta.steps.indexOf(ctx.currentStep)\n : undefined;\n ctx.attachments.push({\n ...options,\n stepId: ctx.currentStep?.id,\n });\n syncAnnotationToTest();\n\n if (activeTestInfo) {\n const attachOptions: { name: string; contentType: string; path?: string; body?: string | Buffer } = {\n name: options.name,\n contentType: options.mediaType,\n };\n if (options.path) attachOptions.path = options.path;\n if (options.body) attachOptions.body = options.body;\n activeTestInfo.attach(options.name, attachOptions);\n }\n}\n\n// ============================================================================\n// Export story object\n// ============================================================================\n\nexport const story = {\n init,\n\n // BDD step markers\n given: createStepMarker('Given'),\n when: createStepMarker('When'),\n then: createStepMarker('Then'),\n and: createStepMarker('And'),\n but: createStepMarker('But'),\n\n // AAA pattern aliases\n arrange: createStepMarker('Given'),\n act: createStepMarker('When'),\n assert: createStepMarker('Then'),\n\n // Additional aliases\n setup: createStepMarker('Given'),\n context: createStepMarker('Given'),\n execute: createStepMarker('When'),\n action: createStepMarker('When'),\n verify: createStepMarker('Then'),\n\n // Standalone doc methods\n note(text: string, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'note', text, phase: 'runtime' }, children);\n },\n\n tag(name: string | string[], children?: DocEntry[]): DocEntry {\n const names = Array.isArray(name) ? name : [name];\n return attachDoc({ kind: 'tag', names, phase: 'runtime' }, children);\n },\n\n kv(options: KvOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'kv', label: options.label, value: options.value, phase: 'runtime' }, children);\n },\n\n json(options: JsonOptions, children?: DocEntry[]): DocEntry {\n const content = JSON.stringify(options.value, null, 2);\n return attachDoc({ kind: 'code', label: options.label, content, lang: 'json', phase: 'runtime' }, children);\n },\n\n code(options: CodeOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'code', label: options.label, content: options.content, lang: options.lang, phase: 'runtime' }, children);\n },\n\n table(options: TableOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'table', label: options.label, columns: options.columns, rows: options.rows, phase: 'runtime' }, children);\n },\n\n link(options: LinkOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'link', label: options.label, url: options.url, phase: 'runtime' }, children);\n },\n\n section(options: SectionOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'section', title: options.title, markdown: options.markdown, phase: 'runtime' }, children);\n },\n\n mermaid(options: MermaidOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'mermaid', code: options.code, title: options.title, phase: 'runtime' }, children);\n },\n\n screenshot(options: ScreenshotOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'screenshot', path: options.path, alt: options.alt, phase: 'runtime' }, children);\n },\n\n custom(options: CustomOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'custom', type: options.type, data: options.data, phase: 'runtime' }, children);\n },\n\n // Attachments\n attach: playwrightAttach,\n\n // OTel span attachment\n attachSpans(spans: ReadonlyArray<Record<string, unknown>>): void {\n if (!activeTestInfo) return;\n const existing = activeTestInfo.annotations.find(\n (a) => a.type === 'story-otel-spans',\n );\n const description = JSON.stringify(spans);\n if (existing) {\n existing.description = description;\n } else {\n activeTestInfo.annotations.push({\n type: 'story-otel-spans',\n description,\n });\n }\n },\n\n // Step timing\n startTimer(): number {\n const ctx = getContext();\n const token = ctx.timerCounter++;\n const stepIndex = ctx.currentStep\n ? ctx.meta.steps.indexOf(ctx.currentStep)\n : undefined;\n ctx.activeTimers.set(token, {\n start: performance.now(),\n stepIndex: stepIndex !== undefined && stepIndex >= 0 ? stepIndex : undefined,\n stepId: ctx.currentStep?.id,\n consumed: false,\n });\n syncAnnotationToTest();\n return token;\n },\n\n endTimer(token: number): void {\n const ctx = getContext();\n const entry = ctx.activeTimers.get(token);\n if (!entry || entry.consumed) return;\n\n entry.consumed = true;\n const durationMs = performance.now() - entry.start;\n\n let step: StoryStep | undefined;\n if (entry.stepId) {\n step = ctx.meta.steps.find((s) => s.id === entry.stepId);\n }\n if (!step && entry.stepIndex !== undefined) {\n step = ctx.meta.steps[entry.stepIndex];\n }\n\n if (step) {\n step.durationMs = durationMs;\n }\n syncAnnotationToTest();\n },\n\n // Step wrappers\n fn,\n expect: storyExpect,\n};\n\nexport type Story = typeof story;\n","/**\n * Playwright Executable Stories\n *\n * BDD-style executable documentation for Playwright Test.\n *\n * @example\n * ```ts\n * import { test, expect } from '@playwright/test';\n * import { story } from 'executable-stories-playwright';\n *\n * test.describe('Calculator', () => {\n * test('adds two numbers', async ({ page }, testInfo) => {\n * story.init(testInfo);\n *\n * story.given('two numbers 5 and 3');\n * const a = 5;\n * const b = 3;\n *\n * story.when('I add them together');\n * const result = a + b;\n *\n * story.then('the result is 8');\n * expect(result).toBe(8);\n * });\n * });\n * ```\n */\n\n// Story API\nimport { story } from './story-api';\nexport { story };\nexport type { Story } from './story-api';\n\n// Top-level step helpers (framework contract)\nexport const given = story.given;\nexport const when = story.when;\nexport const then = story.then;\nexport const and = story.and;\nexport const but = story.but;\n\n// Re-export types from local types module\nexport type {\n StoryMeta,\n StoryStep,\n DocEntry,\n StepKeyword,\n StoryDocs,\n StoryOptions,\n TicketInput,\n NormalizedTicket,\n KvOptions,\n JsonOptions,\n CodeOptions,\n TableOptions,\n LinkOptions,\n SectionOptions,\n MermaidOptions,\n ScreenshotOptions,\n CustomOptions,\n} from './types';\n"],"mappings":";AA4BA,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAiEP,IAAI,gBAAqC;AAGzC,IAAI,iBAAkC;AAGtC,IAAI,qBAAqB;AAKzB,SAAS,aAA2B;AAClC,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAMA,SAAS,iBACP,QACgC;AAChC,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,MAAM,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACpD,SAAO,IAAI,IAAI,CAAC,MAAO,OAAO,MAAM,WAAW,EAAE,IAAI,EAAE,IAAI,CAAE;AAC/D;AAEA,SAAS,0BAA0B,MAA6B;AAC9D,QAAM,UAAsB,CAAC;AAE7B,MAAI,KAAK,MAAM;AACb,YAAQ,KAAK,EA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AAQ;AAChB,aAAO,IAAI,KAAK,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,MAAM;AAAA,IACzD;AACA,QAAI,CAAC,QAAQ,MAAM,cAAc,QAAW;AAC1C,aAAO,IAAI,KAAK,MAAM,MAAM,SAAS;AAAA,IACvC;AAEA,QAAI,MAAM;AACR,WAAK,aAAa;AAAA,IACpB;AACA,yBAAqB;AAAA,EACvB;AAAA;AAAA,EAGA;AAAA,EACA,QAAQ;AACV;;;AC9nBO,IAAM,QAAQ,MAAM;AACpB,IAAM,OAAO,MAAM;AACnB,IAAM,OAAO,MAAM;AACnB,IAAM,MAAM,MAAM;AAClB,IAAM,MAAM,MAAM;","names":[]}
1
+ {"version":3,"sources":["../src/story-api.ts","../src/step-runner.ts","../src/index.ts"],"sourcesContent":["/**\n * Playwright story.* API for executable-stories.\n *\n * Uses native Playwright test() with opt-in documentation:\n *\n * @example\n * ```ts\n * import { test, expect } from '@playwright/test';\n * import { story } from 'executable-stories-playwright';\n *\n * test.describe('Calculator', () => {\n * test('adds two numbers', async ({ page }, testInfo) => {\n * story.init(testInfo);\n *\n * story.given('two numbers 5 and 3');\n * const a = 5;\n * const b = 3;\n *\n * story.when('I add them together');\n * const result = a + b;\n *\n * story.then('the result is 8');\n * expect(result).toBe(8);\n * });\n * });\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { TestInfo, PlaywrightTestArgs, PlaywrightTestOptions } from '@playwright/test';\nimport {\n tryGetActiveOtelContext,\n resolveTraceUrl,\n} from 'executable-stories-formatters';\nimport type {\n StepKeyword,\n StoryMeta,\n StoryStep,\n DocEntry,\n NormalizedTicket,\n TicketInput,\n} from './types';\nimport type {\n StoryDocs,\n StoryOptions,\n AttachmentOptions,\n ScopedAttachment,\n KvOptions,\n JsonOptions,\n CodeOptions,\n TableOptions,\n LinkOptions,\n SectionOptions,\n MermaidOptions,\n ScreenshotOptions,\n CustomOptions,\n ConsoleOptions,\n} from './types';\nimport { runStep, isAsyncFunction } from './step-runner';\nimport type { TestStepInfo } from './step-runner';\n\n// Re-export types for consumers\nexport type {\n StoryMeta,\n StoryStep,\n DocEntry,\n StepKeyword,\n StoryDocs,\n StoryOptions,\n AttachmentOptions,\n} from './types';\n\n// ============================================================================\n// Internal types\n// ============================================================================\n\n/** Fixture type for step callbacks: Playwright test args + options; custom extend() fixtures as unknown. */\ntype PlaywrightFixtures = PlaywrightTestArgs & PlaywrightTestOptions & Record<string, unknown>;\n\ninterface TimerEntry {\n start: number;\n stepIndex?: number;\n stepId?: string;\n consumed: boolean;\n}\n\ninterface StoryContext {\n meta: StoryMeta;\n currentStep: StoryStep | null;\n stepCounter: number;\n attachments: ScopedAttachment[];\n activeTimers: Map<number, TimerEntry>;\n timerCounter: number;\n fixtures?: Record<string, unknown>;\n}\n\n// ============================================================================\n// Playwright-specific context\n// ============================================================================\n\n/** Active story context - set by story.init() */\nlet activeContext: StoryContext | null = null;\n\n/** Reference to testInfo for attaching metadata */\nlet activeTestInfo: TestInfo | null = null;\n\n/** Counter to track source order of stories (increments on each story.init call) */\nlet sourceOrderCounter = 0;\n\n/**\n * Get the current story context. Throws if story.init() wasn't called.\n */\nfunction getContext(): StoryContext {\n if (!activeContext) {\n throw new Error(\n \"story.init(testInfo) must be called first. Use: test('name', async ({ page }, testInfo) => { story.init(testInfo); ... });\",\n );\n }\n return activeContext;\n}\n\n// ============================================================================\n// Helper functions (inlined from core)\n// ============================================================================\n\nfunction normalizeTickets(\n ticket: TicketInput | TicketInput[] | undefined,\n): NormalizedTicket[] | undefined {\n if (!ticket) return undefined;\n const arr = Array.isArray(ticket) ? ticket : [ticket];\n return arr.map((t) => (typeof t === 'string' ? { id: t } : t));\n}\n\nfunction convertStoryDocsToEntries(docs: StoryDocs): DocEntry[] {\n const entries: DocEntry[] = [];\n\n if (docs.note) {\n entries.push({ kind: 'note', text: docs.note, phase: 'runtime' });\n }\n if (docs.tag) {\n const names = Array.isArray(docs.tag) ? docs.tag : [docs.tag];\n entries.push({ kind: 'tag', names, phase: 'runtime' });\n }\n if (docs.kv) {\n for (const [label, value] of Object.entries(docs.kv)) {\n entries.push({ kind: 'kv', label, value, phase: 'runtime' });\n }\n }\n if (docs.code) {\n entries.push({\n kind: 'code',\n label: docs.code.label,\n content: docs.code.content,\n lang: docs.code.lang,\n phase: 'runtime',\n });\n }\n if (docs.json) {\n entries.push({\n kind: 'code',\n label: docs.json.label,\n content: JSON.stringify(docs.json.value, null, 2),\n lang: 'json',\n phase: 'runtime',\n });\n }\n if (docs.table) {\n entries.push({\n kind: 'table',\n label: docs.table.label,\n columns: docs.table.columns,\n rows: docs.table.rows,\n phase: 'runtime',\n });\n }\n if (docs.link) {\n entries.push({\n kind: 'link',\n label: docs.link.label,\n url: docs.link.url,\n phase: 'runtime',\n });\n }\n if (docs.section) {\n entries.push({\n kind: 'section',\n title: docs.section.title,\n markdown: docs.section.markdown,\n phase: 'runtime',\n });\n }\n if (docs.mermaid) {\n entries.push({\n kind: 'mermaid',\n code: docs.mermaid.code,\n title: docs.mermaid.title,\n phase: 'runtime',\n });\n }\n if (docs.screenshot) {\n entries.push({\n kind: 'screenshot',\n path: docs.screenshot.path,\n alt: docs.screenshot.alt,\n phase: 'runtime',\n });\n }\n if (docs.custom) {\n entries.push({\n kind: 'custom',\n type: docs.custom.type,\n data: docs.custom.data,\n phase: 'runtime',\n });\n }\n\n return entries;\n}\n\nfunction attachDoc(entry: DocEntry, children?: DocEntry[]): DocEntry {\n const ctx = getContext();\n if (children && children.length > 0) {\n entry.children = children;\n const childSet = new Set<DocEntry>(children);\n const filterDocs = (docs: DocEntry[]) => docs.filter((d) => !childSet.has(d));\n // Remove children from ALL containers (story-level + every step)\n ctx.meta.docs = filterDocs(ctx.meta.docs ?? []);\n for (const step of ctx.meta.steps) {\n if (step.docs) step.docs = filterDocs(step.docs);\n }\n }\n if (ctx.currentStep) {\n ctx.currentStep.docs ??= [];\n ctx.currentStep.docs.push(entry);\n } else {\n ctx.meta.docs ??= [];\n ctx.meta.docs.push(entry);\n }\n syncAnnotationToTest();\n return entry;\n}\n\n// ============================================================================\n// Suite path extraction\n// ============================================================================\n\n/**\n * Extract the suite path from testInfo.titlePath.\n * Playwright's titlePath includes: [projectName, ...describeTitles, testTitle]\n * We want just the describe titles (excluding project and test name).\n */\nfunction extractSuitePath(testInfo: TestInfo): string[] | undefined {\n const titlePath = testInfo.titlePath;\n if (titlePath.length <= 2) {\n return undefined;\n }\n const suitePath = titlePath.slice(1, -1);\n return suitePath.length > 0 ? suitePath : undefined;\n}\n\n// ============================================================================\n// Step markers\n// ============================================================================\n\nfunction createStepMarker(keyword: StepKeyword) {\n function stepMarker(text: string, docs?: StoryDocs): void;\n function stepMarker(text: string, children: DocEntry[]): void;\n function stepMarker<T>(text: string, body: (fixtures: PlaywrightFixtures, step?: TestStepInfo) => T): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n function stepMarker<T>(text: string, docsOrBody?: StoryDocs | DocEntry[] | ((...args: any[]) => T)): T | void {\n const ctx = getContext();\n const isCallback = typeof docsOrBody === 'function';\n const isChildrenArray = Array.isArray(docsOrBody);\n\n const resolvedKeyword: StepKeyword =\n (keyword === 'Given' || keyword === 'When' || keyword === 'Then') &&\n ctx.meta.steps.some((s) => s.keyword === keyword)\n ? 'And'\n : keyword;\n\n let stepDocs: DocEntry[] = [];\n if (!isCallback && !isChildrenArray && docsOrBody) {\n stepDocs = convertStoryDocsToEntries(docsOrBody as StoryDocs);\n }\n\n const step: StoryStep = {\n id: `step-${ctx.stepCounter++}`,\n keyword: resolvedKeyword,\n text,\n docs: stepDocs,\n ...(isCallback ? { wrapped: true } : {}),\n };\n\n ctx.meta.steps.push(step);\n ctx.currentStep = step;\n syncAnnotationToTest();\n\n // Handle DocEntry[] children: attach as step docs and deduplicate from story-level\n if (isChildrenArray) {\n const children = docsOrBody as DocEntry[];\n if (children.length > 0) {\n const childSet = new Set<DocEntry>(children);\n // Deduplicate from story-level docs\n ctx.meta.docs = (ctx.meta.docs ?? []).filter((d) => !childSet.has(d));\n // Deduplicate from step docs of earlier steps\n for (const prevStep of ctx.meta.steps) {\n if (prevStep !== step && prevStep.docs) {\n prevStep.docs = prevStep.docs.filter((d) => !childSet.has(d));\n }\n }\n step.docs = [...(step.docs ?? []), ...children];\n }\n syncAnnotationToTest();\n return;\n }\n\n if (!isCallback) return;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const body = docsOrBody as (fixtures?: PlaywrightFixtures, stepInfo?: TestStepInfo) => T;\n const label = `${step.keyword}: ${text}`;\n const start = performance.now();\n\n // ── Async or stepInfo-aware callbacks: route through runStep() for Playwright-native integrations ──\n // Integrations: screencast chapters (v1.59), test.step/TestStepInfo (v1.51),\n // tracing.group (v1.49). Activated when fixtures are available AND either:\n // 1. callback is an async function, OR\n // 2. callback expects TestStepInfo (arity >= 2)\n if (ctx.fixtures !== undefined && (isAsyncFunction(body) || body.length >= 2)) {\n const fixtures = ctx.fixtures as Record<string, unknown>;\n const result = runStep(\n label,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n body as unknown as (fixtures: Record<string, unknown>, step?: TestStepInfo) => Promise<any>,\n fixtures,\n );\n return result.then(\n (val: T) => { step.durationMs = performance.now() - start; syncAnnotationToTest(); return val; },\n (err: unknown) => { step.durationMs = performance.now() - start; syncAnnotationToTest(); throw err; },\n ) as T;\n }\n\n // ── Sync callbacks or no-fixture context: existing behaviour ─────────────\n try {\n const result = ctx.fixtures !== undefined ? body(ctx.fixtures as PlaywrightFixtures) : body();\n if (result instanceof Promise) {\n return result.then(\n (val) => { step.durationMs = performance.now() - start; syncAnnotationToTest(); return val; },\n (err) => { step.durationMs = performance.now() - start; syncAnnotationToTest(); throw err; },\n ) as T;\n }\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n return result;\n } catch (err) {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n throw err;\n }\n }\n return stepMarker;\n}\n\n// ============================================================================\n// story.init() - Playwright-specific\n// ============================================================================\n\nfunction isTestInfo(x: unknown): x is TestInfo {\n return (\n typeof x === 'object' &&\n x !== null &&\n 'title' in x &&\n 'annotations' in x &&\n Array.isArray((x as TestInfo).annotations)\n );\n}\n\n/** init(testInfo) or init(fixtures, testInfo) or init(testInfo, { fixtures }). */\nfunction init(\n first: TestInfo | unknown,\n second?: StoryOptions | TestInfo,\n third?: StoryOptions,\n): void {\n let testInfo: TestInfo;\n let options: StoryOptions | undefined;\n let fixtures: unknown;\n\n if (second !== undefined && isTestInfo(second)) {\n fixtures = first;\n testInfo = second;\n options = third;\n } else {\n testInfo = first as TestInfo;\n options = second;\n fixtures = options?.fixtures;\n }\n\n const meta: StoryMeta = {\n scenario: testInfo.title,\n steps: [],\n suitePath: extractSuitePath(testInfo),\n tags: options?.tags,\n tickets: normalizeTickets(options?.ticket),\n meta: options?.meta,\n sourceOrder: sourceOrderCounter++,\n };\n\n // OTel bridge: detect active span, flow data bidirectionally\n const otelCtx = tryGetActiveOtelContext();\n if (otelCtx) {\n // OTel -> Story: capture traceId in structured meta\n meta.meta = { ...meta.meta, otel: { traceId: otelCtx.traceId, spanId: otelCtx.spanId } };\n\n // OTel -> Story: inject human-readable doc entries\n meta.docs = meta.docs ?? [];\n meta.docs.push({ kind: 'kv', label: 'Trace ID', value: otelCtx.traceId, phase: 'runtime' });\n\n const template = options?.traceUrlTemplate ?? process.env.OTEL_TRACE_URL_TEMPLATE;\n const url = resolveTraceUrl(template, otelCtx.traceId);\n if (url) {\n meta.docs.push({ kind: 'link', label: 'View Trace', url, phase: 'runtime' });\n }\n\n // Story -> OTel: enrich active span with story attributes\n try {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const reqUrl = import.meta.url\n ?? (typeof __filename !== 'undefined' ? `file://${__filename}` : undefined);\n const req = createRequire(reqUrl!);\n const api = req('@opentelemetry/api');\n const span = api.trace?.getActiveSpan?.();\n if (span) {\n span.setAttribute('story.scenario', testInfo.title);\n if (options?.tags?.length) span.setAttribute('story.tags', options.tags);\n if (options?.ticket) {\n const tickets = Array.isArray(options.ticket) ? options.ticket : [options.ticket];\n span.setAttribute('story.tickets', tickets.map((t) => typeof t === 'string' ? t : t.id));\n }\n }\n } catch { /* OTel not available */ }\n }\n\n testInfo.annotations.push({\n type: 'story-meta',\n description: JSON.stringify(meta),\n });\n\n // ── Feature: Tag sync (v1.43) ─────────────────────────────────────────────\n // Sync story tags to Playwright's native annotation system so they appear in\n // UI Mode tag filters and the HTML reporter's tag display.\n for (const tag of options?.tags ?? []) {\n testInfo.annotations.push({ type: 'tag', description: tag });\n }\n\n activeContext = {\n meta,\n currentStep: null,\n stepCounter: 0,\n attachments: [],\n activeTimers: new Map(),\n timerCounter: 0,\n fixtures: fixtures as Record<string, unknown> | undefined,\n };\n activeTestInfo = testInfo;\n}\n\n/**\n * Update the story-meta annotation on testInfo with the current meta (including steps).\n * Called after each step/doc so the reporter sees the full story in onTestEnd.\n */\nfunction syncAnnotationToTest(): void {\n if (!activeTestInfo || !activeContext) return;\n const annotation = activeTestInfo.annotations.find(\n (a) => a.type === 'story-meta',\n );\n if (annotation) {\n annotation.description = JSON.stringify(activeContext.meta);\n }\n}\n\n// ============================================================================\n// story.fn() and story.expect()\n// ============================================================================\n\n/**\n * Wrap a function as a step with timing and error capture.\n * Records the step with `wrapped: true` and `durationMs`.\n */\nfunction fn<T>(keyword: StepKeyword, text: string, body: (fixtures: PlaywrightFixtures) => T): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction fn<T>(keyword: StepKeyword, text: string, body: (...args: any[]) => T): T {\n const ctx = getContext();\n const resolvedKeyword: StepKeyword =\n (keyword === 'Given' || keyword === 'When' || keyword === 'Then') &&\n ctx.meta.steps.some((s) => s.keyword === keyword)\n ? 'And'\n : keyword;\n const step: StoryStep = {\n id: `step-${ctx.stepCounter++}`,\n keyword: resolvedKeyword,\n text,\n docs: [],\n wrapped: true,\n };\n ctx.meta.steps.push(step);\n ctx.currentStep = step;\n syncAnnotationToTest();\n\n const start = performance.now();\n try {\n const result = ctx.fixtures !== undefined ? body(ctx.fixtures as PlaywrightFixtures) : body();\n if (result instanceof Promise) {\n return result.then(\n (val) => {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n return val;\n },\n (err) => {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n throw err;\n },\n ) as T;\n }\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n return result;\n } catch (err) {\n step.durationMs = performance.now() - start;\n syncAnnotationToTest();\n throw err;\n }\n}\n\n/**\n * Wrap an assertion as a Then step with timing and error capture.\n * Shorthand for `story.fn('Then', text, body)`.\n */\nfunction storyExpect<T>(text: string, body: () => T): T {\n return fn('Then', text, body);\n}\n\n// ============================================================================\n// Playwright-specific attach\n// ============================================================================\n\nfunction playwrightAttach(options: AttachmentOptions): void {\n const ctx = getContext();\n const stepIndex = ctx.currentStep\n ? ctx.meta.steps.indexOf(ctx.currentStep)\n : undefined;\n ctx.attachments.push({\n ...options,\n stepId: ctx.currentStep?.id,\n });\n syncAnnotationToTest();\n\n if (activeTestInfo) {\n const attachOptions: { name: string; contentType: string; path?: string; body?: string | Buffer } = {\n name: options.name,\n contentType: options.mediaType,\n };\n if (options.path) attachOptions.path = options.path;\n if (options.body) attachOptions.body = options.body;\n activeTestInfo.attach(options.name, attachOptions);\n }\n}\n\n// ============================================================================\n// Export story object\n// ============================================================================\n\nexport const story = {\n init,\n\n // BDD step markers\n given: createStepMarker('Given'),\n when: createStepMarker('When'),\n then: createStepMarker('Then'),\n and: createStepMarker('And'),\n but: createStepMarker('But'),\n\n // AAA pattern aliases\n arrange: createStepMarker('Given'),\n act: createStepMarker('When'),\n assert: createStepMarker('Then'),\n\n // Additional aliases\n setup: createStepMarker('Given'),\n context: createStepMarker('Given'),\n execute: createStepMarker('When'),\n action: createStepMarker('When'),\n verify: createStepMarker('Then'),\n\n // Standalone doc methods\n note(text: string, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'note', text, phase: 'runtime' }, children);\n },\n\n tag(name: string | string[], children?: DocEntry[]): DocEntry {\n const names = Array.isArray(name) ? name : [name];\n return attachDoc({ kind: 'tag', names, phase: 'runtime' }, children);\n },\n\n kv(options: KvOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'kv', label: options.label, value: options.value, phase: 'runtime' }, children);\n },\n\n json(options: JsonOptions, children?: DocEntry[]): DocEntry {\n const content = JSON.stringify(options.value, null, 2);\n return attachDoc({ kind: 'code', label: options.label, content, lang: 'json', phase: 'runtime' }, children);\n },\n\n code(options: CodeOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'code', label: options.label, content: options.content, lang: options.lang, phase: 'runtime' }, children);\n },\n\n table(options: TableOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'table', label: options.label, columns: options.columns, rows: options.rows, phase: 'runtime' }, children);\n },\n\n link(options: LinkOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'link', label: options.label, url: options.url, phase: 'runtime' }, children);\n },\n\n section(options: SectionOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'section', title: options.title, markdown: options.markdown, phase: 'runtime' }, children);\n },\n\n mermaid(options: MermaidOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'mermaid', code: options.code, title: options.title, phase: 'runtime' }, children);\n },\n\n screenshot(options: ScreenshotOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'screenshot', path: options.path, alt: options.alt, phase: 'runtime' }, children);\n },\n\n custom(options: CustomOptions, children?: DocEntry[]): DocEntry {\n return attachDoc({ kind: 'custom', type: options.type, data: options.data, phase: 'runtime' }, children);\n },\n\n // ── Feature: Console capture (v1.56) ────────────────────────────────────\n /**\n * Snapshot the current page console messages (and optionally page errors)\n * and attach them as a code doc entry.\n *\n * Uses page.consoleMessages() and page.pageErrors() introduced in Playwright v1.56.\n * Safe to call on any Playwright version – silently produces empty output if the\n * APIs are not present.\n *\n * @example\n * story.when('the form is submitted', async ({ page }) => {\n * await page.click('#submit');\n * story.console({ page, label: 'Submit console output' });\n * });\n */\n console(options: ConsoleOptions, children?: DocEntry[]): DocEntry {\n const p = options.page as {\n consoleMessages?: () => Array<{ type(): string; text(): string }>;\n pageErrors?: () => Error[];\n };\n\n const lines: string[] = [];\n\n if (typeof p?.consoleMessages === 'function') {\n for (const msg of p.consoleMessages()) {\n lines.push(`[${msg.type()}] ${msg.text()}`);\n }\n }\n\n if (options.includeErrors === true && typeof p?.pageErrors === 'function') {\n for (const err of p.pageErrors()) {\n lines.push(`[error] ${err.message}`);\n }\n }\n\n return attachDoc(\n {\n kind: 'code',\n label: options.label ?? 'Console',\n content: lines.length > 0 ? lines.join('\\n') : '(no console output)',\n lang: 'log',\n phase: 'runtime',\n },\n children,\n );\n },\n\n // Attachments\n attach: playwrightAttach,\n\n // OTel span attachment\n attachSpans(spans: ReadonlyArray<Record<string, unknown>>): void {\n if (!activeTestInfo) return;\n const existing = activeTestInfo.annotations.find(\n (a) => a.type === 'story-otel-spans',\n );\n const description = JSON.stringify(spans);\n if (existing) {\n existing.description = description;\n } else {\n activeTestInfo.annotations.push({\n type: 'story-otel-spans',\n description,\n });\n }\n },\n\n // Step timing\n startTimer(): number {\n const ctx = getContext();\n const token = ctx.timerCounter++;\n const stepIndex = ctx.currentStep\n ? ctx.meta.steps.indexOf(ctx.currentStep)\n : undefined;\n ctx.activeTimers.set(token, {\n start: performance.now(),\n stepIndex: stepIndex !== undefined && stepIndex >= 0 ? stepIndex : undefined,\n stepId: ctx.currentStep?.id,\n consumed: false,\n });\n syncAnnotationToTest();\n return token;\n },\n\n endTimer(token: number): void {\n const ctx = getContext();\n const entry = ctx.activeTimers.get(token);\n if (!entry || entry.consumed) return;\n\n entry.consumed = true;\n const durationMs = performance.now() - entry.start;\n\n let step: StoryStep | undefined;\n if (entry.stepId) {\n step = ctx.meta.steps.find((s) => s.id === entry.stepId);\n }\n if (!step && entry.stepIndex !== undefined) {\n step = ctx.meta.steps[entry.stepIndex];\n }\n\n if (step) {\n step.durationMs = durationMs;\n }\n syncAnnotationToTest();\n },\n\n // Step wrappers\n fn,\n expect: storyExpect,\n};\n\nexport type Story = typeof story;\n","/**\n * Playwright-native step execution helper.\n *\n * Centralises the cross-cutting concerns for fixture-aware step callbacks:\n * 1. page.screencast.showChapter() – narrated chapter markers in video recordings (v1.59)\n * 2. test.step() – TestStepInfo access + trace/report visibility (v1.51)\n * 3. context.tracing.group() – BDD phase grouping in trace viewer (v1.49)\n *\n * Used for callbacks that are either async functions or expect TestStepInfo.\n * Sync callbacks that don't need TestStepInfo follow the faster sync path.\n * All three integrations degrade gracefully if the API is absent.\n */\n\nimport { test } from '@playwright/test';\nimport type { TestStepInfo } from '@playwright/test';\n\nexport type { TestStepInfo };\n\n/** Async step callback that optionally receives TestStepInfo as a second argument. */\nexport type AsyncStepCallback<T = unknown> = (\n fixtures: Record<string, unknown>,\n step?: TestStepInfo,\n) => Promise<T>;\n\n/**\n * Execute an async step callback with full Playwright-native integration.\n *\n * Call order:\n * 1. page.screencast.showChapter(label) – sets chapter in the recording before the step runs\n * 2. test.step(label, …) – wraps execution for trace/report visibility\n * 3. context.tracing.group(label, …) – groups trace actions under the step label\n * 4. body(fixtures, stepInfo) – user callback with injected TestStepInfo\n */\nexport async function runStep<T>(\n label: string,\n body: AsyncStepCallback<T>,\n fixtures: Record<string, unknown>,\n): Promise<T> {\n const page = fixtures.page as Record<string, unknown> | undefined;\n // Derive context from fixtures or from page.context() (Playwright sync method)\n const context =\n (fixtures.context as Record<string, unknown> | undefined) ??\n (typeof (page as { context?: () => Record<string, unknown> })?.context === 'function'\n ? (page as { context: () => Record<string, unknown> }).context()\n : undefined);\n\n // ── Feature 1: Screencast chapter (v1.59) ─────────────────────────────────\n // Show the chapter BEFORE the step body runs so the recording reflects the\n // BDD step title at the right moment. Silently skipped on older Playwright.\n const screencast = page?.screencast as\n | { showChapter?: (label: string) => Promise<void> }\n | undefined;\n if (screencast?.showChapter) {\n try {\n await screencast.showChapter(label);\n } catch {\n // Graceful degradation: screencast not started or API unavailable\n }\n }\n\n // ── Feature 2: test.step (v1.51) + Feature 3: tracing.group (v1.49) ──────\n // test.step provides TestStepInfo for the callback and makes the step visible\n // in the Playwright trace viewer and HTML report as a named action.\n // tracing.group inside it groups the step's child actions under the label.\n return test.step(label, async (stepInfo) => {\n const tracing = context?.tracing as\n | { group?: <R>(label: string, fn: () => Promise<R>) => Promise<R> }\n | undefined;\n\n if (tracing?.group) {\n // Track whether body was invoked to avoid double-execution\n // when body throws inside tracing.group\n let bodyInvoked = false;\n try {\n return await tracing.group(label, async () => {\n bodyInvoked = true;\n return body(fixtures, stepInfo);\n });\n } catch (e) {\n // If body was invoked, it threw - re-throw (don't retry)\n if (bodyInvoked) throw e;\n // Otherwise, tracing.group itself threw (e.g., tracing not recording)\n // Fall back to calling body without tracing.group\n return body(fixtures, stepInfo);\n }\n }\n\n return body(fixtures, stepInfo);\n });\n}\n\n/**\n * Returns true if fn is an async function (declared with `async`).\n * Used along with callback arity to decide whether to route a step callback through runStep().\n *\n * Callbacks are routed through runStep() if they are async functions OR if they\n * have arity >= 2 (meaning they expect TestStepInfo as the second argument).\n */\nexport function isAsyncFunction(fn: unknown): boolean {\n return (\n typeof fn === 'function' &&\n (fn as { constructor?: { name?: string } }).constructor?.name === 'AsyncFunction'\n );\n}\n","/**\n * Playwright Executable Stories\n *\n * BDD-style executable documentation for Playwright Test.\n *\n * @example\n * ```ts\n * import { test, expect } from '@playwright/test';\n * import { story } from 'executable-stories-playwright';\n *\n * test.describe('Calculator', () => {\n * test('adds two numbers', async ({ page }, testInfo) => {\n * story.init(testInfo);\n *\n * story.given('two numbers 5 and 3');\n * const a = 5;\n * const b = 3;\n *\n * story.when('I add them together');\n * const result = a + b;\n *\n * story.then('the result is 8');\n * expect(result).toBe(8);\n * });\n * });\n * ```\n */\n\n// Story API\nimport { story } from './story-api';\nexport { story };\nexport type { Story } from './story-api';\n\n// Top-level step helpers (framework contract)\nexport const given = story.given;\nexport const when = story.when;\nexport const then = story.then;\nexport const and = story.and;\nexport const but = story.but;\n\n// Re-export types from local types module\nexport type {\n StoryMeta,\n StoryStep,\n DocEntry,\n StepKeyword,\n StoryDocs,\n StoryOptions,\n TicketInput,\n NormalizedTicket,\n KvOptions,\n JsonOptions,\n CodeOptions,\n TableOptions,\n LinkOptions,\n SectionOptions,\n MermaidOptions,\n ScreenshotOptions,\n CustomOptions,\n ConsoleOptions,\n AttachmentOptions,\n} from './types';\n\n// TestStepInfo re-exported from @playwright/test for consumer convenience\nexport type { TestStepInfo } from './step-runner';\n"],"mappings":";AA4BA,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,OACK;;;ACpBP,SAAS,YAAY;AAoBrB,eAAsB,QACpB,OACA,MACA,UACY;AACZ,QAAM,OAAO,SAAS;AAEtB,QAAM,UACH,SAAS,YACT,OAAQ,MAAsD,YAAY,aACtE,KAAoD,QAAQ,IAC7D;AAKN,QAAM,aAAa,MAAM;AAGzB,MAAI,YAAY,aAAa;AAC3B,QAAI;AACF,YAAM,WAAW,YAAY,KAAK;AAAA,IACpC,QAAQ;AAAA,IAER;AAAA,EACF;AAMA,SAAO,KAAK,KAAK,OAAO,OAAO,aAAa;AAC1C,UAAM,UAAU,SAAS;AAIzB,QAAI,SAAS,OAAO;AAGlB,UAAI,cAAc;AAClB,UAAI;AACF,eAAO,MAAM,QAAQ,MAAM,OAAO,YAAY;AAC5C,wBAAc;AACd,iBAAO,KAAK,UAAU,QAAQ;AAAA,QAChC,CAAC;AAAA,MACH,SAAS,GAAG;AAEV,YAAI,YAAa,OAAM;AAGvB,eAAO,KAAK,UAAU,QAAQ;AAAA,MAChC;AAAA,IACF;AAEA,WAAO,KAAK,UAAU,QAAQ;AAAA,EAChC,CAAC;AACH;AASO,SAAS,gBAAgBA,KAAsB;AACpD,SACE,OAAOA,QAAO,cACbA,IAA2C,aAAa,SAAS;AAEtE;;;ADFA,IAAI,gBAAqC;AAGzC,IAAI,iBAAkC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,UAAM,YAAY,IAAI,cAClB,IAAI,KAAK,MAAM,QAAQ,IAAI,WAAW,IACtC;AACJ,QAAI,aAAa,IAAI,OAAO;AAAA,MAC1B,OAAO,YAAY,IAAI;AAAA,MACvB,WAAW,cAAc,UAAa,aAAa,IAAI,YAAY;AAAA,MACnE,QAAQ,IAAI,aAAa;AAAA,MACzB,UAAU;AAAA,IACZ,CAAC;AACD,yBAAqB;AACrB,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,OAAqB;AAC5B,UAAM,MAAM,WAAW;AACvB,UAAM,QAAQ,IAAI,aAAa,IAAI,KAAK;AACxC,QAAI,CAAC,SAAS,MAAM,SAAU;AAE9B,UAAM,WAAW;AACjB,UAAM,aAAa,YAAY,IAAI,IAAI,MAAM;AAE7C,QAAI;AACJ,QAAI,MAAM,QAAQ;AAChB,aAAO,IAAI,KAAK,MAAM,KAAK,CAAC,MAAM,EAAE,OAAO,MAAM,MAAM;AAAA,IACzD;AACA,QAAI,CAAC,QAAQ,MAAM,cAAc,QAAW;AAC1C,aAAO,IAAI,KAAK,MAAM,MAAM,SAAS;AAAA,IACvC;AAEA,QAAI,MAAM;AACR,WAAK,aAAa;AAAA,IACpB;AACA,yBAAqB;AAAA,EACvB;AAAA;AAAA,EAGA;AAAA,EACA,QAAQ;AACV;;;AE7sBO,IAAM,QAAQ,MAAM;AACpB,IAAM,OAAO,MAAM;AACnB,IAAM,OAAO,MAAM;AACnB,IAAM,MAAM,MAAM;AAClB,IAAM,MAAM,MAAM;","names":["fn"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "executable-stories-playwright",
3
- "version": "8.1.4",
3
+ "version": "8.2.1",
4
4
  "description": "BDD-style executable stories for Playwright Test with documentation generation",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -25,8 +25,8 @@
25
25
  "bin"
26
26
  ],
27
27
  "peerDependencies": {
28
- "@playwright/test": ">=1.58.2",
29
- "autotel": ">=2.24.0"
28
+ "@playwright/test": ">=1.59.1",
29
+ "autotel": ">=2.26.0"
30
30
  },
31
31
  "peerDependenciesMeta": {
32
32
  "autotel": {
@@ -34,14 +34,14 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "executable-stories-formatters": "0.7.3"
37
+ "executable-stories-formatters": "0.7.4"
38
38
  },
39
39
  "devDependencies": {
40
- "@opentelemetry/api": "^1.9.0",
40
+ "@opentelemetry/api": "^1.9.1",
41
41
  "@playwright/test": "^1.58.2",
42
- "@types/node": "^25.5.0",
42
+ "@types/node": "^25.6.0",
43
43
  "tsup": "^8.5.1",
44
- "typescript": "~5.9.3"
44
+ "typescript": "~6.0.2"
45
45
  },
46
46
  "repository": {
47
47
  "type": "git",
@@ -56,7 +56,7 @@
56
56
  "executable-stories"
57
57
  ],
58
58
  "bin": {
59
- "intent": "./bin/intent.js"
59
+ "intent": "bin/intent.js"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "tsup",
@@ -1,157 +0,0 @@
1
- ---
2
- name: playwright-converting-tests
3
- description: >
4
- Incrementally adopt executable-stories in Playwright. Add story.init(testInfo)
5
- and step markers to existing spec blocks. File naming .story.spec.ts.
6
- TestInfo from test callback second argument. Progressive enhancement.
7
- type: lifecycle
8
- library: executable-stories-playwright
9
- library_version: "7.0.1"
10
- requires:
11
- - playwright-story-api
12
- sources:
13
- - "jagreehal/executable-stories:apps/docs-site/src/content/docs/guides/converting-playwright.md"
14
- ---
15
-
16
- This skill builds on playwright-story-api. Read playwright-story-api first.
17
-
18
- # Converting Existing Playwright Tests
19
-
20
- ## Setup
21
-
22
- Install the packages and configure the reporter:
23
-
24
- ```bash
25
- npm install -D executable-stories-playwright executable-stories-formatters
26
- ```
27
-
28
- ```typescript
29
- // playwright.config.ts
30
- import { defineConfig } from "@playwright/test";
31
-
32
- export default defineConfig({
33
- reporter: [
34
- ["html"],
35
- ["executable-stories-playwright/reporter", { formats: ["markdown"] }],
36
- ],
37
- });
38
- ```
39
-
40
- ## Core Patterns
41
-
42
- ### Step 1: Rename the file
43
-
44
- ```
45
- # Before
46
- tests/login.spec.ts
47
-
48
- # After
49
- tests/login.story.spec.ts
50
- ```
51
-
52
- ### Step 2: Add story.init() and step markers
53
-
54
- ```typescript
55
- // Before
56
- import { test, expect } from "@playwright/test";
57
-
58
- test("logs in successfully", async ({ page }) => {
59
- await page.goto("/login");
60
- await page.fill("#email", "user@example.com");
61
- await page.fill("#password", "secret");
62
- await page.click("#submit");
63
- await expect(page.locator("h1")).toHaveText("Dashboard");
64
- });
65
- ```
66
-
67
- ```typescript
68
- // After
69
- import { test, expect } from "@playwright/test";
70
- import { story, given, when, then } from "executable-stories-playwright";
71
-
72
- test("logs in successfully", async ({ page }, testInfo) => {
73
- story.init(testInfo);
74
-
75
- given("the login page is loaded");
76
- await page.goto("/login");
77
-
78
- when("valid credentials are entered");
79
- await page.fill("#email", "user@example.com");
80
- await page.fill("#password", "secret");
81
- await page.click("#submit");
82
-
83
- then("the dashboard is shown");
84
- await expect(page.locator("h1")).toHaveText("Dashboard");
85
- });
86
- ```
87
-
88
- Key change: add `testInfo` as the second parameter in the test callback.
89
-
90
- ### Step 3: Minimal story
91
-
92
- ```typescript
93
- test("loads homepage", async ({ page }, testInfo) => {
94
- story.init(testInfo);
95
- await page.goto("/");
96
- await expect(page).toHaveTitle("My App");
97
- });
98
- ```
99
-
100
- ### Step 4: Add doc entries
101
-
102
- ```typescript
103
- test("shows product details", async ({ page }, testInfo) => {
104
- story.init(testInfo, { tags: ["e2e", "products"] });
105
-
106
- given("the product page is loaded");
107
- await page.goto("/products/123");
108
-
109
- then("the product details are shown");
110
- story.screenshot({ path: "screenshots/product.png", alt: "Product page" });
111
- story.json({ label: "Product", value: { id: 123, name: "Widget" } });
112
- });
113
- ```
114
-
115
- ### Suite headings from test.describe
116
-
117
- ```typescript
118
- test.describe("Authentication", () => {
119
- test("valid login", async ({ page }, testInfo) => {
120
- story.init(testInfo);
121
- // "Authentication" becomes a ## heading in docs
122
- });
123
- });
124
- ```
125
-
126
- ## Common Mistakes
127
-
128
- ### HIGH Using .story.test.ts instead of .story.spec.ts
129
-
130
- Wrong: `tests/login.story.test.ts`
131
- Correct: `tests/login.story.spec.ts`
132
-
133
- Playwright convention uses `.spec.ts`. The reporter filters accordingly.
134
-
135
- Source: CLAUDE.md — file naming conventions
136
-
137
- ### HIGH Forgetting testInfo parameter
138
-
139
- Wrong:
140
-
141
- ```typescript
142
- test("my test", async ({ page }) => {
143
- story.init(); // No testInfo
144
- });
145
- ```
146
-
147
- Correct:
148
-
149
- ```typescript
150
- test("my test", async ({ page }, testInfo) => {
151
- story.init(testInfo);
152
- });
153
- ```
154
-
155
- `testInfo` is the second parameter of Playwright's test callback. Without it, story metadata is not linked to the test.
156
-
157
- Source: packages/executable-stories-playwright/src/story-api.ts
@@ -1,131 +0,0 @@
1
- ---
2
- name: playwright-reporter-setup
3
- description: >
4
- Configure Playwright custom reporter for executable-stories-playwright.
5
- playwright.config.ts reporter array. Default export from
6
- executable-stories-playwright/reporter. Output formats, directory, naming.
7
- Aggregated and colocated modes. rawRunPath for CLI.
8
- type: core
9
- library: executable-stories-playwright
10
- library_version: "7.0.1"
11
- sources:
12
- - "jagreehal/executable-stories:packages/executable-stories-playwright/src/reporter.ts"
13
- ---
14
-
15
- # executable-stories-playwright — Reporter Setup
16
-
17
- ## Setup
18
-
19
- ```typescript
20
- // playwright.config.ts
21
- import { defineConfig } from "@playwright/test";
22
-
23
- export default defineConfig({
24
- reporter: [
25
- ["html"],
26
- [
27
- "executable-stories-playwright/reporter",
28
- {
29
- formats: ["markdown", "html"],
30
- outputDir: "docs",
31
- outputName: "user-stories",
32
- },
33
- ],
34
- ],
35
- });
36
- ```
37
-
38
- Peer dependency: `executable-stories-formatters` must be installed.
39
-
40
- ## Core Patterns
41
-
42
- ### Minimal config
43
-
44
- ```typescript
45
- export default defineConfig({
46
- reporter: [
47
- ["html"],
48
- ["executable-stories-playwright/reporter", { formats: ["markdown"] }],
49
- ],
50
- });
51
- ```
52
-
53
- ### Full options
54
-
55
- ```typescript
56
- export default defineConfig({
57
- reporter: [
58
- ["html"],
59
- [
60
- "executable-stories-playwright/reporter",
61
- {
62
- formats: ["markdown", "html", "junit", "cucumber-json"],
63
- outputDir: "reports",
64
- outputName: "test-results",
65
- output: {
66
- mode: "aggregated",
67
- },
68
- markdown: {
69
- title: "User Stories",
70
- includeStatusIcons: true,
71
- includeErrors: true,
72
- includeMetadata: true,
73
- sortScenarios: "source",
74
- },
75
- html: {
76
- title: "Test Report",
77
- darkMode: true,
78
- searchable: true,
79
- embedScreenshots: true,
80
- },
81
- rawRunPath: "reports/raw-run.json",
82
- },
83
- ],
84
- ],
85
- });
86
- ```
87
-
88
- ### Annotation-based metadata
89
-
90
- The reporter reads story metadata from test annotations with `type: "story-meta"`. This is handled automatically when using `story.init(testInfo)` — no manual annotation is needed.
91
-
92
- ## Common Mistakes
93
-
94
- ### HIGH Using default export syntax incorrectly
95
-
96
- Wrong:
97
-
98
- ```typescript
99
- import StoryReporter from "executable-stories-playwright/reporter";
100
-
101
- export default defineConfig({
102
- reporter: [
103
- ["html"],
104
- [new StoryReporter({ formats: ["markdown"] })],
105
- ],
106
- });
107
- ```
108
-
109
- Correct:
110
-
111
- ```typescript
112
- export default defineConfig({
113
- reporter: [
114
- ["html"],
115
- [
116
- "executable-stories-playwright/reporter",
117
- { formats: ["markdown"] },
118
- ],
119
- ],
120
- });
121
- ```
122
-
123
- Playwright's reporter config expects a string path and options object tuple, not a class instance. Playwright instantiates the reporter itself from the path.
124
-
125
- Source: packages/executable-stories-playwright/src/reporter.ts
126
-
127
- ### MEDIUM Default format is cucumber-json, not markdown
128
-
129
- The default `formats` is `["cucumber-json"]`. Always specify `formats: ["markdown"]` explicitly to get readable markdown output.
130
-
131
- Source: packages/executable-stories-playwright/src/reporter.ts
@@ -1,236 +0,0 @@
1
- ---
2
- name: playwright-story-api
3
- description: >
4
- Write BDD stories in Playwright using executable-stories-playwright.
5
- Top-level exports with TestInfo: story.init(testInfo). Async steps with
6
- fixtures ({ page }). Steps: given, when, then, and, but. Doc entries:
7
- json, kv, code, table, link, section, mermaid, screenshot, note, tag.
8
- Auto-And keyword conversion. Aliases: arrange, act, assert.
9
- type: core
10
- library: executable-stories-playwright
11
- library_version: "7.0.1"
12
- sources:
13
- - "jagreehal/executable-stories:packages/executable-stories-playwright/src/story-api.ts"
14
- - "jagreehal/executable-stories:apps/docs-site/src/content/docs/playwright/playwright-story-api.md"
15
- ---
16
-
17
- # executable-stories-playwright — Story API
18
-
19
- ## Setup
20
-
21
- ```typescript
22
- import { test, expect } from "@playwright/test";
23
- import { story, given, when, then } from "executable-stories-playwright";
24
-
25
- test.describe("Login page", () => {
26
- test("authenticates with valid credentials", async ({ page }, testInfo) => {
27
- story.init(testInfo, { tags: ["auth"], ticket: "AUTH-42" });
28
-
29
- given("the login page is loaded");
30
- await page.goto("/login");
31
-
32
- when("valid credentials are entered");
33
- await page.fill("#email", "alice@example.com");
34
- await page.fill("#password", "secret");
35
- await page.click('button[type="submit"]');
36
-
37
- then("the dashboard is shown");
38
- await expect(page.locator("h1")).toHaveText("Dashboard");
39
- });
40
- });
41
- ```
42
-
43
- File naming: `*.story.spec.ts`.
44
-
45
- Playwright uses top-level step exports. `story.init(testInfo)` requires the `testInfo` parameter from the test callback.
46
-
47
- ## Core Patterns
48
-
49
- ### Top-level step exports with fixtures
50
-
51
- ```typescript
52
- import { story, given, when, then, and, but } from "executable-stories-playwright";
53
-
54
- test("blocks suspended user login", async ({ page }, testInfo) => {
55
- story.init(testInfo);
56
-
57
- given("the user account exists"); // renders "Given"
58
- given("the account is suspended"); // renders "And" (auto-converted)
59
- when("the user submits valid credentials");
60
- await page.fill("#email", "user@test.com");
61
- await page.click("#submit");
62
-
63
- then("the user sees an error message");
64
- await expect(page.locator(".error")).toBeVisible();
65
-
66
- but("the user is not logged in"); // renders "But" (always)
67
- await expect(page).toHaveURL("/login");
68
- });
69
- ```
70
-
71
- ### Doc entries with screenshots
72
-
73
- ```typescript
74
- test("checkout flow", async ({ page }, testInfo) => {
75
- story.init(testInfo);
76
-
77
- given("a cart with items");
78
- story.json({ label: "Cart", value: { items: 3, total: 150 } });
79
-
80
- when("the user completes checkout");
81
- await page.click("#checkout");
82
- await page.waitForURL("/confirmation");
83
-
84
- then("the confirmation page is shown");
85
- story.screenshot({ path: "screenshots/confirmation.png", alt: "Order confirmation" });
86
- story.table({
87
- label: "Order details",
88
- columns: ["Item", "Qty", "Price"],
89
- rows: [["Widget", "3", "$50"]],
90
- });
91
- });
92
- ```
93
-
94
- ### Step wrappers with timing
95
-
96
- ```typescript
97
- const response = await story.fn("When", "the API is called", async () => {
98
- return page.request.get("/api/data");
99
- });
100
-
101
- await story.expect("the response is successful", async () => {
102
- expect(response.status()).toBe(200);
103
- });
104
- ```
105
-
106
- ### Suite headings from test.describe
107
-
108
- ```typescript
109
- test.describe("Authentication", () => {
110
- test("valid login", async ({ page }, testInfo) => {
111
- story.init(testInfo);
112
- // Produces "## Authentication" heading in generated docs
113
- });
114
- });
115
- ```
116
-
117
- Suite path comes from `testInfo.titlePath`. Describe titles become `##` headings in generated docs.
118
-
119
- ## Common Mistakes
120
-
121
- ### CRITICAL Missing testInfo argument in story.init()
122
-
123
- Wrong:
124
-
125
- ```typescript
126
- test("my test", async ({ page }) => {
127
- story.init();
128
- given("something");
129
- });
130
- ```
131
-
132
- Correct:
133
-
134
- ```typescript
135
- test("my test", async ({ page }, testInfo) => {
136
- story.init(testInfo);
137
- given("something");
138
- });
139
- ```
140
-
141
- Without `testInfo`, story metadata is not linked to the test. The `testInfo` parameter must be the second argument in the Playwright test callback.
142
-
143
- Source: packages/executable-stories-playwright/src/story-api.ts
144
-
145
- ### HIGH Using .story.test.ts file extension
146
-
147
- Wrong:
148
-
149
- ```
150
- tests/login.story.test.ts
151
- ```
152
-
153
- Correct:
154
-
155
- ```
156
- tests/login.story.spec.ts
157
- ```
158
-
159
- Playwright uses `.spec.ts` by convention. The reporter filters for `.story.spec.ts` files. Using `.test.ts` may cause the reporter to miss story metadata.
160
-
161
- Source: CLAUDE.md — "Story test files use .story.spec.ts (playwright)"
162
-
163
- ### HIGH Forgetting testInfo in callback destructuring
164
-
165
- Wrong:
166
-
167
- ```typescript
168
- test("my test", async ({ page }) => {
169
- story.init(testInfo); // testInfo is undefined
170
- });
171
- ```
172
-
173
- Correct:
174
-
175
- ```typescript
176
- test("my test", async ({ page }, testInfo) => {
177
- story.init(testInfo);
178
- });
179
- ```
180
-
181
- `testInfo` is the second parameter of the Playwright test callback, not a fixture. It must be explicitly named after the fixtures object.
182
-
183
- Source: packages/executable-stories-playwright/src/story-api.ts
184
-
185
- ### MEDIUM Calling steps before story.init()
186
-
187
- Wrong:
188
-
189
- ```typescript
190
- test("my test", async ({ page }, testInfo) => {
191
- given("something");
192
- story.init(testInfo);
193
- });
194
- ```
195
-
196
- Correct:
197
-
198
- ```typescript
199
- test("my test", async ({ page }, testInfo) => {
200
- story.init(testInfo);
201
- given("something");
202
- });
203
- ```
204
-
205
- Steps called before `init()` are silently dropped because no story context exists.
206
-
207
- Source: packages/eslint-plugin-executable-stories-playwright/src/rules/require-story-context-for-steps.ts
208
-
209
- ## Parameterized Scenarios (Scenario Outline equivalent)
210
-
211
- Use Playwright's data-driven pattern with `story()` to produce one scenario per data row — the framework-native replacement for Cucumber's Scenario Outline + Examples.
212
-
213
- ```ts
214
- import { test } from "@playwright/test";
215
- import { story, given, when, then } from "executable-stories-playwright";
216
-
217
- const cases = [
218
- { input: 1, expected: 2 },
219
- { input: 2, expected: 4 },
220
- { input: 3, expected: 6 },
221
- ];
222
-
223
- for (const { input, expected } of cases) {
224
- test(`doubles ${input} to ${expected}`, async ({ page }) => {
225
- story(`Doubles ${input} to ${expected}`);
226
- given(`the input is ${input}`);
227
- when("the doubler runs");
228
- then(`the result is ${expected}`);
229
- // ... assertions
230
- });
231
- }
232
- ```
233
-
234
- Each iteration produces a separate scenario in the generated report. Use interpolated titles so each scenario has a distinct, descriptive name.
235
-
236
- Note: Playwright does not have `it.each` — use a `for...of` loop instead.