executable-stories-cypress 2.0.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,173 @@
1
+ import { StoryMeta as StoryMeta$1, StepKeyword } from 'executable-stories-formatters';
2
+ export { DocEntry, StepKeyword, StoryMeta, StoryStep } from 'executable-stories-formatters';
3
+
4
+ /**
5
+ * Shared types between browser (story-api) and Node (store, reporter).
6
+ * No Cypress or Node-only imports so both environments can use them.
7
+ */
8
+
9
+ type StoryMeta = StoryMeta$1;
10
+ /** Scoped attachment stored in context. */
11
+ interface ScopedAttachment {
12
+ name: string;
13
+ mediaType: string;
14
+ path?: string;
15
+ body?: string | Buffer;
16
+ encoding?: 'BASE64' | 'IDENTITY';
17
+ charset?: string;
18
+ fileName?: string;
19
+ stepIndex?: number;
20
+ stepId?: string;
21
+ }
22
+ /** Payload sent from browser to Node via cy.task for the reporter to merge with run results */
23
+ interface RecordMetaPayload {
24
+ specRelative: string;
25
+ titlePath: string[];
26
+ meta: StoryMeta;
27
+ attachments?: ScopedAttachment[];
28
+ }
29
+ /** All inline doc options that can be passed to step markers. */
30
+ interface StoryDocs {
31
+ note?: string;
32
+ tag?: string | string[];
33
+ kv?: Record<string, unknown>;
34
+ json?: JsonOptions;
35
+ table?: TableOptions;
36
+ link?: LinkOptions;
37
+ code?: CodeOptions;
38
+ section?: SectionOptions;
39
+ mermaid?: MermaidOptions;
40
+ screenshot?: ScreenshotOptions;
41
+ custom?: CustomOptions;
42
+ }
43
+ /** Options for story.init(). */
44
+ interface StoryOptions {
45
+ tags?: string[];
46
+ ticket?: string | string[];
47
+ meta?: Record<string, unknown>;
48
+ }
49
+ /** Options for story.attach(). */
50
+ interface AttachmentOptions {
51
+ name: string;
52
+ mediaType: string;
53
+ path?: string;
54
+ body?: string | Buffer;
55
+ }
56
+ interface KvOptions {
57
+ label: string;
58
+ value: unknown;
59
+ }
60
+ interface JsonOptions {
61
+ label: string;
62
+ value: unknown;
63
+ }
64
+ interface CodeOptions {
65
+ label: string;
66
+ content: string;
67
+ lang?: string;
68
+ }
69
+ interface TableOptions {
70
+ label: string;
71
+ columns: string[];
72
+ rows: string[][];
73
+ }
74
+ interface LinkOptions {
75
+ label: string;
76
+ url: string;
77
+ }
78
+ interface SectionOptions {
79
+ title: string;
80
+ markdown: string;
81
+ }
82
+ interface MermaidOptions {
83
+ code: string;
84
+ title?: string;
85
+ }
86
+ interface ScreenshotOptions {
87
+ path: string;
88
+ alt?: string;
89
+ }
90
+ interface CustomOptions {
91
+ type: string;
92
+ data: unknown;
93
+ }
94
+
95
+ /**
96
+ * Cypress story.* API for executable-stories.
97
+ *
98
+ * Uses native Cypress describe/it with opt-in documentation.
99
+ * Story meta is flushed to Node via cy.task from the support file.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { story } from 'executable-stories-cypress';
104
+ *
105
+ * describe('Calculator', () => {
106
+ * it('adds two numbers', () => {
107
+ * story.init();
108
+ *
109
+ * story.given('two numbers 5 and 3');
110
+ * const a = 5, b = 3;
111
+ *
112
+ * story.when('I add them together');
113
+ * const result = a + b;
114
+ *
115
+ * story.then('the result is 8');
116
+ * expect(result).toBe(8);
117
+ * });
118
+ * });
119
+ * ```
120
+ */
121
+
122
+ declare function init(options?: StoryOptions): void;
123
+ /**
124
+ * Get the current story meta and clear the active context.
125
+ * Called by the support file after each test to send meta to Node via cy.task.
126
+ * Returns null if story.init() was never called for this test.
127
+ */
128
+ declare function getAndClearMeta(): RecordMetaPayload | null;
129
+ /**
130
+ * Wrap a function as a step with timing and error capture.
131
+ * Records the step with `wrapped: true` and `durationMs`.
132
+ */
133
+ declare function fn<T>(keyword: StepKeyword, text: string, body: () => T): T;
134
+ /**
135
+ * Wrap an assertion as a Then step with timing and error capture.
136
+ * Shorthand for `story.fn('Then', text, body)`.
137
+ */
138
+ declare function storyExpect<T>(text: string, body: () => T): T;
139
+ declare const story: {
140
+ init: typeof init;
141
+ given: (text: string, docs?: StoryDocs) => void;
142
+ when: (text: string, docs?: StoryDocs) => void;
143
+ then: (text: string, docs?: StoryDocs) => void;
144
+ and: (text: string, docs?: StoryDocs) => void;
145
+ but: (text: string, docs?: StoryDocs) => void;
146
+ arrange: (text: string, docs?: StoryDocs) => void;
147
+ act: (text: string, docs?: StoryDocs) => void;
148
+ assert: (text: string, docs?: StoryDocs) => void;
149
+ setup: (text: string, docs?: StoryDocs) => void;
150
+ context: (text: string, docs?: StoryDocs) => void;
151
+ execute: (text: string, docs?: StoryDocs) => void;
152
+ action: (text: string, docs?: StoryDocs) => void;
153
+ verify: (text: string, docs?: StoryDocs) => void;
154
+ note(text: string): void;
155
+ tag(name: string | string[]): void;
156
+ kv(options: KvOptions): void;
157
+ json(options: JsonOptions): void;
158
+ code(options: CodeOptions): void;
159
+ table(options: TableOptions): void;
160
+ link(options: LinkOptions): void;
161
+ section(options: SectionOptions): void;
162
+ mermaid(options: MermaidOptions): void;
163
+ screenshot(options: ScreenshotOptions): void;
164
+ custom(options: CustomOptions): void;
165
+ attach(options: AttachmentOptions): void;
166
+ startTimer(): number;
167
+ endTimer(token: number): void;
168
+ fn: typeof fn;
169
+ expect: typeof storyExpect;
170
+ };
171
+ type Story = typeof story;
172
+
173
+ export { type CodeOptions, type CustomOptions, type JsonOptions, type KvOptions, type LinkOptions, type MermaidOptions, type RecordMetaPayload, type ScreenshotOptions, type SectionOptions, type Story, type StoryDocs, type StoryOptions, type TableOptions, getAndClearMeta, story };
package/dist/index.js ADDED
@@ -0,0 +1,306 @@
1
+ // src/story-api.ts
2
+ var activeContext = null;
3
+ var sourceOrderCounter = 0;
4
+ function getContext() {
5
+ if (!activeContext) {
6
+ throw new Error(
7
+ "story.init() must be called first. Use: it('name', () => { story.init(); ... });"
8
+ );
9
+ }
10
+ return activeContext;
11
+ }
12
+ function normalizeTickets(ticket) {
13
+ if (!ticket) return void 0;
14
+ return Array.isArray(ticket) ? ticket : [ticket];
15
+ }
16
+ function convertStoryDocsToEntries(docs) {
17
+ const entries = [];
18
+ if (docs.note) {
19
+ entries.push({ kind: "note", text: docs.note, phase: "runtime" });
20
+ }
21
+ if (docs.tag) {
22
+ const names = Array.isArray(docs.tag) ? docs.tag : [docs.tag];
23
+ entries.push({ kind: "tag", names, phase: "runtime" });
24
+ }
25
+ if (docs.kv) {
26
+ for (const [label, value] of Object.entries(docs.kv)) {
27
+ entries.push({ kind: "kv", label, value, phase: "runtime" });
28
+ }
29
+ }
30
+ if (docs.code) {
31
+ entries.push({
32
+ kind: "code",
33
+ label: docs.code.label,
34
+ content: docs.code.content,
35
+ lang: docs.code.lang,
36
+ phase: "runtime"
37
+ });
38
+ }
39
+ if (docs.json) {
40
+ entries.push({
41
+ kind: "code",
42
+ label: docs.json.label,
43
+ content: JSON.stringify(docs.json.value, null, 2),
44
+ lang: "json",
45
+ phase: "runtime"
46
+ });
47
+ }
48
+ if (docs.table) {
49
+ entries.push({
50
+ kind: "table",
51
+ label: docs.table.label,
52
+ columns: docs.table.columns,
53
+ rows: docs.table.rows,
54
+ phase: "runtime"
55
+ });
56
+ }
57
+ if (docs.link) {
58
+ entries.push({
59
+ kind: "link",
60
+ label: docs.link.label,
61
+ url: docs.link.url,
62
+ phase: "runtime"
63
+ });
64
+ }
65
+ if (docs.section) {
66
+ entries.push({
67
+ kind: "section",
68
+ title: docs.section.title,
69
+ markdown: docs.section.markdown,
70
+ phase: "runtime"
71
+ });
72
+ }
73
+ if (docs.mermaid) {
74
+ entries.push({
75
+ kind: "mermaid",
76
+ code: docs.mermaid.code,
77
+ title: docs.mermaid.title,
78
+ phase: "runtime"
79
+ });
80
+ }
81
+ if (docs.screenshot) {
82
+ entries.push({
83
+ kind: "screenshot",
84
+ path: docs.screenshot.path,
85
+ alt: docs.screenshot.alt,
86
+ phase: "runtime"
87
+ });
88
+ }
89
+ if (docs.custom) {
90
+ entries.push({
91
+ kind: "custom",
92
+ type: docs.custom.type,
93
+ data: docs.custom.data,
94
+ phase: "runtime"
95
+ });
96
+ }
97
+ return entries;
98
+ }
99
+ function attachDoc(entry) {
100
+ const ctx = getContext();
101
+ if (ctx.currentStep) {
102
+ ctx.currentStep.docs ??= [];
103
+ ctx.currentStep.docs.push(entry);
104
+ } else {
105
+ ctx.meta.docs ??= [];
106
+ ctx.meta.docs.push(entry);
107
+ }
108
+ }
109
+ function extractSuitePath(titlePath) {
110
+ if (titlePath.length <= 1) return void 0;
111
+ const suitePath = titlePath.slice(0, -1);
112
+ return suitePath.length > 0 ? suitePath : void 0;
113
+ }
114
+ function createStepMarker(keyword) {
115
+ return function stepMarker(text, docs) {
116
+ const ctx = getContext();
117
+ const step = {
118
+ id: `step-${ctx.stepCounter++}`,
119
+ keyword,
120
+ text,
121
+ docs: docs ? convertStoryDocsToEntries(docs) : []
122
+ };
123
+ ctx.meta.steps.push(step);
124
+ ctx.currentStep = step;
125
+ };
126
+ }
127
+ function init(options) {
128
+ const currentTest = Cypress.currentTest;
129
+ const spec = Cypress.spec;
130
+ if (!currentTest) {
131
+ throw new Error("story.init() must be called inside an it() block so Cypress.currentTest is available.");
132
+ }
133
+ const titlePath = currentTest.titlePath ?? [currentTest.title];
134
+ const scenario = currentTest.title;
135
+ const suitePath = extractSuitePath(titlePath);
136
+ const specRelative = spec?.relative ?? "unknown";
137
+ const meta = {
138
+ scenario,
139
+ steps: [],
140
+ suitePath,
141
+ tags: options?.tags,
142
+ tickets: normalizeTickets(options?.ticket),
143
+ meta: options?.meta,
144
+ sourceOrder: sourceOrderCounter++
145
+ };
146
+ activeContext = {
147
+ meta,
148
+ currentStep: null,
149
+ stepCounter: 0,
150
+ attachments: [],
151
+ activeTimers: /* @__PURE__ */ new Map(),
152
+ timerCounter: 0,
153
+ specRelative,
154
+ titlePath
155
+ };
156
+ }
157
+ function getAndClearMeta() {
158
+ if (!activeContext) return null;
159
+ const payload = {
160
+ specRelative: activeContext.specRelative,
161
+ titlePath: activeContext.titlePath,
162
+ meta: activeContext.meta,
163
+ attachments: activeContext.attachments.length > 0 ? activeContext.attachments : void 0
164
+ };
165
+ activeContext = null;
166
+ return payload;
167
+ }
168
+ function fn(keyword, text, body) {
169
+ const ctx = getContext();
170
+ const step = {
171
+ id: `step-${ctx.stepCounter++}`,
172
+ keyword,
173
+ text,
174
+ docs: [],
175
+ wrapped: true
176
+ };
177
+ ctx.meta.steps.push(step);
178
+ ctx.currentStep = step;
179
+ const start = performance.now();
180
+ try {
181
+ const result = body();
182
+ if (result instanceof Promise) {
183
+ return result.then(
184
+ (val) => {
185
+ step.durationMs = performance.now() - start;
186
+ return val;
187
+ },
188
+ (err) => {
189
+ step.durationMs = performance.now() - start;
190
+ throw err;
191
+ }
192
+ );
193
+ }
194
+ step.durationMs = performance.now() - start;
195
+ return result;
196
+ } catch (err) {
197
+ step.durationMs = performance.now() - start;
198
+ throw err;
199
+ }
200
+ }
201
+ function storyExpect(text, body) {
202
+ return fn("Then", text, body);
203
+ }
204
+ var story = {
205
+ init,
206
+ // BDD step markers
207
+ given: createStepMarker("Given"),
208
+ when: createStepMarker("When"),
209
+ then: createStepMarker("Then"),
210
+ and: createStepMarker("And"),
211
+ but: createStepMarker("But"),
212
+ // AAA pattern aliases
213
+ arrange: createStepMarker("Given"),
214
+ act: createStepMarker("When"),
215
+ assert: createStepMarker("Then"),
216
+ // Additional aliases
217
+ setup: createStepMarker("Given"),
218
+ context: createStepMarker("Given"),
219
+ execute: createStepMarker("When"),
220
+ action: createStepMarker("When"),
221
+ verify: createStepMarker("Then"),
222
+ // Standalone doc methods
223
+ note(text) {
224
+ attachDoc({ kind: "note", text, phase: "runtime" });
225
+ },
226
+ tag(name) {
227
+ const names = Array.isArray(name) ? name : [name];
228
+ attachDoc({ kind: "tag", names, phase: "runtime" });
229
+ },
230
+ kv(options) {
231
+ attachDoc({ kind: "kv", label: options.label, value: options.value, phase: "runtime" });
232
+ },
233
+ json(options) {
234
+ const content = JSON.stringify(options.value, null, 2);
235
+ attachDoc({ kind: "code", label: options.label, content, lang: "json", phase: "runtime" });
236
+ },
237
+ code(options) {
238
+ attachDoc({ kind: "code", label: options.label, content: options.content, lang: options.lang, phase: "runtime" });
239
+ },
240
+ table(options) {
241
+ attachDoc({ kind: "table", label: options.label, columns: options.columns, rows: options.rows, phase: "runtime" });
242
+ },
243
+ link(options) {
244
+ attachDoc({ kind: "link", label: options.label, url: options.url, phase: "runtime" });
245
+ },
246
+ section(options) {
247
+ attachDoc({ kind: "section", title: options.title, markdown: options.markdown, phase: "runtime" });
248
+ },
249
+ mermaid(options) {
250
+ attachDoc({ kind: "mermaid", code: options.code, title: options.title, phase: "runtime" });
251
+ },
252
+ screenshot(options) {
253
+ attachDoc({ kind: "screenshot", path: options.path, alt: options.alt, phase: "runtime" });
254
+ },
255
+ custom(options) {
256
+ attachDoc({ kind: "custom", type: options.type, data: options.data, phase: "runtime" });
257
+ },
258
+ // Attachments
259
+ attach(options) {
260
+ const ctx = getContext();
261
+ const stepIndex = ctx.currentStep ? ctx.meta.steps.indexOf(ctx.currentStep) : void 0;
262
+ ctx.attachments.push({
263
+ ...options,
264
+ stepIndex: stepIndex !== void 0 && stepIndex >= 0 ? stepIndex : void 0,
265
+ stepId: ctx.currentStep?.id
266
+ });
267
+ },
268
+ // Step timing
269
+ startTimer() {
270
+ const ctx = getContext();
271
+ const token = ctx.timerCounter++;
272
+ const stepIndex = ctx.currentStep ? ctx.meta.steps.indexOf(ctx.currentStep) : void 0;
273
+ ctx.activeTimers.set(token, {
274
+ start: performance.now(),
275
+ stepIndex: stepIndex !== void 0 && stepIndex >= 0 ? stepIndex : void 0,
276
+ stepId: ctx.currentStep?.id,
277
+ consumed: false
278
+ });
279
+ return token;
280
+ },
281
+ endTimer(token) {
282
+ const ctx = getContext();
283
+ const entry = ctx.activeTimers.get(token);
284
+ if (!entry || entry.consumed) return;
285
+ entry.consumed = true;
286
+ const durationMs = performance.now() - entry.start;
287
+ let step;
288
+ if (entry.stepId) {
289
+ step = ctx.meta.steps.find((s) => s.id === entry.stepId);
290
+ }
291
+ if (!step && entry.stepIndex !== void 0) {
292
+ step = ctx.meta.steps[entry.stepIndex];
293
+ }
294
+ if (step) {
295
+ step.durationMs = durationMs;
296
+ }
297
+ },
298
+ // Step wrappers
299
+ fn,
300
+ expect: storyExpect
301
+ };
302
+ export {
303
+ getAndClearMeta,
304
+ story
305
+ };
306
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/story-api.ts"],"sourcesContent":["/**\n * Cypress story.* API for executable-stories.\n *\n * Uses native Cypress describe/it with opt-in documentation.\n * Story meta is flushed to Node via cy.task from the support file.\n *\n * @example\n * ```ts\n * import { story } from 'executable-stories-cypress';\n *\n * describe('Calculator', () => {\n * it('adds two numbers', () => {\n * story.init();\n *\n * story.given('two numbers 5 and 3');\n * const a = 5, 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 type {\n StepKeyword,\n StoryMeta,\n StoryStep,\n DocEntry,\n StoryDocs,\n StoryOptions,\n AttachmentOptions,\n ScopedAttachment,\n RecordMetaPayload,\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\nexport type { RecordMetaPayload } from './types';\n\n// ============================================================================\n// Internal types\n// ============================================================================\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 specRelative: string;\n titlePath: string[];\n}\n\n// ============================================================================\n// Cypress-specific context\n// ============================================================================\n\n/** Active story context - set by story.init() */\nlet activeContext: StoryContext | 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() must be called first. Use: it('name', () => { story.init(); ... });\"\n );\n }\n return activeContext;\n}\n\n// ============================================================================\n// Helper functions (inlined from core)\n// ============================================================================\n\nfunction normalizeTickets(ticket: string | string[] | undefined): string[] | undefined {\n if (!ticket) return undefined;\n return Array.isArray(ticket) ? ticket : [ticket];\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): void {\n const ctx = getContext();\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}\n\n/**\n * Extract suite path from Cypress.currentTest.titlePath (describe blocks only).\n * titlePath is [describe1, describe2, ..., testTitle] — we want everything except the last.\n */\nfunction extractSuitePath(titlePath: string[]): string[] | undefined {\n if (titlePath.length <= 1) return undefined;\n const suitePath = titlePath.slice(0, -1);\n return suitePath.length > 0 ? suitePath : undefined;\n}\n\n// ============================================================================\n// Step markers\n// ============================================================================\n\nfunction createStepMarker(keyword: StepKeyword) {\n return function stepMarker(text: string, docs?: StoryDocs): void {\n const ctx = getContext();\n const step: StoryStep = {\n id: `step-${ctx.stepCounter++}`,\n keyword,\n text,\n docs: docs ? convertStoryDocsToEntries(docs) : [],\n };\n ctx.meta.steps.push(step);\n ctx.currentStep = step;\n };\n}\n\n// ============================================================================\n// story.init() - Cypress-specific\n// ============================================================================\n\nfunction init(options?: StoryOptions): void {\n const currentTest = Cypress.currentTest;\n const spec = Cypress.spec;\n if (!currentTest) {\n throw new Error(\"story.init() must be called inside an it() block so Cypress.currentTest is available.\");\n }\n\n const titlePath = currentTest.titlePath ?? [currentTest.title];\n const scenario = currentTest.title;\n const suitePath = extractSuitePath(titlePath);\n const specRelative = spec?.relative ?? \"unknown\";\n\n const meta: StoryMeta = {\n scenario,\n steps: [],\n suitePath,\n tags: options?.tags,\n tickets: normalizeTickets(options?.ticket),\n meta: options?.meta,\n sourceOrder: sourceOrderCounter++,\n };\n\n activeContext = {\n meta,\n currentStep: null,\n stepCounter: 0,\n attachments: [],\n activeTimers: new Map(),\n timerCounter: 0,\n specRelative,\n titlePath,\n };\n}\n\n/**\n * Get the current story meta and clear the active context.\n * Called by the support file after each test to send meta to Node via cy.task.\n * Returns null if story.init() was never called for this test.\n */\nexport function getAndClearMeta(): RecordMetaPayload | null {\n if (!activeContext) return null;\n const payload: RecordMetaPayload = {\n specRelative: activeContext.specRelative,\n titlePath: activeContext.titlePath,\n meta: activeContext.meta,\n attachments: activeContext.attachments.length > 0 ? activeContext.attachments : undefined,\n };\n activeContext = null;\n return payload;\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: () => T): T {\n const ctx = getContext();\n const step: StoryStep = {\n id: `step-${ctx.stepCounter++}`,\n keyword,\n text,\n docs: [],\n wrapped: true,\n };\n ctx.meta.steps.push(step);\n ctx.currentStep = step;\n\n const start = performance.now();\n try {\n const result = body();\n if (result instanceof Promise) {\n return result.then(\n (val) => {\n step.durationMs = performance.now() - start;\n return val;\n },\n (err) => {\n step.durationMs = performance.now() - start;\n throw err;\n },\n ) as T;\n }\n step.durationMs = performance.now() - start;\n return result;\n } catch (err) {\n step.durationMs = performance.now() - start;\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// 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): void {\n attachDoc({ kind: 'note', text, phase: 'runtime' });\n },\n\n tag(name: string | string[]): void {\n const names = Array.isArray(name) ? name : [name];\n attachDoc({ kind: 'tag', names, phase: 'runtime' });\n },\n\n kv(options: KvOptions): void {\n attachDoc({ kind: 'kv', label: options.label, value: options.value, phase: 'runtime' });\n },\n\n json(options: JsonOptions): void {\n const content = JSON.stringify(options.value, null, 2);\n attachDoc({ kind: 'code', label: options.label, content, lang: 'json', phase: 'runtime' });\n },\n\n code(options: CodeOptions): void {\n attachDoc({ kind: 'code', label: options.label, content: options.content, lang: options.lang, phase: 'runtime' });\n },\n\n table(options: TableOptions): void {\n attachDoc({ kind: 'table', label: options.label, columns: options.columns, rows: options.rows, phase: 'runtime' });\n },\n\n link(options: LinkOptions): void {\n attachDoc({ kind: 'link', label: options.label, url: options.url, phase: 'runtime' });\n },\n\n section(options: SectionOptions): void {\n attachDoc({ kind: 'section', title: options.title, markdown: options.markdown, phase: 'runtime' });\n },\n\n mermaid(options: MermaidOptions): void {\n attachDoc({ kind: 'mermaid', code: options.code, title: options.title, phase: 'runtime' });\n },\n\n screenshot(options: ScreenshotOptions): void {\n attachDoc({ kind: 'screenshot', path: options.path, alt: options.alt, phase: 'runtime' });\n },\n\n custom(options: CustomOptions): void {\n attachDoc({ kind: 'custom', type: options.type, data: options.data, phase: 'runtime' });\n },\n\n // Attachments\n attach(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 stepIndex: stepIndex !== undefined && stepIndex >= 0 ? stepIndex : undefined,\n stepId: ctx.currentStep?.id,\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 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 },\n\n // Step wrappers\n fn,\n expect: storyExpect,\n};\n\nexport type Story = typeof story;\n"],"mappings":";AAwFA,IAAI,gBAAqC;AAGzC,IAAI,qBAAqB;AAKzB,SAAS,aAA2B;AAClC,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAMA,SAAS,iBAAiB,QAA6D;AACrF,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC,MAAM;AACjD;AAEA,SAAS,0BAA0B,MAA6B;AAC9D,QAAM,UAAsB,CAAC;AAE7B,MAAI,KAAK,MAAM;AACb,YAAQ,KAAK,EAAE,MAAM,QAAQ,MAAM,KAAK,MAAM,OAAO,UAAU,CAAC;AAAA,EAClE;AACA,MAAI,KAAK,KAAK;AACZ,UAAM,QAAQ,MAAM,QAAQ,KAAK,GAAG,IAAI,KAAK,MAAM,CAAC,KAAK,GAAG;AAC5D,YAAQ,KAAK,EAAE,MAAM,OAAO,OAAO,OAAO,UAAU,CAAC;AAAA,EACvD;AACA,MAAI,KAAK,IAAI;AACX,eAAW,CAAC,OAAO,KAAK,KAAK,OAAO,QAAQ,KAAK,EAAE,GAAG;AACpD,cAAQ,KAAK,EAAE,MAAM,MAAM,OAAO,OAAO,OAAO,UAAU,CAAC;AAAA,IAC7D;AAAA,EACF;AACA,MAAI,K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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,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;AAAA,EACF;AAAA;AAAA,EAGA;AAAA,EACA,QAAQ;AACV;","names":[]}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key2 of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key2) && key2 !== except)
14
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/plugin.ts
21
+ var plugin_exports = {};
22
+ __export(plugin_exports, {
23
+ registerExecutableStoriesPlugin: () => registerExecutableStoriesPlugin
24
+ });
25
+ module.exports = __toCommonJS(plugin_exports);
26
+
27
+ // src/store.ts
28
+ function key(specRelative, titlePath) {
29
+ return `${specRelative}\0${titlePath.join("\0")}`;
30
+ }
31
+ var store = /* @__PURE__ */ new Map();
32
+ function recordMeta(payload) {
33
+ store.set(key(payload.specRelative, payload.titlePath), {
34
+ specRelative: payload.specRelative,
35
+ titlePath: payload.titlePath,
36
+ meta: payload.meta,
37
+ attachments: payload.attachments
38
+ });
39
+ return null;
40
+ }
41
+ function getMeta(specRelative, titlePath) {
42
+ return store.get(key(specRelative, titlePath))?.meta;
43
+ }
44
+
45
+ // src/plugin.ts
46
+ var TASK_NAME = "executableStories:recordMeta";
47
+ var GET_STORED_META_TASK = "executableStories:getStoredMeta";
48
+ function registerExecutableStoriesPlugin(on) {
49
+ on("task", {
50
+ [TASK_NAME]: (payload) => recordMeta(payload),
51
+ [GET_STORED_META_TASK]: (arg) => {
52
+ const { specRelative, titlePath } = arg;
53
+ return getMeta(specRelative, titlePath) ?? null;
54
+ }
55
+ });
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ registerExecutableStoriesPlugin
60
+ });
61
+ //# sourceMappingURL=plugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugin.ts","../src/store.ts"],"sourcesContent":["/**\n * Cypress Node plugin: registers the task that receives story meta from the browser.\n * Use in cypress.config.ts (or plugins file) so the reporter can merge meta with run results.\n *\n * @example\n * // cypress.config.ts\n * import { defineConfig } from 'cypress';\n * import { registerExecutableStoriesPlugin } from 'executable-stories-cypress/plugin';\n *\n * export default defineConfig({\n * e2e: {\n * setupNodeEvents(on) {\n * registerExecutableStoriesPlugin(on);\n * },\n * },\n * });\n */\n\nimport { recordMeta, getMeta } from \"./store\";\n\nconst TASK_NAME = \"executableStories:recordMeta\";\nconst GET_STORED_META_TASK = \"executableStories:getStoredMeta\";\n\n/** Minimal type for Cypress plugin `on` (task registration) */\nexport interface PluginEvents {\n (event: \"task\", tasks: Record<string, (arg: unknown) => unknown>): void;\n}\n\n/**\n * Register the executable-stories task on the Cypress `on` handler.\n * Call this from setupNodeEvents in your Cypress config.\n */\n/** Argument for getStoredMeta task (used by tests to assert on recorded meta). */\nexport interface GetStoredMetaArg {\n specRelative: string;\n titlePath: string[];\n}\n\nexport function registerExecutableStoriesPlugin(on: PluginEvents): void {\n on(\"task\", {\n [TASK_NAME]: (payload: unknown) => recordMeta(payload as import(\"./types\").RecordMetaPayload),\n [GET_STORED_META_TASK]: (arg: unknown) => {\n const { specRelative, titlePath } = arg as GetStoredMetaArg;\n return getMeta(specRelative, titlePath) ?? null;\n },\n });\n}\n","/**\n * Node-only store for story meta sent from the browser via cy.task.\n * Plugin writes; reporter reads. Keyed by spec + titlePath for merging with run results.\n */\n\nimport type { StoryMeta, ScopedAttachment, RecordMetaPayload } from \"./types\";\n\nexport interface StoredMeta {\n specRelative: string;\n titlePath: string[];\n meta: StoryMeta;\n attachments?: ScopedAttachment[];\n}\n\nfunction key(specRelative: string, titlePath: string[]): string {\n return `${specRelative}\\0${titlePath.join(\"\\0\")}`;\n}\n\nconst store = new Map<string, StoredMeta>();\n\nexport function recordMeta(payload: RecordMetaPayload): null {\n store.set(key(payload.specRelative, payload.titlePath), {\n specRelative: payload.specRelative,\n titlePath: payload.titlePath,\n meta: payload.meta,\n attachments: payload.attachments,\n });\n return null;\n}\n\nexport function getAttachments(specRelative: string, titlePath: string[]): ScopedAttachment[] | undefined {\n return store.get(key(specRelative, titlePath))?.attachments;\n}\n\nexport function getMeta(specRelative: string, titlePath: string[]): StoryMeta | undefined {\n return store.get(key(specRelative, titlePath))?.meta;\n}\n\nexport function getAllMeta(): StoredMeta[] {\n return Array.from(store.values());\n}\n\nexport function clearStore(): void {\n store.clear();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcA,SAAS,IAAI,cAAsB,WAA6B;AAC9D,SAAO,GAAG,YAAY,KAAK,UAAU,KAAK,IAAI,CAAC;AACjD;AAEA,IAAM,QAAQ,oBAAI,IAAwB;AAEnC,SAAS,WAAW,SAAkC;AAC3D,QAAM,IAAI,IAAI,QAAQ,cAAc,QAAQ,SAAS,GAAG;AAAA,IACtD,cAAc,QAAQ;AAAA,IACtB,WAAW,QAAQ;AAAA,IACnB,MAAM,QAAQ;AAAA,IACd,aAAa,QAAQ;AAAA,EACvB,CAAC;AACD,SAAO;AACT;AAMO,SAAS,QAAQ,cAAsB,WAA4C;AACxF,SAAO,MAAM,IAAI,IAAI,cAAc,SAAS,CAAC,GAAG;AAClD;;;ADhBA,IAAM,YAAY;AAClB,IAAM,uBAAuB;AAiBtB,SAAS,gCAAgC,IAAwB;AACtE,KAAG,QAAQ;AAAA,IACT,CAAC,SAAS,GAAG,CAAC,YAAqB,WAAW,OAA8C;AAAA,IAC5F,CAAC,oBAAoB,GAAG,CAAC,QAAiB;AACxC,YAAM,EAAE,cAAc,UAAU,IAAI;AACpC,aAAO,QAAQ,cAAc,SAAS,KAAK;AAAA,IAC7C;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Cypress Node plugin: registers the task that receives story meta from the browser.
3
+ * Use in cypress.config.ts (or plugins file) so the reporter can merge meta with run results.
4
+ *
5
+ * @example
6
+ * // cypress.config.ts
7
+ * import { defineConfig } from 'cypress';
8
+ * import { registerExecutableStoriesPlugin } from 'executable-stories-cypress/plugin';
9
+ *
10
+ * export default defineConfig({
11
+ * e2e: {
12
+ * setupNodeEvents(on) {
13
+ * registerExecutableStoriesPlugin(on);
14
+ * },
15
+ * },
16
+ * });
17
+ */
18
+ /** Minimal type for Cypress plugin `on` (task registration) */
19
+ interface PluginEvents {
20
+ (event: "task", tasks: Record<string, (arg: unknown) => unknown>): void;
21
+ }
22
+ /**
23
+ * Register the executable-stories task on the Cypress `on` handler.
24
+ * Call this from setupNodeEvents in your Cypress config.
25
+ */
26
+ /** Argument for getStoredMeta task (used by tests to assert on recorded meta). */
27
+ interface GetStoredMetaArg {
28
+ specRelative: string;
29
+ titlePath: string[];
30
+ }
31
+ declare function registerExecutableStoriesPlugin(on: PluginEvents): void;
32
+
33
+ export { type GetStoredMetaArg, type PluginEvents, registerExecutableStoriesPlugin };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Cypress Node plugin: registers the task that receives story meta from the browser.
3
+ * Use in cypress.config.ts (or plugins file) so the reporter can merge meta with run results.
4
+ *
5
+ * @example
6
+ * // cypress.config.ts
7
+ * import { defineConfig } from 'cypress';
8
+ * import { registerExecutableStoriesPlugin } from 'executable-stories-cypress/plugin';
9
+ *
10
+ * export default defineConfig({
11
+ * e2e: {
12
+ * setupNodeEvents(on) {
13
+ * registerExecutableStoriesPlugin(on);
14
+ * },
15
+ * },
16
+ * });
17
+ */
18
+ /** Minimal type for Cypress plugin `on` (task registration) */
19
+ interface PluginEvents {
20
+ (event: "task", tasks: Record<string, (arg: unknown) => unknown>): void;
21
+ }
22
+ /**
23
+ * Register the executable-stories task on the Cypress `on` handler.
24
+ * Call this from setupNodeEvents in your Cypress config.
25
+ */
26
+ /** Argument for getStoredMeta task (used by tests to assert on recorded meta). */
27
+ interface GetStoredMetaArg {
28
+ specRelative: string;
29
+ titlePath: string[];
30
+ }
31
+ declare function registerExecutableStoriesPlugin(on: PluginEvents): void;
32
+
33
+ export { type GetStoredMetaArg, type PluginEvents, registerExecutableStoriesPlugin };