@digital-commons-official/codeceptjs-storyboard 0.3.1 → 0.4.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/README.md CHANGED
@@ -11,11 +11,14 @@ When the scenario ends the plugin assembles the whole story into one SVG: the fr
11
11
  ## Installation šŸ“¦
12
12
 
13
13
  ```bash
14
- npm install --save-dev @digital-commons-official/codeceptjs-storyboard @digital-commons-official/codeceptjs-visual-helper
14
+ npm install --save-dev codeceptjs playwright @digital-commons-official/codeceptjs-storyboard @digital-commons-official/codeceptjs-visual-helper
15
+ npx playwright install chromium
15
16
  ```
16
17
 
17
18
  Peer dependencies: `codeceptjs >= 4` and [`@digital-commons-official/codeceptjs-visual-helper`](https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-visual-helper) (the plugin captures and asserts through `I.takeScreenshot`, `I.captureScreenshot` and `I.assertVisualMatch`).
18
19
 
20
+ VisualHelper is required: enable it in CodeceptJS as shown below. Keeping it as a peer dependency lets the plugin use your project's helper and CodeceptJS installation.
21
+
19
22
  ## Configuration āš™ļø
20
23
 
21
24
  Register the plugin next to the visual helper in `codecept.conf.js`, and point Gherkin at your step files:
@@ -23,10 +26,16 @@ Register the plugin next to the visual helper in `codecept.conf.js`, and point G
23
26
  ```javascript
24
27
  exports.config = {
25
28
  output: './_output',
29
+ noGlobals: true,
26
30
  helpers: {
27
- Playwright: { browser: 'chromium', url: 'http://localhost:8080', show: false, windowSize: '1280x720' },
31
+ Playwright: {
32
+ browser: 'chromium',
33
+ url: 'http://localhost:8080',
34
+ show: false,
35
+ windowSize: '1280x720'
36
+ },
28
37
  VisualHelper: {
29
- require: '@digital-commons-official/codeceptjs-visual-helper',
38
+ require: require.resolve('@digital-commons-official/codeceptjs-visual-helper'),
30
39
  baselineDir: './screenshots/base/',
31
40
  diffDir: './screenshots/diff/',
32
41
  actualDir: './_output/',
@@ -131,6 +140,18 @@ storyboard.storyboardStep(Given, 'a fresh project with only a README on its main
131
140
  - `addStoryboardFrame(I, png)` refuses a blank frame, attaches the frame to the open card and asserts it against its own baseline at once. On drift the error names the frame, the pixel diff, the failure storyboard and the command that regenerates the baseline.
132
141
  - `annotate({ note, copy })` overrides the feature comments for a value only known at runtime.
133
142
 
143
+ ### Gherkin languages and examples
144
+
145
+ Set `# language: fr` (or another Cucumber dialect) on the first line of a feature file. Without this header, Gherkin uses English. Storyboards keep the source keywords, accents and scenario title, including keywords joined directly to the sentence. Register the translated sentences in your CodeceptJS step definitions.
146
+
147
+ Background steps and outline examples appear in execution order. Each example row gets its own SVG and baseline directory, with an `-example-<line>` suffix. Repeated sentences keep their own annotations.
148
+
149
+ `# Chapter`, `# Note` and `# Copy` remain the annotation keys in every language; outline values are substituted in them too. Text inside doc strings and data tables does not become an extra card or annotation.
150
+
151
+ Invalid syntax or an unknown dialect produces an error naming the feature file. The parser also reads rule backgrounds, but **CodeceptJS 4.2.0 does not execute scenarios nested in `Rule`**. Runner support is tracked in [#8](https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-storyboard/-/issues/8).
152
+
153
+ The [multilingual storyboard](tests/e2e/storyboards/05-languages/storyboard-languages.svg) runs English, French and German examples and shows a real visual regression on a French sentence.
154
+
134
155
  ### What you get
135
156
 
136
157
  - On every run the SVG of the scenario is written under `_output/<feature-dir>/<scenario-tag>.svg`.
@@ -173,6 +194,12 @@ task code # linters (MegaLinter)
173
194
 
174
195
  The e2e suite is the plugin's own dogfood: every scenario is a storyboard rendered by the plugin under test, committed under `tests/e2e/storyboards/`.
175
196
 
197
+ The [installation storyboard](tests/e2e/storyboards/06-installation/storyboard-consumer.svg) packs the current source, installs the tarball into a fresh project, and runs the README configuration verbatim. It checks CodeceptJS 4.2.0, Playwright 1.63.0 and VisualHelper 1.3.5 in Chromium. It opens the generated `index.html` and SVG, repeats the run with strict baselines, then proves that a changed page fails on its exact sentence.
198
+
199
+ The [consumer manifest](tests/e2e/consumer/package.json) pins those tools and overrides vulnerable transitive dependencies. Its lockfile makes the test repeatable. This verifies that combination; the wider peer dependency ranges are not a tested version matrix. The complete installation and run logs are kept in `tests/e2e/_output/consumer-install.log`.
200
+
201
+ Replay commands in the generated gallery and SVG currently assume a Toolbox project with `task test`. In a standalone project, use `npx codeceptjs run --grep "@your-tag"`. Configurable replay commands are tracked in [#12](https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-storyboard/-/issues/12).
202
+
176
203
  ## Licence šŸ“œ
177
204
 
178
205
  EUPL-1.2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digital-commons-official/codeceptjs-storyboard",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Storyboard plugin for CodeceptJS: one Gherkin sentence = one card = one pixel baseline, and every scenario renders itself as a single SVG storyboard",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -23,6 +23,7 @@
23
23
  "url": "git+https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-storyboard.git"
24
24
  },
25
25
  "dependencies": {
26
+ "@cucumber/gherkin": "^38.0.0",
26
27
  "pngjs": "^7.0.0"
27
28
  },
28
29
  "peerDependencies": {
package/src/gherkin.js ADDED
@@ -0,0 +1,108 @@
1
+ const fs = require('fs')
2
+ const { randomUUID } = require('crypto')
3
+ const { AstBuilder, GherkinClassicTokenMatcher, Parser, compile } = require('@cucumber/gherkin')
4
+
5
+ const GROUPS = { Context: 'given', Action: 'when', Outcome: 'then' }
6
+
7
+ function substitute (text, values) {
8
+ return text == null ? null : text.replace(/<([^>]+)>/g, (match, name) => Object.hasOwn(values, name) ? values[name] : match)
9
+ }
10
+
11
+ function annotations (comments, after, before) {
12
+ const result = { chapter: null, note: null, copy: null }
13
+ for (const comment of comments) {
14
+ if (comment.location.line <= after || comment.location.line >= before) continue
15
+ const match = comment.text.trim().match(/^#\s*(Chapter|Note|Copy)\s*:\s*(.+)$/i)
16
+ if (!match) continue
17
+ const kind = match[1].toLowerCase()
18
+ const value = match[2].trim()
19
+ result[kind] = kind === 'note' && result.note ? `${result.note}\n${value}` : value
20
+ }
21
+ return result
22
+ }
23
+
24
+ // CodeceptJS appends the example values when the outline name has no
25
+ // placeholders. Match its displayed title while Cucumber owns the grammar.
26
+ function runnerTitle (scenario, values) {
27
+ const json = JSON.stringify(values)
28
+ let title = `${scenario.name} ${json}`
29
+ for (const [name, value] of Object.entries(values)) {
30
+ if (title.includes(`<${name}>`)) title = title.replace(json, '').replace(`<${name}>`, value)
31
+ }
32
+ return title.trim()
33
+ }
34
+
35
+ function readScenario (file, title, { occurrence = 0 } = {}) {
36
+ let source
37
+ try {
38
+ source = fs.readFileSync(file, 'utf8')
39
+ } catch (error) {
40
+ if (error.code === 'ENOENT') return null
41
+ throw error
42
+ }
43
+ let document
44
+ let pickles
45
+ try {
46
+ const parser = new Parser(new AstBuilder(randomUUID), new GherkinClassicTokenMatcher())
47
+ document = parser.parse(source)
48
+ pickles = compile(document, file, randomUUID)
49
+ } catch (error) {
50
+ throw new Error(`storyboard: invalid Gherkin in ${file}: ${error.message}`)
51
+ }
52
+ if (!document.feature) throw new Error(`storyboard: no Feature in ${file}`)
53
+
54
+ const steps = new Map()
55
+ const scenarios = new Map()
56
+ const examples = new Map()
57
+ const visit = children => {
58
+ for (const child of children) {
59
+ if (child.rule) {
60
+ visit(child.rule.children)
61
+ continue
62
+ }
63
+ const container = child.scenario || child.background
64
+ let previous = container.location.line
65
+ for (const step of container.steps) {
66
+ steps.set(step.id, { ...step, annotations: annotations(document.comments, previous, step.location.line) })
67
+ previous = step.location.line
68
+ }
69
+ if (!child.scenario) continue
70
+ scenarios.set(container.id, container)
71
+ for (const table of container.examples) {
72
+ const fields = table.tableHeader ? table.tableHeader.cells.map(cell => cell.value) : []
73
+ for (const row of table.tableBody) {
74
+ examples.set(row.id, { line: row.location.line, values: Object.fromEntries(fields.map((field, i) => [field, row.cells[i].value])) })
75
+ }
76
+ }
77
+ }
78
+ }
79
+ visit(document.feature.children)
80
+ const matches = pickles.filter(pickle => {
81
+ const scenario = scenarios.get(pickle.astNodeIds[0])
82
+ const example = examples.get(pickle.astNodeIds[1])
83
+ return pickle.name === title || (example && runnerTitle(scenario, example.values) === title)
84
+ })
85
+ const pickle = matches[occurrence]
86
+ if (!pickle) return null
87
+ const scenario = scenarios.get(pickle.astNodeIds[0])
88
+ const example = examples.get(pickle.astNodeIds[1])
89
+ const values = example ? example.values : {}
90
+ let group = null
91
+ const lines = pickle.steps.map(compiled => {
92
+ const step = steps.get(compiled.astNodeIds[0])
93
+ group = GROUPS[step.keywordType] || group
94
+ return {
95
+ keyword: step.keyword.trim(),
96
+ keywordSeparator: /\s$/.test(step.keyword) ? ' ' : '',
97
+ group,
98
+ text: compiled.text,
99
+ chapter: substitute(step.annotations.chapter, values),
100
+ note: substitute(step.annotations.note, values),
101
+ copy: substitute(step.annotations.copy, values),
102
+ sourceLine: step.location.line
103
+ }
104
+ })
105
+ return { lines, keyword: scenario.keyword, title: pickle.name, exampleLine: example ? example.line : null }
106
+ }
107
+
108
+ module.exports = { readScenario }
package/src/index.d.ts CHANGED
@@ -18,12 +18,16 @@ export interface Annotation {
18
18
 
19
19
  /** One sentence of the scenario, read verbatim from the .feature source. */
20
20
  export interface ScenarioLine {
21
- keyword: 'Given' | 'When' | 'Then' | 'And' | 'But'
21
+ keyword: string
22
+ /** Empty for a keyword joined to its sentence, such as French qu' or Japanese. */
23
+ keywordSeparator?: string
22
24
  group: 'given' | 'when' | 'then' | null
23
25
  text: string
24
26
  chapter: string | null
25
27
  note: string | null
26
28
  copy: string | null
29
+ /** Original step line in the feature file, including for an expanded example. */
30
+ sourceLine?: number
27
31
  }
28
32
 
29
33
  /** One frame attached to a card. */
@@ -39,6 +43,7 @@ export interface Panel {
39
43
  note: string
40
44
  copy: string
41
45
  images: Frame[]
46
+ line?: ScenarioLine
42
47
  }
43
48
 
44
49
  /** Header metadata of the storyboard about to be built. */
@@ -50,6 +55,8 @@ export interface BoardMeta {
50
55
  baseDir?: string
51
56
  featureFile?: string
52
57
  lines?: ScenarioLine[]
58
+ /** Zero-based occurrence when several examples have the same rendered title. */
59
+ occurrence?: number
53
60
  }
54
61
 
55
62
  /** The drifted frame the plugin marks on a failed run. */
@@ -58,6 +65,7 @@ export interface FailureFrame {
58
65
  step: number
59
66
  sentence: string
60
67
  keyword: string
68
+ keywordSeparator?: string
61
69
  baseline: string
62
70
  actual: string
63
71
  diff: string | null
@@ -109,7 +117,7 @@ declare namespace storyboardPlugin {
109
117
  /** Baseline directory of the running scenario, `<feature-dir>/<scenario-tag>`. */
110
118
  function baseDir (): string
111
119
  /** Every sentence of a scenario, verbatim, with its attached # Chapter / # Note / # Copy comments. */
112
- function parseScenarioLines (featureFile: string, scenarioTitle: string): ScenarioLine[]
120
+ function parseScenarioLines (featureFile: string, scenarioTitle: string, options?: { occurrence?: number }): ScenarioLine[]
113
121
  /** Open a card (the plugin does it on bddStep.before). */
114
122
  function panel (title: string, opts?: Annotation): void
115
123
  /** Attach a PNG to the open card without asserting it. */
package/src/index.js CHANGED
@@ -56,6 +56,7 @@ const path = require('path')
56
56
  const { PNG } = require('pngjs')
57
57
  const { tryTo } = require('codeceptjs/effects')
58
58
  const { PROPERTIES, normalizeTheme, loadTheme } = require('./theme')
59
+ const { readScenario } = require('./gherkin')
59
60
 
60
61
  let board = null
61
62
 
@@ -68,70 +69,27 @@ function e2eDir () {
68
69
  return global.codecept_dir
69
70
  }
70
71
 
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
72
+ // Cucumber supplies the grammar and source locations, including backgrounds,
73
+ // dialects and substituted examples. No translated-keyword list lives here.
74
+ function parseScenarioLines (featureFile, scenarioTitle, options) {
75
+ const scenario = readScenario(featureFile, scenarioTitle, options)
76
+ if (!scenario) return []
77
+ return scenario.lines
123
78
  }
124
79
 
125
80
  // Fill the header from a scenario about to run. Exposed for the plugin AND
126
81
  // for direct calls (standalone rendering, tests).
127
82
  function begin (meta) {
83
+ const scenario = meta.featureFile ? readScenario(meta.featureFile, meta.scenario || '', { occurrence: meta.occurrence || 0 }) : null
128
84
  board = {
129
85
  feature: meta.feature || '',
130
- scenario: meta.scenario || '',
86
+ scenario: scenario ? scenario.title : (meta.scenario || ''),
87
+ scenarioKeyword: scenario ? scenario.keyword : 'Scenario',
88
+ exampleLine: scenario ? scenario.exampleLine : null,
131
89
  file: meta.file || '',
132
90
  rerun: meta.rerun || '',
133
91
  baseDir: meta.baseDir || '',
134
- lines: meta.featureFile ? parseScenarioLines(meta.featureFile, meta.scenario || '') : (meta.lines || []),
92
+ lines: scenario ? scenario.lines : (meta.lines || []),
135
93
  panels: []
136
94
  }
137
95
  }
@@ -147,7 +105,7 @@ function baseDir () {
147
105
 
148
106
  function panel (title, opts = {}) {
149
107
  if (!board) begin({})
150
- board.panels.push({ title, note: opts.note || '', copy: opts.copy || '', images: [] })
108
+ board.panels.push({ title, note: opts.note || '', copy: opts.copy || '', images: [], line: board.lines[board.panels.length] })
151
109
  }
152
110
 
153
111
  function frame (pngPath, opts = {}) {
@@ -326,6 +284,11 @@ function esc (text) {
326
284
  return String(text).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
327
285
  }
328
286
 
287
+ function sentenceOf (line, text = line.text) {
288
+ const separator = line.keywordSeparator === undefined ? ' ' : line.keywordSeparator
289
+ return (line.keyword ? line.keyword + separator : '') + text
290
+ }
291
+
329
292
  // SVG has no text auto-wrap: break on words against an estimated glyph width.
330
293
  function wrap (text, maxWidth, charWidth) {
331
294
  const perLine = Math.max(8, Math.floor(maxWidth / charWidth))
@@ -408,18 +371,19 @@ function render (outFile, options = {}) {
408
371
  // carries its expected / diff / actual triptych.
409
372
  // Verbatim Gherkin keyword of a sentence (And/But included), coloured by
410
373
  // its resolved group so the grid scans as stage / actions / proofs.
411
- const lineOf = (title) => (board.lines || []).find(l => l.text === title)
374
+ const lineOf = (card) => card.line
412
375
 
413
376
  const failName = failure && failure.frame && failure.frame.name
414
377
  // note/copy precedence: per-frame value > JS panel value (opts/annotate,
415
378
  // e.g. a URL only known at runtime) > `# Note:` / `# Copy:` comment in the
416
379
  // .feature — the feature file is the default source of the human text.
417
380
  const cards = board.panels.flatMap((p, pi) => {
418
- const line = lineOf(p.title)
381
+ const line = lineOf(p)
419
382
  return p.images.map((img, fi) => ({
420
383
  n: pi + 1,
421
384
  first: fi === 0,
422
385
  title: p.title,
386
+ line,
423
387
  note: img.note !== undefined ? img.note : (fi === 0 ? (p.note || (line && line.note) || '') : ''),
424
388
  copy: img.copy !== undefined ? img.copy : (fi === 0 ? (p.copy || (line && line.copy) || '') : ''),
425
389
  file: resolveImage(img.file),
@@ -505,7 +469,7 @@ function render (outFile, options = {}) {
505
469
  // Red header: which step and sentence regressed.
506
470
  parts.push(`<rect x="${g.pagePad}" y="${top}" width="${bandW}" height="${headerH}" rx="12" fill="${t.fail}"/>`)
507
471
  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}`,
472
+ text(`āœ– Visual regression — step ${frame.step}: ${sentenceOf(frame, frame.sentence)}`,
509
473
  g.pagePad + 18, top + 30, { size: 16, fill: '#ffffff', weight: '700' })
510
474
  text(frame.name, width - g.pagePad - 18, top + 30, { size: 12.5, fill: '#ffffff', font: t.mono, anchor: 'end' })
511
475
 
@@ -547,9 +511,9 @@ function render (outFile, options = {}) {
547
511
  // (bold sans ā‰ˆ 9.3px/char at 15.5px) — an over-wrap is invisible, an
548
512
  // under-wrap bleeds into the next card.
549
513
  const layoutOf = (card) => {
550
- const line = lineOf(card.title)
514
+ const line = lineOf(card)
551
515
  const keyword = line ? line.keyword : ''
552
- const title = wrap(`${keyword ? keyword + ' ' : ''}${card.title}`, textW, 9.3)
516
+ const title = wrap(line ? sentenceOf(line, card.title) : card.title, textW, 9.3)
553
517
  const note = card.note ? wrap(card.note, textW, 7.2) : []
554
518
  const copy = card.copy ? wrap(card.copy, textW, 8.0) : []
555
519
  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 }
@@ -592,7 +556,7 @@ function render (outFile, options = {}) {
592
556
  row = []
593
557
  }
594
558
  cards.forEach((card, i) => {
595
- const line = lineOf(card.title)
559
+ const line = lineOf(card)
596
560
  if (card.first && line && line.chapter) {
597
561
  flushRow()
598
562
  chapterBands.push({ title: line.chapter, top: rowTop, n: chapterBands.length + 1 })
@@ -614,7 +578,7 @@ function render (outFile, options = {}) {
614
578
  text(line, g.pagePad, hy, { size: 28, weight: '700' })
615
579
  hy += 34
616
580
  }
617
- for (const line of wrap('Scenario: ' + board.scenario, titleW, 8.7)) {
581
+ for (const line of wrap(board.scenarioKeyword + ': ' + board.scenario, titleW, 8.7)) {
618
582
  text(line, g.pagePad, hy - 6, { size: 15, fill: t.dim })
619
583
  hy += 20
620
584
  }
@@ -643,7 +607,7 @@ function render (outFile, options = {}) {
643
607
  fy += 34
644
608
  for (const line of failure.notReached) {
645
609
  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 })
610
+ text(`${sentenceOf(line)} — not reached`, g.pagePad + 26, fy, { size: 13.5, fill: t.dim })
647
611
  fy += 20
648
612
  }
649
613
  }
@@ -759,8 +723,8 @@ function render (outFile, options = {}) {
759
723
  function buildFailure (board) {
760
724
  const dir = global.codecept_dir
761
725
  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)
726
+ const notReached = (board.lines || []).filter((line, index) =>
727
+ !board.panels[index] || !board.panels[index].images.length
764
728
  )
765
729
  if (!board.visualFailure || !marked) return { frame: null, notReached }
766
730
 
@@ -769,7 +733,7 @@ function buildFailure (board) {
769
733
  const hasDiff = fs.existsSync(diffPath)
770
734
  const baseline = path.join(dir, 'screenshots', 'base', board.baseDir, name)
771
735
  const actual = path.join(dir, '_output', board.baseDir, name)
772
- const line = (board.lines || []).find(l => l.text === marked.title)
736
+ const line = marked.line
773
737
  const rel = (abs) => path.relative(process.cwd(), abs)
774
738
  return {
775
739
  frame: {
@@ -777,6 +741,7 @@ function buildFailure (board) {
777
741
  step: board.panels.indexOf(marked) + 1,
778
742
  sentence: marked.title,
779
743
  keyword: line ? line.keyword : '',
744
+ keywordSeparator: line ? line.keywordSeparator : ' ',
780
745
  baseline,
781
746
  actual,
782
747
  diff: hasDiff ? diffPath : null,
@@ -796,7 +761,7 @@ function buildFailure (board) {
796
761
  function logVisualRegression (frame, outputSvg) {
797
762
  console.error(
798
763
  '\n════════════════════════════════════════════════════════════════\n' +
799
- `āœ– VISUAL REGRESSION — step ${frame.step}: ${frame.keyword} ${frame.sentence}\n` +
764
+ `āœ– VISUAL REGRESSION — step ${frame.step}: ${sentenceOf(frame, frame.sentence)}\n` +
800
765
  ' The failure storyboard sums it all up (expected / diff / actual):\n' +
801
766
  ` šŸŽ¬ open in a browser: ${path.relative(process.cwd(), outputSvg)}\n` +
802
767
  '════════════════════════════════════════════════════════════════\n'
@@ -849,9 +814,11 @@ module.exports = function storyboardPlugin (config = {}) {
849
814
  scenario: stripTags(test.title),
850
815
  file,
851
816
  featureFile: test.file,
817
+ occurrence: Math.max(0, (test.parent.tests || []).filter(other => other.title === test.title).indexOf(test)),
852
818
  baseDir: base,
853
819
  rerun: tag ? `task test -- --grep "${tag}"` : ''
854
820
  })
821
+ if (board.exampleLine) board.baseDir += `-example-${board.exampleLine}`
855
822
  if (config.theme) {
856
823
  const current = board
857
824
  recorder.add('load storyboard theme', async () => {
@@ -867,6 +834,8 @@ module.exports = function storyboardPlugin (config = {}) {
867
834
  event.dispatcher.on(event.bddStep.before, (step) => {
868
835
  if (!board) return
869
836
  panel(step.text)
837
+ const current = board.panels[board.panels.length - 1]
838
+ if (step.keyword) current.line = { ...current.line, keyword: step.keyword.trim(), keywordSeparator: /\s$/.test(step.keyword) ? ' ' : '', text: step.text }
870
839
  })
871
840
 
872
841
  const finish = (passed) => {