@digital-commons-official/codeceptjs-storyboard 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/index.js ADDED
@@ -0,0 +1,930 @@
1
+ /**
2
+ * codeceptjs-storyboard — ONE SVG per scenario, built from the real frames
3
+ * captured during the journey. ONE Gherkin sentence = ONE card = ONE pixel
4
+ * baseline.
5
+ *
6
+ * Why SVG and not PNG: every piece of text drawn AROUND the frames (the
7
+ * feature title, the re-run command, the file path, the per-card captions
8
+ * and reproduce commands) is real selectable text — a reader can copy/paste
9
+ * the command that replays the scenario, which a PNG can never offer. The
10
+ * frames themselves stay bitmap (embedded as data URIs): they are genuine
11
+ * captures and each one is ALSO asserted pixel-perfect against its own
12
+ * baseline, inside the step that captured it — the SVG is the human
13
+ * artifact, the per-frame PNGs are the regression gate. Open the SVG
14
+ * locally in a browser: one click selects a whole command (Chromium/Safari;
15
+ * inert in Firefox and in GitLab's image-based preview).
16
+ *
17
+ * Register the plugin in codecept.conf.js next to the VisualHelper it relies
18
+ * on (I.takeScreenshot / I.captureScreenshot / I.assertVisualMatch come from
19
+ * @digital-commons-official/codeceptjs-visual-helper):
20
+ *
21
+ * plugins: {
22
+ * storyboard: { require: '@digital-commons-official/codeceptjs-storyboard', enabled: true }
23
+ * }
24
+ *
25
+ * The .feature file is then the single human-authored source — the
26
+ * sentences, plus structured comments attached to the sentence below them:
27
+ *
28
+ * # Chapter: a full-width band opens here
29
+ * # Note: why this step matters, what to look at
30
+ * # Copy: exact command shown one-click-copyable under the card
31
+ * When the developer starts the installer
32
+ *
33
+ * Cards open automatically for every Gherkin sentence (bddStep.before). The
34
+ * step file only drives the app and captures the proof:
35
+ *
36
+ * const storyboard = require('@digital-commons-official/codeceptjs-storyboard')
37
+ * storyboard.storyboardStep(When, 'the developer starts the installer', async () => {
38
+ * ...drive the app...
39
+ * await storyboard.addStoryboardFrame(I, await storyboard.capturePageFrame(I, 'frame-name'))
40
+ * })
41
+ *
42
+ * (storyboardStep = plain Given/When/Then registration + escaping of
43
+ * cucumber-expression metacharacters, so "CI/CD" or "(y/N)" in a sentence
44
+ * never breaks the match. Runtime-only annotations — e.g. a URL known only
45
+ * mid-step — still go through storyboard.annotate({ note, copy }).)
46
+ *
47
+ * Every path is derived from global.codecept_dir (the codecept.conf.js
48
+ * directory): frames land in _output/storyboard-frames/, per-frame baselines
49
+ * in screenshots/base/<feature-dir>/<scenario>/, the committed SVG in
50
+ * storyboards/<feature-dir>/<scenario>.svg — all mirrored from the feature
51
+ * file path, zero configuration.
52
+ */
53
+
54
+ const fs = require('fs')
55
+ const path = require('path')
56
+ const { PNG } = require('pngjs')
57
+ const { tryTo } = require('codeceptjs/effects')
58
+ const { PROPERTIES, normalizeTheme, loadTheme } = require('./theme')
59
+
60
+ let board = null
61
+
62
+ function stripTags (title) {
63
+ return String(title || '').replace(/\s*@[\w:-]+/g, '').trim()
64
+ }
65
+
66
+ function e2eDir () {
67
+ if (!global.codecept_dir) throw new Error('storyboard: global.codecept_dir is not set — run under codeceptjs')
68
+ return global.codecept_dir
69
+ }
70
+
71
+ // Every line of the scenario, verbatim from the .feature source, so each
72
+ // card can carry its exact keyword (Given/When/Then/And/But — the And/But
73
+ // resolution the step registry cannot provide).
74
+ // ponytail: single flat Scenario only — no Background/Examples resolution;
75
+ // extend when a storyboard scenario first uses them.
76
+ function parseScenarioLines (featureFile, scenarioTitle) {
77
+ let source
78
+ try {
79
+ source = fs.readFileSync(featureFile, 'utf8')
80
+ } catch (_) {
81
+ return []
82
+ }
83
+ const lines = source.split('\n').map(line => line.trim())
84
+ const start = lines.findIndex(line =>
85
+ /^Scenario( Outline)?:/.test(line) && line.replace(/^Scenario( Outline)?:\s*/, '') === scenarioTitle
86
+ )
87
+ if (start === -1) return []
88
+ const out = []
89
+ let group = null
90
+ let chapter = null
91
+ let note = null
92
+ let copy = null
93
+ for (let i = start + 1; i < lines.length; i++) {
94
+ const line = lines[i]
95
+ if (line.startsWith('#')) {
96
+ // Structured comments make the .feature the single human-authored
97
+ // source: they all attach to the NEXT sentence.
98
+ // # Chapter: Title -> full-width chapter band before that card
99
+ // # Note: text -> the card's explanation (why this step, what to see)
100
+ // # Copy: command -> the card's one-click-copyable command
101
+ const mark = line.match(/^#\s*(Chapter|Note|Copy)\s*:\s*(.+)$/i)
102
+ if (mark) {
103
+ const kind = mark[1].toLowerCase()
104
+ if (kind === 'chapter') chapter = mark[2].trim()
105
+ // Several `# Note:` lines stack into paragraphs: a long explanation
106
+ // reads as a few short blocks instead of one dense wall of text.
107
+ if (kind === 'note') note = note ? `${note}\n${mark[2].trim()}` : mark[2].trim()
108
+ if (kind === 'copy') copy = mark[2].trim()
109
+ }
110
+ continue
111
+ }
112
+ if (line === '' || line.startsWith('@')) continue
113
+ if (/^(Scenario|Feature|Examples|Background)/.test(line)) break
114
+ const step = line.match(/^(Given|When|Then|And|But)\s+(.*)$/)
115
+ if (!step) continue
116
+ if (step[1] === 'Given' || step[1] === 'When' || step[1] === 'Then') group = step[1].toLowerCase()
117
+ out.push({ keyword: step[1], group, text: step[2], chapter, note, copy })
118
+ chapter = null
119
+ note = null
120
+ copy = null
121
+ }
122
+ return out
123
+ }
124
+
125
+ // Fill the header from a scenario about to run. Exposed for the plugin AND
126
+ // for direct calls (standalone rendering, tests).
127
+ function begin (meta) {
128
+ board = {
129
+ feature: meta.feature || '',
130
+ scenario: meta.scenario || '',
131
+ file: meta.file || '',
132
+ rerun: meta.rerun || '',
133
+ baseDir: meta.baseDir || '',
134
+ lines: meta.featureFile ? parseScenarioLines(meta.featureFile, meta.scenario || '') : (meta.lines || []),
135
+ panels: []
136
+ }
137
+ }
138
+
139
+ // Where this scenario's frames live, relative to _output/ and to
140
+ // screenshots/base/ — derived by the plugin from the feature file path
141
+ // (features/<dir>/<name>.feature -> <dir>/<name>), so the baseline layout
142
+ // always mirrors the feature tree with zero configuration.
143
+ function baseDir () {
144
+ if (!board || !board.baseDir) throw new Error('storyboard.baseDir() called before the plugin saw the scenario')
145
+ return board.baseDir
146
+ }
147
+
148
+ function panel (title, opts = {}) {
149
+ if (!board) begin({})
150
+ board.panels.push({ title, note: opts.note || '', copy: opts.copy || '', images: [] })
151
+ }
152
+
153
+ function frame (pngPath, opts = {}) {
154
+ const current = board && board.panels[board.panels.length - 1]
155
+ if (!current) throw new Error('storyboard.frame() called with no open panel')
156
+ current.images.push({ file: pngPath, note: opts.note, copy: opts.copy })
157
+ }
158
+
159
+ // Merge late annotations (e.g. a URL only known mid-step) into the open panel.
160
+ function annotate (opts = {}) {
161
+ const current = board && board.panels[board.panels.length - 1]
162
+ if (!current) throw new Error('storyboard.annotate() called with no open panel')
163
+ if (opts.note) current.note = opts.note
164
+ if (opts.copy) current.copy = opts.copy
165
+ }
166
+
167
+ function panels () {
168
+ return board ? board.panels : []
169
+ }
170
+
171
+ // ---------------------------------------------------------------------------
172
+ // Step-side API — register a sentence as a card, capture and assert frames.
173
+ // ---------------------------------------------------------------------------
174
+
175
+ // Storyboard sentences are LITERAL: a cucumber-expression would reinterpret
176
+ // "CI/CD" as an alternation and "(...)" as optional text. Escape the
177
+ // metacharacters at registration so the .feature line, the registered step
178
+ // and the card title stay the exact same verbatim string.
179
+ function escapeCucumberExpression (sentence) {
180
+ return sentence.replace(/[\\/(){}]/g, '\\$&')
181
+ }
182
+
183
+ // Register a Gherkin step through its Given/When/Then function. The card
184
+ // itself opens AUTOMATICALLY (the plugin listens to bddStep.before), so this
185
+ // wrapper only (1) escapes cucumber-expression metacharacters so the .feature
186
+ // line and the pattern stay the exact same verbatim string, and (2) applies
187
+ // legacy JS note/copy options — new scenarios should prefer `# Note:` /
188
+ // `# Copy:` comments in the .feature instead. `opts` is optional.
189
+ function storyboardStep (register, pattern, opts, fn) {
190
+ if (typeof opts === 'function') {
191
+ fn = opts
192
+ opts = null
193
+ }
194
+ register(escapeCucumberExpression(pattern), async (...args) => {
195
+ if (opts && (opts.note || opts.copy)) annotate(opts)
196
+ await fn(...args)
197
+ })
198
+ }
199
+
200
+ function frameOutputPath (frameName) {
201
+ return path.join(e2eDir(), '_output', 'storyboard-frames', frameName + '.png')
202
+ }
203
+
204
+ // Full-page snapshot of the CURRENT page (mask its volatile content first)
205
+ // into the frames dir; returns the PNG's absolute path.
206
+ async function capturePageFrame (I, frameName) {
207
+ fs.mkdirSync(path.dirname(frameOutputPath(frameName)), { recursive: true })
208
+ await I.takeScreenshot(`storyboard-frames/${frameName}`)
209
+ return frameOutputPath(frameName)
210
+ }
211
+
212
+ // Element-cropped snapshot: the frame is EXACTLY the selector's box, never
213
+ // the whole viewport — a short verdict yields a short frame, not a mostly
214
+ // empty page. Use for rendered <pre> verdicts and any focused element.
215
+ async function captureElementFrame (I, frameName, selector) {
216
+ fs.mkdirSync(path.dirname(frameOutputPath(frameName)), { recursive: true })
217
+ await I.captureScreenshot(`storyboard-frames/${frameName}`, 'actual', selector)
218
+ return frameOutputPath(frameName)
219
+ }
220
+
221
+ // Guarantee the capture actually rendered: a frame whose sampled pixels are
222
+ // ~one single colour is a blank/unfinished capture (page not loaded, empty
223
+ // render) and must fail LOUD at capture time, not survive into a baseline.
224
+ function assertFrameNotEmpty (png) {
225
+ const img = PNG.sync.read(fs.readFileSync(png))
226
+ const { width, height, data } = img
227
+ const step = Math.max(1, Math.floor(Math.sqrt((width * height) / 20000)))
228
+ const counts = new Map()
229
+ let sampled = 0
230
+ for (let y = 0; y < height; y += step) {
231
+ for (let x = 0; x < width; x += step) {
232
+ const i = (width * y + x) << 2
233
+ // Quantize to 4 bits per channel so soft gradients still count as one colour.
234
+ const key = ((data[i] >> 4) << 8) | ((data[i + 1] >> 4) << 4) | (data[i + 2] >> 4)
235
+ counts.set(key, (counts.get(key) || 0) + 1)
236
+ sampled++
237
+ }
238
+ }
239
+ const dominant = Math.max(...counts.values())
240
+ const ratio = dominant / sampled
241
+ if (ratio > 0.985) {
242
+ throw new Error(
243
+ `storyboard frame "${path.basename(png)}" looks empty — ${(ratio * 100).toFixed(1)}% of its pixels are a single colour. ` +
244
+ 'The capture probably fired before the content rendered (or the element crop missed). Fix the capture; do not baseline a blank frame.'
245
+ )
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Assert `_output/<baselineName>.png` against its committed baseline, or — in
251
+ * baseline-update mode (TASK_E2E_UPDATE_BASELINES=1) — assert first and only
252
+ * when the assert FAILS persist the freshly captured actual as the baseline:
253
+ * green baselines stay byte-identical, so a regeneration run produces no
254
+ * churn. Each baseline produced this way MUST be inspected by a human, which
255
+ * is why the mode is refused in CI — there it would silently swallow every
256
+ * visual regression.
257
+ */
258
+ async function assertOrUpdateBaseline (I, baselineName) {
259
+ if (process.env.TASK_E2E_UPDATE_BASELINES && process.env.CI) {
260
+ throw new Error('TASK_E2E_UPDATE_BASELINES is forbidden in CI — baselines must be regenerated and inspected locally')
261
+ }
262
+ if (process.env.TASK_E2E_UPDATE_BASELINES) {
263
+ // tryTo: the recorder marks the test failed on a plain try/catch around
264
+ // an actor call; tryTo is the supported way to probe an assert. Since
265
+ // CodeceptJS 4 it is no longer a plugin exposing a global — it is an
266
+ // effect imported from the package, and only this directory can resolve
267
+ // it (node_modules lives here, not in the test tree), which is why the
268
+ // module re-exports it below.
269
+ const matches = await tryTo(() => I.assertVisualMatch(baselineName, { captureActual: false }))
270
+ if (!matches) {
271
+ const actualPath = path.join(e2eDir(), '_output', baselineName + '.png')
272
+ const baselinePath = path.join(e2eDir(), 'screenshots', 'base', baselineName + '.png')
273
+ fs.mkdirSync(path.dirname(baselinePath), { recursive: true })
274
+ fs.copyFileSync(actualPath, baselinePath)
275
+ }
276
+ return
277
+ }
278
+ await I.assertVisualMatch(baselineName, { captureActual: false })
279
+ }
280
+
281
+ // Attach the frame to the current card and assert it against its own
282
+ // baseline immediately (tolerance: 0, update-mode aware): a visual
283
+ // regression fails on the exact sentence whose image drifted, and the error
284
+ // message carries everything a human needs to act on it.
285
+ async function addStoryboardFrame (I, png) {
286
+ assertFrameNotEmpty(png)
287
+ frame(png)
288
+ const name = `${baseDir()}/${path.basename(png, '.png')}`
289
+ const actualPath = path.join(e2eDir(), '_output', `${name}.png`)
290
+ fs.mkdirSync(path.dirname(actualPath), { recursive: true })
291
+ fs.copyFileSync(png, actualPath)
292
+ try {
293
+ await assertOrUpdateBaseline(I, name)
294
+ } catch (err) {
295
+ // Exact marker of WHICH frame failed its visual assert — the failure band
296
+ // trusts this, never a heuristic (a diff PNG may not even exist, e.g. on
297
+ // an "Image dimensions do not match" error).
298
+ if (board) board.visualFailure = path.basename(png)
299
+ if (err && typeof err.message === 'string') {
300
+ err.message +=
301
+ `\n storyboard frame : ${name}.png` +
302
+ `\n pixel diff : screenshots/diff/${path.dirname(name)}/Diff_${path.basename(name)}.png` +
303
+ `\n failure storyboard : _output/${board && board.baseDir ? board.baseDir : '<scenario>'}.svg` +
304
+ (board && board.rerun
305
+ ? `\n deliberate change? regenerate locally, then inspect: TASK_E2E_UPDATE_BASELINES=1 ${board.rerun}`
306
+ : '')
307
+ }
308
+ throw err
309
+ }
310
+ }
311
+
312
+ // ---------------------------------------------------------------------------
313
+ // SVG rendering — pure Node, no dependencies.
314
+ // ---------------------------------------------------------------------------
315
+
316
+ // PNG dimensions live in the header chunk: width/height big-endian at bytes 16/20.
317
+ function pngSize (file) {
318
+ const buf = Buffer.alloc(24)
319
+ const fd = fs.openSync(file, 'r')
320
+ fs.readSync(fd, buf, 0, 24, 0)
321
+ fs.closeSync(fd)
322
+ return { w: buf.readUInt32BE(16), h: buf.readUInt32BE(20) }
323
+ }
324
+
325
+ function esc (text) {
326
+ return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
327
+ }
328
+
329
+ // SVG has no text auto-wrap: break on words against an estimated glyph width.
330
+ function wrap (text, maxWidth, charWidth) {
331
+ const perLine = Math.max(8, Math.floor(maxWidth / charWidth))
332
+ const lines = []
333
+ // A newline is a deliberate paragraph break (several `# Note:` lines), kept
334
+ // as one blank line so the card breathes instead of reading as a wall.
335
+ String(text).split('\n').forEach((paragraph, index) => {
336
+ if (index > 0) lines.push('')
337
+ let line = ''
338
+ for (const word of paragraph.split(/\s+/).filter(Boolean)) {
339
+ const candidate = line ? line + ' ' + word : word
340
+ if (candidate.length > perLine && line) {
341
+ lines.push(line)
342
+ line = word
343
+ } else {
344
+ line = candidate
345
+ }
346
+ }
347
+ if (line) lines.push(line)
348
+ })
349
+ return lines
350
+ }
351
+
352
+ const THEME = {
353
+ bg: '#0f1017',
354
+ card: '#181a24',
355
+ slot: '#0b0c12',
356
+ text: '#e8e8ec',
357
+ dim: '#98a0b3',
358
+ accent: '#7aa2f7',
359
+ badge: '#3b82f6',
360
+ codeBg: '#1c1e2a',
361
+ given: '#9ece6a',
362
+ when: '#7aa2f7',
363
+ then: '#bb9af7',
364
+ fail: '#f7768e',
365
+ sans: 'ui-sans-serif, system-ui, sans-serif',
366
+ mono: "ui-monospace, 'JetBrains Mono', 'Fira Code', monospace"
367
+ }
368
+
369
+ // Two-column grid of uniform cards, one card per frame: the image sits
370
+ // full-width at the top of the card in a fixed-height slot (scaled to fit,
371
+ // letterboxed on the slot colour), the texts below. 700x438 keeps the
372
+ // 1024x640 GitLab pages at their exact aspect ratio.
373
+ const GRID = {
374
+ cols: 2,
375
+ cardW: 700,
376
+ pagePad: 32,
377
+ gap: 24,
378
+ textPad: 18
379
+ }
380
+
381
+ /**
382
+ * Write the storyboard SVG. options.imageDir substitutes every frame with the
383
+ * same-named PNG inside that directory — used to build the COMMITTED SVG from
384
+ * the reviewed baselines instead of the run's actuals. options.failure (built
385
+ * by the plugin on a failed test) marks the drifted card in red, embeds its
386
+ * pixel-diff image as an extra card, and lists the sentences the journey
387
+ * never reached — one downloadable artifact tells the whole debugging story.
388
+ */
389
+ function render (outFile, options = {}) {
390
+ if (!board || !board.panels.length) {
391
+ throw new Error('storyboard.render() called with no panels')
392
+ }
393
+ const custom = normalizeTheme(options.theme || board.theme || {})
394
+ const t = { ...THEME }
395
+ const declarations = Object.entries(custom).map(([key, value]) => {
396
+ t[key] = `var(${PROPERTIES[key]})`
397
+ return `${PROPERTIES[key]}:${value}`
398
+ }).join(';')
399
+ const themeCss = declarations ? `:root{${declarations}}` : ''
400
+ const g = GRID
401
+ const failure = options.failure || null
402
+ const resolveImage = (file) =>
403
+ options.imageDir ? path.join(options.imageDir, path.basename(file)) : file
404
+
405
+ // One card per frame; a multi-frame panel repeats its number and title so
406
+ // every card still reads as its Gherkin line. The card whose pixels drifted
407
+ // is flagged (red chrome) — the full-width comparison band above the grid
408
+ // carries its expected / diff / actual triptych.
409
+ // Verbatim Gherkin keyword of a sentence (And/But included), coloured by
410
+ // its resolved group so the grid scans as stage / actions / proofs.
411
+ const lineOf = (title) => (board.lines || []).find(l => l.text === title)
412
+
413
+ const failName = failure && failure.frame && failure.frame.name
414
+ // note/copy precedence: per-frame value > JS panel value (opts/annotate,
415
+ // e.g. a URL only known at runtime) > `# Note:` / `# Copy:` comment in the
416
+ // .feature — the feature file is the default source of the human text.
417
+ const cards = board.panels.flatMap((p, pi) => {
418
+ const line = lineOf(p.title)
419
+ return p.images.map((img, fi) => ({
420
+ n: pi + 1,
421
+ first: fi === 0,
422
+ title: p.title,
423
+ note: img.note !== undefined ? img.note : (fi === 0 ? (p.note || (line && line.note) || '') : ''),
424
+ copy: img.copy !== undefined ? img.copy : (fi === 0 ? (p.copy || (line && line.copy) || '') : ''),
425
+ file: resolveImage(img.file),
426
+ failed: failName === path.basename(img.file)
427
+ }))
428
+ })
429
+ const keywordColor = { given: t.given, when: t.when, then: t.then }
430
+
431
+ const width = 2 * g.pagePad + g.cols * g.cardW + (g.cols - 1) * g.gap
432
+ const textW = g.cardW - 2 * g.textPad
433
+ const parts = []
434
+
435
+ const text = (str, x, yy, { size = 14, fill = t.text, font = t.sans, weight = 'normal', anchor = 'start', cls = '' } = {}) => {
436
+ parts.push(
437
+ `<text x="${x}" y="${yy}" font-family="${font}" font-size="${size}" fill="${fill}"` +
438
+ (weight !== 'normal' ? ` font-weight="${weight}"` : '') +
439
+ (anchor !== 'start' ? ` text-anchor="${anchor}"` : '') +
440
+ (cls ? ` class="${cls}"` : '') +
441
+ `>${esc(str)}</text>`
442
+ )
443
+ }
444
+
445
+ // A copyable command: ONE <text class="copy"> so a single click selects the
446
+ // WHOLE command (user-select:all — Chromium/Safari; inert elsewhere). Each
447
+ // wrapped line is a <tspan>; tspans concatenate with NO separator on copy,
448
+ // so every line but the last keeps a trailing space (xml:space preserves it).
449
+ const copyText = (str, x, yy, { size = 12.5, fill = t.accent } = {}) => {
450
+ const lines = wrap(str, textW, 7.6)
451
+ const tspans = lines.map((line, i) =>
452
+ `<tspan x="${x}" dy="${i === 0 ? 0 : 18}">${esc(line + (i < lines.length - 1 ? ' ' : ''))}</tspan>`
453
+ ).join('')
454
+ parts.push(
455
+ `<text x="${x}" y="${yy}" font-family="${t.mono}" font-size="${size}" fill="${fill}"` +
456
+ ` class="copy" xml:space="preserve">${tspans}</text>`
457
+ )
458
+ return lines.length
459
+ }
460
+
461
+ // Draw an image letterboxed inside a box (scaled to fit, centred on the
462
+ // slot colour), with an optional native <title> tooltip.
463
+ const drawImage = (file, x, y, boxW, boxH, tooltip) => {
464
+ const { w, h } = pngSize(file)
465
+ const data = fs.readFileSync(file).toString('base64')
466
+ const scale = Math.min(boxW / w, boxH / h)
467
+ const dw = w * scale
468
+ const dh = h * scale
469
+ parts.push(`<rect x="${x}" y="${y}" width="${boxW}" height="${boxH}" fill="${t.slot}"/>`)
470
+ parts.push(
471
+ `<image x="${(x + (boxW - dw) / 2).toFixed(1)}" y="${(y + (boxH - dh) / 2).toFixed(1)}"` +
472
+ ` width="${dw.toFixed(1)}" height="${dh.toFixed(1)}" href="data:image/png;base64,${data}">` +
473
+ (tooltip ? `<title>${esc(tooltip)}</title>` : '') + '</image>'
474
+ )
475
+ }
476
+
477
+ // Full-width failure band, rendered IN PLACE of the drifted card (which is
478
+ // always the last one — the assert throws there and stops the run): the
479
+ // expected / diff / actual triptych read left→right (what it should be,
480
+ // exactly which pixels changed, what this run produced), each image over
481
+ // its full, copyable file path — zero ambiguity, all in one artifact.
482
+ // Wrap a filesystem path onto up to `maxLines` lines, breaking on '/' (kept
483
+ // attached to its segment) so no line overflows its slot. Path segments have
484
+ // no spaces, so tspans concatenate back to the exact path on copy.
485
+ const pathLines = (str, slotW, maxLines = 2) => {
486
+ const perLine = Math.max(8, Math.floor(slotW / 6.6))
487
+ const segments = String(str).split('/').map((s, i, a) => i < a.length - 1 ? s + '/' : s)
488
+ const lines = []
489
+ let line = ''
490
+ for (const segment of segments) {
491
+ if ((line + segment).length > perLine && line) { lines.push(line); line = segment } else { line += segment }
492
+ }
493
+ if (line) lines.push(line)
494
+ return lines.slice(0, maxLines)
495
+ }
496
+ const bandPathH = 32
497
+ const failBandHeight = () => 46 + 12 + 22 + 300 + bandPathH + 16
498
+ const drawFailureBand = (frame, top) => {
499
+ const bandW = width - 2 * g.pagePad
500
+ const slotH = 300
501
+ const headerH = 46
502
+ const bandH = failBandHeight()
503
+ parts.push(`<rect x="${g.pagePad}" y="${top}" width="${bandW}" height="${bandH}" rx="12" fill="${t.card}" stroke="${t.fail}" stroke-width="3"/>`)
504
+
505
+ // Red header: which step and sentence regressed.
506
+ parts.push(`<rect x="${g.pagePad}" y="${top}" width="${bandW}" height="${headerH}" rx="12" fill="${t.fail}"/>`)
507
+ parts.push(`<rect x="${g.pagePad}" y="${top + headerH - 12}" width="${bandW}" height="12" fill="${t.fail}"/>`)
508
+ text(`✖ Visual regression — step ${frame.step}: ${frame.keyword ? frame.keyword + ' ' : ''}${frame.sentence}`,
509
+ g.pagePad + 18, top + 30, { size: 16, fill: '#ffffff', weight: '700' })
510
+ text(frame.name, width - g.pagePad - 18, top + 30, { size: 12.5, fill: '#ffffff', font: t.mono, anchor: 'end' })
511
+
512
+ const p = frame.paths || {}
513
+ const gap = 16
514
+ const slotW = (bandW - 2 * gap) / 3
515
+ const cols = [
516
+ { file: frame.baseline, label: 'Expected (baseline)', pathText: p.expected },
517
+ { file: frame.diff, label: 'Diff — changed pixels', pathText: p.diff },
518
+ { file: frame.actual, label: 'Actual (this run)', pathText: p.actual }
519
+ ]
520
+ cols.forEach((col, ci) => {
521
+ const x = g.pagePad + ci * (slotW + gap)
522
+ const ly = top + headerH + 12 + 15
523
+ text(col.label, x + 2, ly, { size: 13, fill: ci === 1 ? t.fail : t.dim, weight: '600' })
524
+ if (col.file && fs.existsSync(col.file)) {
525
+ drawImage(col.file, x, ly + 8, slotW, slotH, col.pathText)
526
+ } else {
527
+ parts.push(`<rect x="${x}" y="${ly + 8}" width="${slotW}" height="${slotH}" fill="${t.slot}"/>`)
528
+ text('(not generated)', x + slotW / 2, ly + 8 + slotH / 2, { size: 13, fill: t.dim, anchor: 'middle' })
529
+ }
530
+ // Full, one-click-copyable path to the file — open it or hand it to a
531
+ // command without retyping. Wrapped on '/' so it never overflows.
532
+ if (col.pathText) {
533
+ const pl = pathLines(col.pathText, slotW)
534
+ const tspans = pl.map((line, li) =>
535
+ `<tspan x="${x + 2}" dy="${li === 0 ? 0 : 13}">${esc(line)}</tspan>`
536
+ ).join('')
537
+ parts.push(
538
+ `<text x="${x + 2}" y="${ly + 8 + slotH + 14}" font-family="${t.mono}" font-size="11" fill="${t.accent}"` +
539
+ ` class="copy" xml:space="preserve">${tspans}</text>`
540
+ )
541
+ }
542
+ })
543
+ return bandH
544
+ }
545
+
546
+ // Text block of a card. Glyph-width estimates are deliberately generous
547
+ // (bold sans ≈ 9.3px/char at 15.5px) — an over-wrap is invisible, an
548
+ // under-wrap bleeds into the next card.
549
+ const layoutOf = (card) => {
550
+ const line = lineOf(card.title)
551
+ const keyword = line ? line.keyword : ''
552
+ const title = wrap(`${keyword ? keyword + ' ' : ''}${card.title}`, textW, 9.3)
553
+ const note = card.note ? wrap(card.note, textW, 7.2) : []
554
+ const copy = card.copy ? wrap(card.copy, textW, 8.0) : []
555
+ return { keyword, group: line ? line.group : '', title, note, copy, h: 16 + title.length * 21 + note.length * 18 + (copy.length ? 6 + copy.length * 18 : 0) + 16 }
556
+ }
557
+
558
+ // ADAPTIVE slots: the image is shown at natural size (downscaled only when
559
+ // wider than the card or taller than MAX_SLOT_H — never upscaled, terminal
560
+ // text must stay crisp) and the slot HUGS it: a 3-line verdict gets a short
561
+ // card, a 90-line one gets a tall card. Cards on the same ROW share the
562
+ // row's tallest slot/text so the grid stays aligned without drowning short
563
+ // frames in letterbox.
564
+ const MAX_SLOT_H = 1100
565
+ const slotOf = (card) => {
566
+ const { w, h } = pngSize(card.file)
567
+ const scale = Math.min(1, g.cardW / w, MAX_SLOT_H / h)
568
+ return { scale, dispW: w * scale, dispH: h * scale }
569
+ }
570
+ // Cards flow in READING ORDER, two per row, and the two cards of a row are
571
+ // fully UNIFORM: one shared image slot (as tall as the row's tallest frame —
572
+ // a smaller frame is centred inside it) and one shared text zone starting at
573
+ // the same height in both cards. The top BADGE_BAND of every card is
574
+ // reserved for the number badge so it never covers the first line of a
575
+ // frame. A `# Chapter:` comment in the .feature closes the current row and
576
+ // inserts a full-width chapter band — that is how a 20-card story keeps a
577
+ // beginning, a middle and an end.
578
+ const BADGE_BAND = 28
579
+ const CHAPTER_BAND = 56
580
+ const slots2d = []
581
+ const chapterBands = []
582
+ let rowTop = 0
583
+ let row = []
584
+ const flushRow = () => {
585
+ if (!row.length) return
586
+ const rowSlot = Math.max(...row.map(i => BADGE_BAND + Math.ceil(slotOf(cards[i]).dispH)))
587
+ const rowText = Math.max(...row.map(i => Math.ceil(layoutOf(cards[i]).h)))
588
+ row.forEach((cardIndex, col) => {
589
+ slots2d[cardIndex] = { col, top: rowTop, slotH: rowSlot, h: rowSlot + rowText }
590
+ })
591
+ rowTop += rowSlot + rowText + g.gap
592
+ row = []
593
+ }
594
+ cards.forEach((card, i) => {
595
+ const line = lineOf(card.title)
596
+ if (card.first && line && line.chapter) {
597
+ flushRow()
598
+ chapterBands.push({ title: line.chapter, top: rowTop, n: chapterBands.length + 1 })
599
+ rowTop += CHAPTER_BAND + g.gap
600
+ }
601
+ if (row.length === g.cols) flushRow()
602
+ row.push(i)
603
+ })
604
+ flushRow()
605
+ const gridHeight = cards.length ? rowTop - g.gap : 0
606
+
607
+ // --- Header: feature left (wrapped, never under the right column), the
608
+ // scenario under it, file path top-right, then the rerun bar. ---
609
+ const drawHeader = () => {
610
+ const rightZone = 470
611
+ const titleW = width - 2 * g.pagePad - rightZone
612
+ let hy = 54
613
+ for (const line of wrap(board.feature, titleW, 16.8)) {
614
+ text(line, g.pagePad, hy, { size: 28, weight: '700' })
615
+ hy += 34
616
+ }
617
+ for (const line of wrap('Scenario: ' + board.scenario, titleW, 8.7)) {
618
+ text(line, g.pagePad, hy - 6, { size: 15, fill: t.dim })
619
+ hy += 20
620
+ }
621
+ if (board.file) {
622
+ text(board.file, width - g.pagePad, 44, { size: 12, fill: t.dim, font: t.mono, anchor: 'end' })
623
+ text('e2e storyboard · baseline', width - g.pagePad, 62, { size: 12, fill: t.dim, anchor: 'end' })
624
+ }
625
+ hy = Math.max(hy + 8, 104)
626
+ if (board.rerun) {
627
+ parts.push(`<rect x="${g.pagePad}" y="${hy}" width="${width - 2 * g.pagePad}" height="36" rx="8" fill="${t.codeBg}"/>`)
628
+ text('replay this scenario', g.pagePad + 16, hy + 23, { size: 12.5, fill: t.dim })
629
+ copyText(board.rerun, g.pagePad + 170, hy + 23, { size: 13 })
630
+ hy += 36
631
+ }
632
+ return hy + 28
633
+ }
634
+
635
+ // --- Footer: failure band (in place of the drifted card), the sentences
636
+ // never reached, the verdict line and the colour legend. ---
637
+ const drawFooter = (fy) => {
638
+ if (failure && failure.frame) {
639
+ if (cards.length) fy += g.gap
640
+ fy += drawFailureBand(failure.frame, fy)
641
+ }
642
+ if (failure && failure.notReached && failure.notReached.length) {
643
+ fy += 34
644
+ for (const line of failure.notReached) {
645
+ text('○', g.pagePad + 4, fy, { size: 13, fill: t.dim, weight: '600' })
646
+ text(`${line.keyword} ${line.text} — not reached`, g.pagePad + 26, fy, { size: 13.5, fill: t.dim })
647
+ fy += 20
648
+ }
649
+ }
650
+ fy += 30
651
+ const proven = board.panels.filter(p => p.images.length).length
652
+ const verdict = failure
653
+ ? `FAILED — ${proven} of ${(board.lines || []).length || board.panels.length} sentences proven · the red band shows where it broke (expected / diff / actual)`
654
+ : `Storyboard e2e · ${board.panels.length} steps · ${cards.length} frames · every frame is its own pixel baseline (tolerance: 0)`
655
+ text(verdict, g.pagePad, fy, { size: failure ? 12.5 : 12, fill: failure ? t.fail : t.dim, weight: failure ? '600' : 'normal' })
656
+ parts.push(
657
+ `<text x="${width - g.pagePad}" y="${fy}" font-family="${t.sans}" font-size="12" fill="${t.dim}" text-anchor="end">` +
658
+ `<tspan fill="${t.given}">●</tspan> Given — stage <tspan fill="${t.when}">●</tspan> When — actions ` +
659
+ `<tspan fill="${t.then}">●</tspan> Then — proofs</text>`
660
+ )
661
+ return fy
662
+ }
663
+
664
+ let y = drawHeader()
665
+
666
+ // --- Chapter bands: full-width titled strips between rows. ---
667
+ chapterBands.forEach((band) => {
668
+ const bw = width - 2 * g.pagePad
669
+ parts.push(`<rect x="${g.pagePad}" y="${y + band.top}" width="${bw}" height="${CHAPTER_BAND}" rx="10" fill="${t.codeBg}"/>`)
670
+ parts.push(`<rect x="${g.pagePad}" y="${y + band.top}" width="6" height="${CHAPTER_BAND}" fill="${t.accent}"/>`)
671
+ text(`Chapter ${band.n}`, g.pagePad + 26, y + band.top + 35, { size: 17, fill: t.accent, weight: '700' })
672
+ text(band.title, g.pagePad + 26 + 9.5 * `Chapter ${band.n}`.length + 18, y + band.top + 35, { size: 17, weight: '600' })
673
+ })
674
+
675
+ // --- Cards (every captured frame, the drifted one red-outlined). Rows have
676
+ // their own heights; inside a row every card is top-aligned. ---
677
+ cards.forEach((card, i) => {
678
+ const { scale, dispW, dispH } = slotOf(card)
679
+ const slotH = slots2d[i].slotH
680
+ const cardH = slots2d[i].h
681
+ const cx = g.pagePad + slots2d[i].col * (g.cardW + g.gap)
682
+ const cy = y + slots2d[i].top
683
+
684
+ parts.push(`<clipPath id="card${i}"><rect x="${cx}" y="${cy}" width="${g.cardW}" height="${cardH}" rx="12"/></clipPath>`)
685
+ parts.push(
686
+ `<rect x="${cx}" y="${cy}" width="${g.cardW}" height="${cardH}" rx="12" fill="${t.card}"` +
687
+ (card.failed ? ` stroke="${t.fail}" stroke-width="3"` : '') + '/>'
688
+ )
689
+ parts.push(`<g clip-path="url(#card${i})">`)
690
+ // The image at NATURAL size (downscaled only when oversized), centred both
691
+ // ways inside the ROW's shared slot: the two cards of a row keep the same
692
+ // image zone and the same text zone, whatever each frame's own size.
693
+ parts.push(`<rect x="${cx}" y="${cy}" width="${g.cardW}" height="${slotH}" fill="${t.slot}"/>`)
694
+ const data = fs.readFileSync(card.file).toString('base64')
695
+ const iy = cy + BADGE_BAND + (slotH - BADGE_BAND - Math.ceil(dispH)) / 2
696
+ parts.push(
697
+ `<image x="${(cx + (g.cardW - dispW) / 2).toFixed(1)}" y="${iy.toFixed(1)}"` +
698
+ ` width="${dispW.toFixed(1)}" height="${dispH.toFixed(1)}" href="data:image/png;base64,${data}">` +
699
+ `<title>${esc(path.basename(card.file))}${scale < 1 ? ` (shown at ${(scale * 100).toFixed(0)}%)` : ''}</title></image>`
700
+ )
701
+
702
+ const layout = layoutOf(card)
703
+ let ty = cy + slotH + 16 + 15
704
+ layout.title.forEach((line, li) => {
705
+ if (li === 0 && layout.keyword && line.startsWith(layout.keyword)) {
706
+ // Verbatim keyword coloured by its group — the only chrome that also
707
+ // survives GitLab's image-based preview.
708
+ const rest = line.slice(layout.keyword.length)
709
+ parts.push(
710
+ `<text x="${cx + g.textPad}" y="${ty}" font-family="${t.sans}" font-size="15.5" font-weight="600"` +
711
+ ` fill="${t.text}" xml:space="preserve"><tspan fill="${keywordColor[layout.group] || t.dim}">${esc(layout.keyword)}</tspan>${esc(rest)}</text>`
712
+ )
713
+ } else {
714
+ text(line, cx + g.textPad, ty, { size: 15.5, weight: '600' })
715
+ }
716
+ ty += 21
717
+ })
718
+ for (const line of layout.note) {
719
+ text(line, cx + g.textPad, ty, { size: 12.8, fill: t.dim })
720
+ ty += 18
721
+ }
722
+ if (layout.copy.length) {
723
+ ty += 6
724
+ copyText(card.copy, cx + g.textPad, ty)
725
+ ty += layout.copy.length * 18
726
+ }
727
+ parts.push('</g>')
728
+
729
+ // Number badge astride the card's TOP-LEFT CORNER — on the chrome, never
730
+ // over the captured pixels.
731
+ parts.push(`<circle cx="${cx + 4}" cy="${cy + 4}" r="16" fill="${card.failed ? t.fail : t.badge}"/>`)
732
+ text(String(card.n), cx + 4, cy + 9, { size: 15, fill: '#ffffff', weight: '700', anchor: 'middle' })
733
+ })
734
+
735
+ if (cards.length) y += gridHeight
736
+ y = drawFooter(y)
737
+
738
+ const height = y + g.pagePad
739
+ const svg =
740
+ // The W3C namespace is an identifier, not a network request.
741
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}"` + // DevSkim: ignore DS137138
742
+ ' role="img" aria-labelledby="sb-title sb-desc">\n' +
743
+ `<title id="sb-title">${esc(board.feature)} — ${esc(board.scenario)}</title>\n` +
744
+ `<desc id="sb-desc">e2e storyboard · ${esc(board.file)} · replay: ${esc(board.rerun)}</desc>\n` +
745
+ `<style>${themeCss}.copy{user-select:all;-webkit-user-select:all;cursor:text}.copy:hover{text-decoration:underline}</style>\n` +
746
+ `<rect width="${width}" height="${height}" fill="${t.bg}"/>\n` +
747
+ parts.join('\n') +
748
+ '\n</svg>\n'
749
+
750
+ fs.mkdirSync(path.dirname(outFile), { recursive: true })
751
+ fs.writeFileSync(outFile, svg)
752
+ return outFile
753
+ }
754
+
755
+ // Build the failure descriptor for a failed test: the drifted frame (marked
756
+ // exactly by addStoryboardFrame via board.visualFailure) with its
757
+ // expected/diff/actual paths, plus the sentences never reached. Returns null
758
+ // when nothing was marked.
759
+ function buildFailure (board) {
760
+ const dir = global.codecept_dir
761
+ const marked = board.panels.find(p => p.images.some(img => path.basename(img.file) === board.visualFailure))
762
+ const notReached = (board.lines || []).filter(line =>
763
+ !board.panels.some(p => p.title === line.text && p.images.length)
764
+ )
765
+ if (!board.visualFailure || !marked) return { frame: null, notReached }
766
+
767
+ const name = board.visualFailure
768
+ const diffPath = path.join(dir, 'screenshots', 'diff', board.baseDir, `Diff_${name}`)
769
+ const hasDiff = fs.existsSync(diffPath)
770
+ const baseline = path.join(dir, 'screenshots', 'base', board.baseDir, name)
771
+ const actual = path.join(dir, '_output', board.baseDir, name)
772
+ const line = (board.lines || []).find(l => l.text === marked.title)
773
+ const rel = (abs) => path.relative(process.cwd(), abs)
774
+ return {
775
+ frame: {
776
+ name,
777
+ step: board.panels.indexOf(marked) + 1,
778
+ sentence: marked.title,
779
+ keyword: line ? line.keyword : '',
780
+ baseline,
781
+ actual,
782
+ diff: hasDiff ? diffPath : null,
783
+ paths: {
784
+ expected: rel(baseline),
785
+ diff: hasDiff ? rel(diffPath) : '(no pixel diff — see the error message, e.g. image dimensions differ)',
786
+ actual: rel(actual)
787
+ }
788
+ },
789
+ notReached
790
+ }
791
+ }
792
+
793
+ // One unmissable block in the runner output: WHERE to look. The path is
794
+ // repo-relative — valid on the host once the artifact sync (end of the run)
795
+ // has copied _output back.
796
+ function logVisualRegression (frame, outputSvg) {
797
+ console.error(
798
+ '\n════════════════════════════════════════════════════════════════\n' +
799
+ `✖ VISUAL REGRESSION — step ${frame.step}: ${frame.keyword} ${frame.sentence}\n` +
800
+ ' The failure storyboard sums it all up (expected / diff / actual):\n' +
801
+ ` 🎬 open in a browser: ${path.relative(process.cwd(), outputSvg)}\n` +
802
+ '════════════════════════════════════════════════════════════════\n'
803
+ )
804
+ }
805
+
806
+ // ---------------------------------------------------------------------------
807
+ // CodeceptJS plugin — fills the header from the Gherkin metadata of every
808
+ // scenario before it runs (and drops stale panels from a previous test),
809
+ // then renders the SVG when the test ends: to _output on every outcome (a
810
+ // failing run's partial board shows exactly how far the journey got), and —
811
+ // only on a PASSED run in baseline-update mode — the committed copy under
812
+ // storyboards/, rebuilt FROM the reviewed baselines so it never embeds
813
+ // unreviewed pixels.
814
+ // codeceptjs 3.7.8 sets test.title / test.tags / test.file / test.parent.title
815
+ // (feature name) in lib/mocha/gherkin.js; titles carry the tags appended.
816
+ // ---------------------------------------------------------------------------
817
+ module.exports = function storyboardPlugin (config = {}) {
818
+ const { event, recorder } = require('codeceptjs')
819
+ const writeGallery = require('./gallery')
820
+ const entries = new Map()
821
+ let themePromise
822
+ event.dispatcher.on(event.all.before, () => {
823
+ entries.clear()
824
+ themePromise = null
825
+ })
826
+ event.dispatcher.on(event.test.before, (test) => {
827
+ const tags = test.tags || []
828
+ const tag = tags.length ? tags[tags.length - 1] : ''
829
+ let file = ''
830
+ let base = ''
831
+ if (test.file && global.codecept_dir) {
832
+ // Display path relative to the process cwd (the repo root in the
833
+ // container), correct wherever the suite lives in a given project.
834
+ file = path.relative(process.cwd(), test.file)
835
+ const fromFeatures = path.relative(path.join(global.codecept_dir, 'features'), test.file)
836
+ if (!fromFeatures.startsWith('..')) {
837
+ // FLAT per-scenario layout: <feature-dir>/<scenario-tag> — the film
838
+ // reads as acts/stories with no per-feature nesting. Scenario tags are
839
+ // grep filters, unique by construction, so they key the baselines and
840
+ // the SVG unambiguously.
841
+ const scenarioKey = tag
842
+ ? tag.replace(/^@/, '')
843
+ : stripTags(test.title).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
844
+ base = path.join(path.dirname(fromFeatures), scenarioKey)
845
+ }
846
+ }
847
+ begin({
848
+ feature: stripTags(test.parent && test.parent.title),
849
+ scenario: stripTags(test.title),
850
+ file,
851
+ featureFile: test.file,
852
+ baseDir: base,
853
+ rerun: tag ? `task test -- --grep "${tag}"` : ''
854
+ })
855
+ if (config.theme) {
856
+ const current = board
857
+ recorder.add('load storyboard theme', async () => {
858
+ themePromise = themePromise || loadTheme(config.theme, e2eDir())
859
+ current.theme = await themePromise
860
+ })
861
+ }
862
+ })
863
+
864
+ // Every Gherkin sentence opens its own card AUTOMATICALLY, in scenario
865
+ // order, right before its step function runs — frames captured inside the
866
+ // step attach to it. Step files never do panel bookkeeping.
867
+ event.dispatcher.on(event.bddStep.before, (step) => {
868
+ if (!board) return
869
+ panel(step.text)
870
+ })
871
+
872
+ const finish = (passed) => {
873
+ // Only scenarios that actually captured frames are storyboards — plain
874
+ // Gherkin tests (no addStoryboardFrame call) must not render empty boards.
875
+ if (!board || !board.panels.some(p => p.images.length) || !board.baseDir || !global.codecept_dir) return
876
+ try {
877
+ // The drifted frame was marked exactly by addStoryboardFrame; on a
878
+ // diff-less failure (e.g. "Image dimensions do not match") the band's
879
+ // middle slot reads "(not generated)".
880
+ const failure = passed ? null : buildFailure(board)
881
+ const outputSvg = render(path.join(global.codecept_dir, '_output', `${board.baseDir}.svg`), { failure })
882
+ entries.set(board.baseDir, {
883
+ baseDir: board.baseDir,
884
+ scenario: board.scenario,
885
+ rerun: board.rerun,
886
+ passed,
887
+ sentence: failure && failure.frame ? failure.frame.sentence : ''
888
+ })
889
+ if (failure && failure.frame) logVisualRegression(failure.frame, outputSvg)
890
+ if (passed && process.env.TASK_E2E_UPDATE_BASELINES) {
891
+ render(path.join(global.codecept_dir, 'storyboards', `${board.baseDir}.svg`), {
892
+ imageDir: path.join(global.codecept_dir, 'screenshots', 'base', board.baseDir)
893
+ })
894
+ }
895
+ } catch (err) {
896
+ // Rendering must never mask the test outcome.
897
+ console.error(`storyboard: SVG rendering failed: ${err.message}`)
898
+ }
899
+ }
900
+ event.dispatcher.on(event.test.passed, () => finish(true))
901
+ event.dispatcher.on(event.test.failed, () => finish(false))
902
+ event.dispatcher.on(event.all.after, () => {
903
+ if (!global.codecept_dir) return
904
+ try {
905
+ const stories = [...entries.values()]
906
+ writeGallery(path.join(global.codecept_dir, '_output'), stories)
907
+ if (process.env.TASK_E2E_UPDATE_BASELINES && !process.env.CI) {
908
+ writeGallery(path.join(global.codecept_dir, 'storyboards'), stories.filter(entry => entry.passed))
909
+ }
910
+ } catch (err) {
911
+ console.error(`storyboard: gallery rendering failed: ${err.message}`)
912
+ }
913
+ })
914
+ }
915
+
916
+ module.exports.begin = begin
917
+ module.exports.baseDir = baseDir
918
+ module.exports.parseScenarioLines = parseScenarioLines
919
+ module.exports.panel = panel
920
+ module.exports.frame = frame
921
+ module.exports.annotate = annotate
922
+ module.exports.panels = panels
923
+ module.exports.storyboardStep = storyboardStep
924
+ module.exports.capturePageFrame = capturePageFrame
925
+ module.exports.captureElementFrame = captureElementFrame
926
+ module.exports.frameOutputPath = frameOutputPath
927
+ module.exports.assertOrUpdateBaseline = assertOrUpdateBaseline
928
+ module.exports.addStoryboardFrame = addStoryboardFrame
929
+ module.exports.render = render
930
+ module.exports.tryTo = tryTo