@digital-commons-official/codeceptjs-storyboard 2.0.1 → 2.0.3

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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/package.json +2 -2
  3. package/src/index.js +58 -27
package/README.md CHANGED
@@ -337,6 +337,7 @@ tag filter, and proves the exact sentence of a deliberate visual regression.
337
337
  ### What you get
338
338
 
339
339
  - On every run the selected storyboard is written under `_output/<feature-dir>/<scenario-tag>.md` or `.svg`.
340
+ - In SVG, cards sit two per row, 708 px each. A frame still 1000 px wide or more once fitted to the 1100 px height limit, such as a web page 1440 px wide, takes a full 1440 px row and shows at its real size. A narrower strip stays in its half of a row, shrunk to fit. A card alone on its row is centred in it.
340
341
  - On a failed run the storyboard shows the expected image, the changed pixels and the actual image with their paths, then lists the sentences the run never reached. SVG presents the comparison as a red band; Markdown uses a labelled table.
341
342
  - In baseline-update mode the plugin asserts first and rewrites a baseline only when its assert fails, then rebuilds the reviewed storyboard under `storyboards/` from the reviewed baselines:
342
343
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digital-commons-official/codeceptjs-storyboard",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Storyboard plugin for CodeceptJS: one Gherkin sentence = one card = one pixel baseline, with Markdown or SVG reports",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "@digital-commons-official/codeceptjs-visual-helper": "2.0.13",
35
35
  "@onitofu/gherkin-lint": "5.0.0",
36
36
  "codeceptjs": "4.2.2",
37
- "playwright": "1.63.0",
37
+ "playwright": "1.64.1",
38
38
  "standard": "^17.1.2",
39
39
  "vitest": "^5.0.0"
40
40
  },
package/src/index.js CHANGED
@@ -332,14 +332,23 @@ const THEME = {
332
332
 
333
333
  // Two-column grid of uniform cards, one card per frame: the image sits
334
334
  // full-width at the top of the card in a fixed-height slot (scaled to fit,
335
- // letterboxed on the slot colour), the texts below. 700x438 keeps the
336
- // 1024x640 GitLab pages at their exact aspect ratio.
335
+ // letterboxed on the slot colour), the texts below. A frame still at least
336
+ // wideFrom pixels wide once fitted to maxSlotH (a 1440 px web page, a
337
+ // terminal window 1024 px wide) takes a full row instead, 2 * 708 + 24 = 1440,
338
+ // so it shows at its real size rather than shrunk into half a row. Narrower
339
+ // strips stay two per row, shrunk into their card, so one long line never
340
+ // moves the layout; a frame so tall that it is shrunk below wideFrom anyway
341
+ // keeps its half row too. A card left alone on its row is centred in it. The
342
+ // text under a full-row card wraps at wideTextW, a line a reader follows.
337
343
  const GRID = {
338
344
  cols: 2,
339
- cardW: 700,
345
+ cardW: 708,
340
346
  pagePad: 32,
341
347
  gap: 24,
342
- textPad: 18
348
+ textPad: 18,
349
+ wideFrom: 1000,
350
+ wideTextW: 900,
351
+ maxSlotH: 1100
343
352
  }
344
353
 
345
354
  /**
@@ -396,8 +405,17 @@ function render (outFile, options = {}) {
396
405
  })
397
406
  const keywordColor = { given: t.given, when: t.when, then: t.then }
398
407
 
399
- const width = 2 * g.pagePad + g.cols * g.cardW + (g.cols - 1) * g.gap
400
- const textW = g.cardW - 2 * g.textPad
408
+ // A full row: every column plus the gaps between them.
409
+ const rowW = g.cols * g.cardW + (g.cols - 1) * g.gap
410
+ const width = 2 * g.pagePad + rowW
411
+ // Wide: still wideFrom pixels wide at its full-row scale (see GRID).
412
+ const fullRowScale = ({ w, h }) => Math.min(1, rowW / w, g.maxSlotH / h)
413
+ const isWide = (card) => {
414
+ const size = pngSize(card.file)
415
+ return size.w * fullRowScale(size) >= g.wideFrom
416
+ }
417
+ const cardWOf = (card) => isWide(card) ? rowW : g.cardW
418
+ const textWOf = (card) => Math.min(cardWOf(card), g.wideTextW) - 2 * g.textPad
401
419
  const parts = []
402
420
 
403
421
  const text = (str, x, yy, { size = 14, fill = t.text, font = t.sans, weight = 'normal', anchor = 'start', cls = '' } = {}) => {
@@ -414,8 +432,8 @@ function render (outFile, options = {}) {
414
432
  // WHOLE command (user-select:all — Chromium/Safari; inert elsewhere). Each
415
433
  // wrapped line is a <tspan>; tspans concatenate with NO separator on copy,
416
434
  // so every line but the last keeps a trailing space (xml:space preserves it).
417
- const copyText = (str, x, yy, { size = 12.5, fill = t.accent } = {}) => {
418
- const lines = wrap(str, textW, 7.6)
435
+ const copyText = (str, x, yy, { size = 12.5, fill = t.accent, maxW = g.cardW - 2 * g.textPad } = {}) => {
436
+ const lines = wrap(str, maxW, 7.6)
419
437
  const tspans = lines.map((line, i) =>
420
438
  `<tspan x="${x}" dy="${i === 0 ? 0 : 18}">${esc(line + (i < lines.length - 1 ? ' ' : ''))}</tspan>`
421
439
  ).join('')
@@ -473,7 +491,7 @@ function render (outFile, options = {}) {
473
491
  // Red header: which step and sentence regressed.
474
492
  parts.push(`<rect x="${g.pagePad}" y="${top}" width="${bandW}" height="${headerH}" rx="12" fill="${t.fail}"/>`)
475
493
  parts.push(`<rect x="${g.pagePad}" y="${top + headerH - 12}" width="${bandW}" height="12" fill="${t.fail}"/>`)
476
- text(`✖ Visual regression — step ${frame.step}: ${sentenceOf(frame, frame.sentence)}`,
494
+ text(`✖ Visual regression at step ${frame.step}: ${sentenceOf(frame, frame.sentence)}`,
477
495
  g.pagePad + 18, top + 30, { size: 16, fill: '#ffffff', weight: '700' })
478
496
  text(frame.name, width - g.pagePad - 18, top + 30, { size: 12.5, fill: '#ffffff', font: t.mono, anchor: 'end' })
479
497
 
@@ -482,7 +500,7 @@ function render (outFile, options = {}) {
482
500
  const slotW = (bandW - 2 * gap) / 3
483
501
  const cols = [
484
502
  { file: frame.baseline, label: 'Expected (baseline)', pathText: p.expected },
485
- { file: frame.diff, label: 'Diff — changed pixels', pathText: p.diff },
503
+ { file: frame.diff, label: 'Diff: changed pixels', pathText: p.diff },
486
504
  { file: frame.actual, label: 'Actual (this run)', pathText: p.actual }
487
505
  ]
488
506
  cols.forEach((col, ci) => {
@@ -517,6 +535,7 @@ function render (outFile, options = {}) {
517
535
  const layoutOf = (card) => {
518
536
  const line = lineOf(card)
519
537
  const keyword = line ? line.keyword : ''
538
+ const textW = textWOf(card)
520
539
  const title = wrap(line ? sentenceOf(line, card.title) : card.title, textW, 9.3)
521
540
  const note = card.note ? wrap(card.note, textW, 7.2) : []
522
541
  const copy = card.copy ? wrap(card.copy, textW, 8.0) : []
@@ -524,21 +543,24 @@ function render (outFile, options = {}) {
524
543
  }
525
544
 
526
545
  // ADAPTIVE slots: the image is shown at natural size (downscaled only when
527
- // wider than the card or taller than MAX_SLOT_H — never upscaled, terminal
546
+ // wider than its card or taller than GRID.maxSlotH — never upscaled, terminal
528
547
  // text must stay crisp) and the slot HUGS it: a 3-line verdict gets a short
529
548
  // card, a 90-line one gets a tall card. Cards on the same ROW share the
530
549
  // row's tallest slot/text so the grid stays aligned without drowning short
531
- // frames in letterbox.
532
- const MAX_SLOT_H = 1100
550
+ // frames in letterbox. A wide frame's box is the whole row, so a 1440x900
551
+ // web page keeps its full height and shows at 100%.
533
552
  const slotOf = (card) => {
534
553
  const { w, h } = pngSize(card.file)
535
- const scale = Math.min(1, g.cardW / w, MAX_SLOT_H / h)
554
+ const scale = Math.min(1, cardWOf(card) / w, g.maxSlotH / h)
536
555
  return { scale, dispW: w * scale, dispH: h * scale }
537
556
  }
538
557
  // Cards flow in READING ORDER, two per row, and the two cards of a row are
539
558
  // fully UNIFORM: one shared image slot (as tall as the row's tallest frame —
540
559
  // a smaller frame is centred inside it) and one shared text zone starting at
541
- // the same height in both cards. The top BADGE_BAND of every card is
560
+ // the same height in both cards. A WIDE frame (see GRID) closes the
561
+ // half-filled row before it and takes a row of its own, full width, so a
562
+ // whole web page is read at its real size. A row left with fewer cards
563
+ // than columns centres them. The top BADGE_BAND of every card is
542
564
  // reserved for the number badge so it never covers the first line of a
543
565
  // frame. A `# Chapter:` comment in the .feature closes the current row and
544
566
  // inserts a full-width chapter band — that is how a 20-card story keeps a
@@ -553,8 +575,10 @@ function render (outFile, options = {}) {
553
575
  if (!row.length) return
554
576
  const rowSlot = Math.max(...row.map(i => BADGE_BAND + Math.ceil(slotOf(cards[i]).dispH)))
555
577
  const rowText = Math.max(...row.map(i => Math.ceil(layoutOf(cards[i]).h)))
578
+ const used = row.length * g.cardW + (row.length - 1) * g.gap
579
+ const left = g.pagePad + (isWide(cards[row[0]]) ? 0 : (rowW - used) / 2)
556
580
  row.forEach((cardIndex, col) => {
557
- slots2d[cardIndex] = { col, top: rowTop, slotH: rowSlot, h: rowSlot + rowText }
581
+ slots2d[cardIndex] = { x: left + col * (g.cardW + g.gap), top: rowTop, slotH: rowSlot, h: rowSlot + rowText }
558
582
  })
559
583
  rowTop += rowSlot + rowText + g.gap
560
584
  row = []
@@ -566,6 +590,12 @@ function render (outFile, options = {}) {
566
590
  chapterBands.push({ title: line.chapter, top: rowTop, n: chapterBands.length + 1 })
567
591
  rowTop += CHAPTER_BAND + g.gap
568
592
  }
593
+ if (isWide(card)) {
594
+ flushRow()
595
+ row.push(i)
596
+ flushRow()
597
+ return
598
+ }
569
599
  if (row.length === g.cols) flushRow()
570
600
  row.push(i)
571
601
  })
@@ -611,20 +641,20 @@ function render (outFile, options = {}) {
611
641
  fy += 34
612
642
  for (const line of failure.notReached) {
613
643
  text('○', g.pagePad + 4, fy, { size: 13, fill: t.dim, weight: '600' })
614
- text(`${sentenceOf(line)} — not reached`, g.pagePad + 26, fy, { size: 13.5, fill: t.dim })
644
+ text(`${sentenceOf(line)} (not reached)`, g.pagePad + 26, fy, { size: 13.5, fill: t.dim })
615
645
  fy += 20
616
646
  }
617
647
  }
618
648
  fy += 30
619
649
  const proven = board.panels.filter(p => p.images.length).length
620
650
  const verdict = failure
621
- ? `FAILED — ${proven} of ${(board.lines || []).length || board.panels.length} sentences proven · the red band shows where it broke (expected / diff / actual)`
651
+ ? `FAILED: ${proven} of ${(board.lines || []).length || board.panels.length} sentences proven · the red band shows where it broke (expected / diff / actual)`
622
652
  : `Storyboard e2e · ${board.panels.length} steps · ${cards.length} frames · every frame is its own pixel baseline (tolerance: 0)`
623
653
  text(verdict, g.pagePad, fy, { size: failure ? 12.5 : 12, fill: failure ? t.fail : t.dim, weight: failure ? '600' : 'normal' })
624
654
  parts.push(
625
655
  `<text x="${width - g.pagePad}" y="${fy}" font-family="${t.sans}" font-size="12" fill="${t.dim}" text-anchor="end">` +
626
- `<tspan fill="${t.given}">●</tspan> Given — stage <tspan fill="${t.when}">●</tspan> When — actions ` +
627
- `<tspan fill="${t.then}">●</tspan> Then — proofs</text>`
656
+ `<tspan fill="${t.given}">●</tspan> Given: stage <tspan fill="${t.when}">●</tspan> When: actions ` +
657
+ `<tspan fill="${t.then}">●</tspan> Then: proofs</text>`
628
658
  )
629
659
  return fy
630
660
  }
@@ -646,23 +676,24 @@ function render (outFile, options = {}) {
646
676
  const { scale, dispW, dispH } = slotOf(card)
647
677
  const slotH = slots2d[i].slotH
648
678
  const cardH = slots2d[i].h
649
- const cx = g.pagePad + slots2d[i].col * (g.cardW + g.gap)
679
+ const cw = cardWOf(card)
680
+ const cx = slots2d[i].x
650
681
  const cy = y + slots2d[i].top
651
682
 
652
- parts.push(`<clipPath id="card${i}"><rect x="${cx}" y="${cy}" width="${g.cardW}" height="${cardH}" rx="12"/></clipPath>`)
683
+ parts.push(`<clipPath id="card${i}"><rect x="${cx}" y="${cy}" width="${cw}" height="${cardH}" rx="12"/></clipPath>`)
653
684
  parts.push(
654
- `<rect x="${cx}" y="${cy}" width="${g.cardW}" height="${cardH}" rx="12" fill="${t.card}"` +
685
+ `<rect x="${cx}" y="${cy}" width="${cw}" height="${cardH}" rx="12" fill="${t.card}"` +
655
686
  (card.failed ? ` stroke="${t.fail}" stroke-width="3"` : '') + '/>'
656
687
  )
657
688
  parts.push(`<g clip-path="url(#card${i})">`)
658
689
  // The image at NATURAL size (downscaled only when oversized), centred both
659
690
  // ways inside the ROW's shared slot: the two cards of a row keep the same
660
691
  // image zone and the same text zone, whatever each frame's own size.
661
- parts.push(`<rect x="${cx}" y="${cy}" width="${g.cardW}" height="${slotH}" fill="${t.slot}"/>`)
692
+ parts.push(`<rect x="${cx}" y="${cy}" width="${cw}" height="${slotH}" fill="${t.slot}"/>`)
662
693
  const data = fs.readFileSync(card.file).toString('base64')
663
694
  const iy = cy + BADGE_BAND + (slotH - BADGE_BAND - Math.ceil(dispH)) / 2
664
695
  parts.push(
665
- `<image x="${(cx + (g.cardW - dispW) / 2).toFixed(1)}" y="${iy.toFixed(1)}"` +
696
+ `<image x="${(cx + (cw - dispW) / 2).toFixed(1)}" y="${iy.toFixed(1)}"` +
666
697
  ` width="${dispW.toFixed(1)}" height="${dispH.toFixed(1)}" href="data:image/png;base64,${data}">` +
667
698
  `<title>${esc(path.basename(card.file))}${scale < 1 ? ` (shown at ${(scale * 100).toFixed(0)}%)` : ''}</title></image>`
668
699
  )
@@ -689,7 +720,7 @@ function render (outFile, options = {}) {
689
720
  }
690
721
  if (layout.copy.length) {
691
722
  ty += 6
692
- copyText(card.copy, cx + g.textPad, ty)
723
+ copyText(card.copy, cx + g.textPad, ty, { maxW: textWOf(card) })
693
724
  ty += layout.copy.length * 18
694
725
  }
695
726
  parts.push('</g>')
@@ -708,7 +739,7 @@ function render (outFile, options = {}) {
708
739
  // The W3C namespace is an identifier, not a network request.
709
740
  `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}"` + // DevSkim: ignore DS137138
710
741
  ' role="img" aria-labelledby="sb-title sb-desc">\n' +
711
- `<title id="sb-title">${esc(board.feature)} — ${esc(board.scenario)}</title>\n` +
742
+ `<title id="sb-title">${esc(board.feature)}: ${esc(board.scenario)}</title>\n` +
712
743
  `<desc id="sb-desc">e2e storyboard · ${esc(board.file)} · replay: ${esc(board.rerun)}</desc>\n` +
713
744
  `<style>${themeCss}.copy{user-select:all;-webkit-user-select:all;cursor:text}.copy:hover{text-decoration:underline}</style>\n` +
714
745
  `<rect width="${width}" height="${height}" fill="${t.bg}"/>\n` +