@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/README.md CHANGED
@@ -1,3 +1,178 @@
1
- # Temporary Holding Version
1
+ <!-- cspell:ignore storyboardStep addStoryboardFrame capturePageFrame captureElementFrame -->
2
+ # 🎬 codeceptjs-storyboard
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ [![pipeline status](https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-storyboard/badges/main/pipeline.svg)](https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-storyboard/-/commits/main)
5
+
6
+ A [CodeceptJS](https://codecept.io) plugin that turns one Gherkin scenario into one human-readable SVG storyboard, straight from the real screenshots the test captures.
7
+
8
+ ONE Gherkin sentence = ONE card = ONE pixel baseline, asserted inside its step at `tolerance: 0`: a visual regression fails on the exact sentence whose image drifted.
9
+ When the scenario ends the plugin assembles the whole story into one SVG: the frames stay bitmap, but every caption, note and reproduce-command around them is real selectable text you can copy from the SVG (Chromium/Safari).
10
+
11
+ ## Installation 📦
12
+
13
+ ```bash
14
+ npm install --save-dev @digital-commons-official/codeceptjs-storyboard @digital-commons-official/codeceptjs-visual-helper
15
+ ```
16
+
17
+ 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
+ ## Configuration ⚙️
20
+
21
+ Register the plugin next to the visual helper in `codecept.conf.js`, and point Gherkin at your step files:
22
+
23
+ ```javascript
24
+ exports.config = {
25
+ output: './_output',
26
+ helpers: {
27
+ Playwright: { browser: 'chromium', url: 'http://localhost:8080', show: false, windowSize: '1280x720' },
28
+ VisualHelper: {
29
+ require: '@digital-commons-official/codeceptjs-visual-helper',
30
+ baselineDir: './screenshots/base/',
31
+ diffDir: './screenshots/diff/',
32
+ actualDir: './_output/',
33
+ tolerance: 0,
34
+ captureBaseline: false
35
+ }
36
+ },
37
+ gherkin: {
38
+ features: './features/**/*.feature',
39
+ steps: ['./steps/first-run.js']
40
+ },
41
+ plugins: {
42
+ storyboard: {
43
+ require: '@digital-commons-official/codeceptjs-storyboard',
44
+ enabled: true
45
+ }
46
+ }
47
+ }
48
+ ```
49
+
50
+ Nothing configures paths: everything is derived from the feature file location.
51
+ Frames land in `_output/storyboard-frames/`, baselines in `screenshots/base/<feature-dir>/<scenario-tag>/`, the committed SVG in `storyboards/<feature-dir>/<scenario-tag>.svg`.
52
+ A scenario that never calls `addStoryboardFrame` renders no SVG, so plain Gherkin tests are left untouched.
53
+
54
+ When the run ends, open `_output/index.html` to browse its storyboards. The page groups scenarios by feature directory, puts failed groups and scenarios first, and shows the failed sentence with its replay command. Links open the actual SVGs.
55
+
56
+ A filtered run lists only the scenarios it ran. In baseline-update mode, `storyboards/index.html` lists the passing scenarios from that update; failed scenarios never replace reviewed storyboards. Run the full suite in update mode to rebuild the complete reviewed gallery.
57
+
58
+ ### Colours and fonts
59
+
60
+ Set `theme` on the storyboard plugin to an object, a CSS file path, or an HTTP(S) URL:
61
+
62
+ ```javascript
63
+ storyboard: {
64
+ require: '@digital-commons-official/codeceptjs-storyboard',
65
+ enabled: true,
66
+ theme: './storyboard.css'
67
+ // Or: theme: 'https://example.org/storyboard.css'
68
+ // Or: theme: { bg: '#f6f8fb', text: '#192b3d', sans: 'Georgia, serif' }
69
+ }
70
+ ```
71
+
72
+ Relative paths start at the directory containing `codecept.conf.js`. The plugin loads the theme once per run, before the first scenario's steps, and embeds its values in every SVG. Remote requests time out after five seconds. A missing, unreachable or invalid theme emits a warning and uses the default dark theme.
73
+
74
+ ```css
75
+ :root {
76
+ --sb-bg: #f6f8fb;
77
+ --sb-card: #ffffff;
78
+ --sb-slot: #edf2f8;
79
+ --sb-text: #192b3d;
80
+ --sb-dim: #42576b;
81
+ --sb-accent: #175fa4;
82
+ --sb-code-bg: #e7eef7;
83
+ --sb-given: #356b16;
84
+ --sb-when: #175fa4;
85
+ --sb-then: #7b3990;
86
+ --sb-font-sans: Georgia, serif;
87
+ }
88
+ ```
89
+
90
+ Supported object keys are `bg`, `card`, `slot`, `text`, `dim`, `accent`, `badge`, `codeBg`, `given`, `when`, `then`, `fail`, `sans` and `mono`. CSS uses `--sb-<key>`, except `codeBg` becomes `--sb-code-bg`, and the fonts use `--sb-font-sans` and `--sb-font-mono`. Omitted values keep their defaults. Colours accept hex, named colours, `rgb()` and `hsl()` values; fonts accept installed font family names and fallback lists.
91
+
92
+ Only these properties are read. Imports, external fonts and arbitrary CSS rules are not embedded. The SVG works offline; install the same fonts on machines where matching typography matters. Themes change the labels and cards around captured frames; the screenshot pixels stay unchanged.
93
+
94
+ ## Usage 🚀
95
+
96
+ ### The `.feature` is the single human-authored source
97
+
98
+ Attach structured comments to the sentence just below them. The feature file carries the story, the step file only drives and captures:
99
+
100
+ - `# Chapter: Title` opens a full-width chapter band before that card.
101
+ - `# Note: text` is the card's explanation: what to look at, why it matters. Repeat the line to stack paragraphs.
102
+ - `# Copy: command` is the exact command shown one-click-copyable under the card.
103
+
104
+ The scenario's LAST tag names the baseline directory and the replay command printed on the board.
105
+
106
+ ```gherkin
107
+ @e2e @first-run
108
+ Feature: A developer opens their new project
109
+ Scenario: The project home shows the framework
110
+ # Chapter: The empty project
111
+ # Note: The project as GitLab shows it, before anything is installed.
112
+ # Copy: http://gitlab/<user>/<project>
113
+ Given a fresh project with only a README on its main branch
114
+ ```
115
+
116
+ ### The step file drives and captures
117
+
118
+ ```javascript
119
+ /* global inject Given */
120
+ const { I } = inject()
121
+ const storyboard = require('@digital-commons-official/codeceptjs-storyboard')
122
+
123
+ storyboard.storyboardStep(Given, 'a fresh project with only a README on its main branch', async () => {
124
+ await I.amOnPage('/my/project')
125
+ await storyboard.addStoryboardFrame(I, await storyboard.capturePageFrame(I, 'project-home'))
126
+ })
127
+ ```
128
+
129
+ - `storyboardStep(register, sentence, fn)` registers the step and escapes cucumber-expression metacharacters, so `CI/CD` or `(y/N)` in a sentence never breaks the match. Cards open automatically for every sentence.
130
+ - `capturePageFrame(I, name)` captures the full viewport; `captureElementFrame(I, name, selector)` crops the frame to one element, so a short verdict yields a short card.
131
+ - `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
+ - `annotate({ note, copy })` overrides the feature comments for a value only known at runtime.
133
+
134
+ ### What you get
135
+
136
+ - On every run the SVG of the scenario is written under `_output/<feature-dir>/<scenario-tag>.svg`.
137
+ - On a failed run that SVG shows, in place of the drifted card, a red band with the expected image, the changed pixels and the actual image, each over its copyable path, then lists the sentences the run never reached.
138
+ - In baseline-update mode the plugin asserts first and rewrites a baseline only when its assert fails, then rebuilds the committed SVG under `storyboards/` from the reviewed baselines:
139
+
140
+ ```bash
141
+ TASK_E2E_UPDATE_BASELINES=1 npx codeceptjs run
142
+ ```
143
+
144
+ Every baseline written this way must be inspected by a human, which is why the mode throws when `CI` is set.
145
+
146
+ ## API 📚
147
+
148
+ | Function | Purpose |
149
+ |-------------------------------------------------|--------------------------------------------------------------------------|
150
+ | `storyboardStep(register, sentence, fn)` | Register a sentence literally through `Given`, `When` or `Then` |
151
+ | `capturePageFrame(I, name)` | Full-viewport frame, returns the PNG path |
152
+ | `captureElementFrame(I, name, selector)` | Element-cropped frame, returns the PNG path |
153
+ | `addStoryboardFrame(I, png)` | Attach the frame to the open card and assert it at `tolerance: 0` |
154
+ | `annotate({ note, copy })` | Runtime override of the open card's note and copyable command |
155
+ | `assertOrUpdateBaseline(I, name)` | The assert-or-rewrite primitive `addStoryboardFrame` relies on |
156
+ | `render(outFile, { imageDir, failure, theme })` | Write the SVG, optionally with a theme object |
157
+ | `parseScenarioLines(featureFile, title)` | Every sentence of a scenario with its `# Chapter` / `# Note` / `# Copy` |
158
+ | `begin`, `panel`, `frame`, `panels` | The board primitives the plugin drives (useful for standalone rendering) |
159
+
160
+ Type definitions ship in `src/index.d.ts`.
161
+
162
+ ## Development 🛠️
163
+
164
+ ```bash
165
+ task build # install dependencies + build the e2e runner image
166
+ task test # unit tests, then the e2e storyboard suite
167
+ task project:test:storyboard # unit tests only (vitest)
168
+ task project:test:storyboard:e2e # e2e storyboard suite only, inside the pinned Playwright runner
169
+ task project:test:storyboard:e2e -- --grep "@storyboard-happy-path"
170
+ TASK_E2E_UPDATE_BASELINES=1 task project:test:storyboard:e2e # regenerate drifted baselines + committed SVGs, then LOOK at them
171
+ task code # linters (MegaLinter)
172
+ ```
173
+
174
+ 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
+
176
+ ## Licence 📜
177
+
178
+ EUPL-1.2
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@digital-commons-official/codeceptjs-storyboard",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
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
+ "main": "src/index.js",
6
+ "types": "src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.d.ts",
10
+ "import": "./src/index.js",
11
+ "require": "./src/index.js",
12
+ "default": "./src/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "src/**/*"
17
+ ],
18
+ "scripts": {
19
+ "test": "vitest run"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-storyboard.git"
24
+ },
25
+ "dependencies": {
26
+ "pngjs": "^7.0.0"
27
+ },
28
+ "peerDependencies": {
29
+ "@digital-commons-official/codeceptjs-visual-helper": ">=1.3.0",
30
+ "codeceptjs": ">=4.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@digital-commons-official/codeceptjs-visual-helper": "1.3.4",
34
+ "codeceptjs": "4.2.0",
35
+ "playwright": "1.63.0",
36
+ "standard": "^17.1.2",
37
+ "vitest": "^5.0.0"
38
+ },
39
+ "overrides": {
40
+ "axios": "^1.18.0",
41
+ "uuid": "^14.0.0",
42
+ "joi": "^18.2.1",
43
+ "diff": "^9.0.0",
44
+ "serialize-javascript": "^7.0.5",
45
+ "undici": "^8.0.0",
46
+ "@xmldom/xmldom": "^0.9.12"
47
+ },
48
+ "keywords": [
49
+ "codeceptjs",
50
+ "storyboard",
51
+ "visual-testing",
52
+ "visual-regression",
53
+ "gherkin",
54
+ "bdd",
55
+ "e2e-testing",
56
+ "playwright",
57
+ "svg"
58
+ ],
59
+ "author": "Digital Commons",
60
+ "license": "EUPL-1.2",
61
+ "engines": {
62
+ "node": ">=18.0.0"
63
+ }
64
+ }
package/src/gallery.js ADDED
@@ -0,0 +1,77 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ function escape (value) {
5
+ return String(value || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
6
+ }
7
+
8
+ function entryHtml (entry) {
9
+ const href = entry.baseDir.split(path.sep).map(encodeURIComponent).join('/') + '.svg'
10
+ return `<li class="${entry.passed ? 'passed' : 'failed'}">
11
+ <span class="status">${entry.passed ? 'Passed' : 'Failed'}</span>
12
+ <h3><a href="${escape(href)}">${escape(entry.scenario)}</a></h3>
13
+ ${entry.sentence ? ` <p class="failure">${escape(entry.sentence)}</p>` : ''}
14
+ ${entry.rerun ? ` <pre><code>${escape(entry.rerun)}</code></pre>` : ''}
15
+ </li>`
16
+ }
17
+
18
+ // Entries come from this run's test events, never from a directory listing:
19
+ // a filtered rerun must not make yesterday's pictures look freshly checked.
20
+ module.exports = function writeGallery (directory, entries) {
21
+ const groups = new Map()
22
+ for (const entry of entries) {
23
+ const group = path.dirname(entry.baseDir)
24
+ if (!groups.has(group)) groups.set(group, [])
25
+ groups.get(group).push(entry)
26
+ }
27
+ const hasFailure = entries => entries.some(entry => !entry.passed)
28
+ const ordered = [...groups].sort(([a, aa], [b, bb]) => Number(hasFailure(bb)) - Number(hasFailure(aa)) || a.localeCompare(b))
29
+ const content = ordered.map(([group, stories]) => {
30
+ const rows = [...stories].sort((a, b) => Number(a.passed) - Number(b.passed) || a.scenario.localeCompare(b.scenario)).map(entryHtml).join('\n')
31
+ return `<section>\n<h2>${escape(group === '.' ? 'Scenarios' : group)}</h2>\n<ul>${rows}</ul>\n</section>`
32
+ }).join('\n')
33
+ const html = `<!DOCTYPE html>
34
+ <html lang="en">
35
+ <head>
36
+ <meta charset="utf-8">
37
+ <meta name="viewport" content="width=device-width, initial-scale=1">
38
+ <meta name="description" content="Browse this test run's storyboards and replay failed scenarios.">
39
+ <title>Storyboards</title>
40
+ <style>
41
+ :root { color-scheme: dark; font-family: system-ui, sans-serif; background: #0f1017; color: #e8e8ec; }
42
+ * { box-sizing: border-box; }
43
+ body { margin: 0; }
44
+ main { max-width: 960px; margin: auto; padding: 32px; }
45
+ h1 { margin: 0 0 8px; font-size: 36px; }
46
+ header p, h2 { color: #98a0b3; }
47
+ header p { margin: 0; line-height: 1.6; }
48
+ h2 { margin: 32px 0 12px; font-size: 18px; font-weight: 500; }
49
+ h3 { margin: 4px 0 12px; font-size: 20px; line-height: 1.4; }
50
+ ul { list-style: none; padding: 0; margin: 0; }
51
+ li { padding: 20px 24px; margin-bottom: 12px; background: #181a24; border-left: 4px solid #9ece6a; }
52
+ li.failed { border-color: #f7768e; }
53
+ .status { color: #9ece6a; font-size: 14px; }
54
+ .failed .status, .failure { color: #f7768e; }
55
+ .failure { overflow-wrap: anywhere; }
56
+ a { color: #7aa2f7; text-underline-offset: 4px; }
57
+ a:hover { color: #e8e8ec; }
58
+ a:focus-visible { outline: 2px solid #e8e8ec; outline-offset: 4px; }
59
+ pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
60
+ code { font-size: 13px; line-height: 1.6; }
61
+ @media (max-width: 600px) { main { padding: 20px; } li { padding: 16px; } }
62
+ </style>
63
+ </head>
64
+ <body>
65
+ <main>
66
+ <header>
67
+ <h1>Storyboards</h1>
68
+ <p>Open a scenario to review its pictures. Copy its command to run it again.</p>
69
+ </header>
70
+ ${content || '<p>No storyboards in this run.</p>'}
71
+ </main>
72
+ </body>
73
+ </html>
74
+ `
75
+ fs.mkdirSync(directory, { recursive: true })
76
+ fs.writeFileSync(path.join(directory, 'index.html'), html)
77
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Type definitions for @digital-commons-official/codeceptjs-storyboard.
3
+ */
4
+
5
+ /** A CodeceptJS actor extended by codeceptjs-visual-helper. */
6
+ export interface StoryboardActor {
7
+ takeScreenshot: (name: string) => Promise<void>
8
+ captureScreenshot: (name: string, target?: string, elementSelector?: string) => Promise<void>
9
+ assertVisualMatch: (name: string, options?: Record<string, unknown>) => Promise<void>
10
+ [method: string]: unknown
11
+ }
12
+
13
+ /** Runtime overrides of a card's note and copyable command. */
14
+ export interface Annotation {
15
+ note?: string
16
+ copy?: string
17
+ }
18
+
19
+ /** One sentence of the scenario, read verbatim from the .feature source. */
20
+ export interface ScenarioLine {
21
+ keyword: 'Given' | 'When' | 'Then' | 'And' | 'But'
22
+ group: 'given' | 'when' | 'then' | null
23
+ text: string
24
+ chapter: string | null
25
+ note: string | null
26
+ copy: string | null
27
+ }
28
+
29
+ /** One frame attached to a card. */
30
+ export interface Frame {
31
+ file: string
32
+ note?: string
33
+ copy?: string
34
+ }
35
+
36
+ /** One card: a Gherkin sentence and the frames captured inside its step. */
37
+ export interface Panel {
38
+ title: string
39
+ note: string
40
+ copy: string
41
+ images: Frame[]
42
+ }
43
+
44
+ /** Header metadata of the storyboard about to be built. */
45
+ export interface BoardMeta {
46
+ feature?: string
47
+ scenario?: string
48
+ file?: string
49
+ rerun?: string
50
+ baseDir?: string
51
+ featureFile?: string
52
+ lines?: ScenarioLine[]
53
+ }
54
+
55
+ /** The drifted frame the plugin marks on a failed run. */
56
+ export interface FailureFrame {
57
+ name: string
58
+ step: number
59
+ sentence: string
60
+ keyword: string
61
+ baseline: string
62
+ actual: string
63
+ diff: string | null
64
+ paths: { expected: string, diff: string, actual: string }
65
+ }
66
+
67
+ /** Colours and installed font families used around the captured frames. */
68
+ export interface Theme {
69
+ bg?: string
70
+ card?: string
71
+ slot?: string
72
+ text?: string
73
+ dim?: string
74
+ accent?: string
75
+ badge?: string
76
+ codeBg?: string
77
+ given?: string
78
+ when?: string
79
+ then?: string
80
+ fail?: string
81
+ sans?: string
82
+ mono?: string
83
+ }
84
+
85
+ export interface StoryboardConfig {
86
+ /** Theme object, CSS file relative to codecept.conf.js, or HTTP(S) CSS URL. */
87
+ theme?: Theme | string
88
+ [option: string]: unknown
89
+ }
90
+
91
+ export interface RenderOptions {
92
+ /** Inline overrides for standalone rendering. */
93
+ theme?: Theme
94
+ /** Substitute every frame with the same-named PNG inside this directory (the reviewed baselines). */
95
+ imageDir?: string
96
+ /** Marks the drifted card in red, adds the expected/diff/actual band and the sentences never reached. */
97
+ failure?: { frame: FailureFrame | null, notReached: ScenarioLine[] } | null
98
+ }
99
+
100
+ type StepRegister = (pattern: string, fn: (...args: any[]) => unknown) => void
101
+ type StepFunction = (...args: any[]) => Promise<unknown> | unknown
102
+
103
+ /** The CodeceptJS plugin factory: `plugins: { storyboard: { require: '@digital-commons-official/codeceptjs-storyboard', enabled: true } }`. */
104
+ declare function storyboardPlugin (config?: StoryboardConfig): void
105
+
106
+ declare namespace storyboardPlugin {
107
+ /** Fill the header for the scenario about to run (the plugin calls it on test.before). */
108
+ function begin (meta: BoardMeta): void
109
+ /** Baseline directory of the running scenario, `<feature-dir>/<scenario-tag>`. */
110
+ function baseDir (): string
111
+ /** Every sentence of a scenario, verbatim, with its attached # Chapter / # Note / # Copy comments. */
112
+ function parseScenarioLines (featureFile: string, scenarioTitle: string): ScenarioLine[]
113
+ /** Open a card (the plugin does it on bddStep.before). */
114
+ function panel (title: string, opts?: Annotation): void
115
+ /** Attach a PNG to the open card without asserting it. */
116
+ function frame (pngPath: string, opts?: Annotation): void
117
+ /** Merge a runtime note/copy into the open card. */
118
+ function annotate (opts: Annotation): void
119
+ /** The cards captured so far. */
120
+ function panels (): Panel[]
121
+ /** Register a Gherkin sentence literally (cucumber-expression metacharacters escaped). */
122
+ function storyboardStep (register: StepRegister, pattern: string, fn: StepFunction): void
123
+ function storyboardStep (register: StepRegister, pattern: string, opts: Annotation | null, fn: StepFunction): void
124
+ /** Full-viewport capture into _output/storyboard-frames/<name>.png; returns the absolute path. */
125
+ function capturePageFrame (I: StoryboardActor, frameName: string): Promise<string>
126
+ /** Element-cropped capture; the frame is exactly the selector's box. */
127
+ function captureElementFrame (I: StoryboardActor, frameName: string, selector: string): Promise<string>
128
+ /** Absolute path a frame of that name is written to. */
129
+ function frameOutputPath (frameName: string): string
130
+ /** Assert _output/<name>.png against screenshots/base/<name>.png, or rewrite the baseline in update mode. */
131
+ function assertOrUpdateBaseline (I: StoryboardActor, baselineName: string): Promise<void>
132
+ /** Attach the frame to the open card and assert it against its own baseline at tolerance 0. */
133
+ function addStoryboardFrame (I: StoryboardActor, png: string): Promise<void>
134
+ /** Write the storyboard SVG of the cards captured so far; returns outFile. */
135
+ function render (outFile: string, options?: RenderOptions): string
136
+ /** Re-export of codeceptjs/effects tryTo. */
137
+ function tryTo (fn: () => unknown): Promise<boolean>
138
+ }
139
+
140
+ export = storyboardPlugin