@digital-commons-official/codeceptjs-storyboard 0.4.12 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,10 +15,66 @@ npm install --save-dev codeceptjs playwright @digital-commons-official/codeceptj
15
15
  npx playwright install chromium
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
+ Requires Node.js `>= 22.19.0`, CodeceptJS `^4.2.0` and
19
+ [`@digital-commons-official/codeceptjs-visual-helper`](https://gitlab.com/digital-commons/software/libraries/npm/codeceptjs-visual-helper)
20
+ `>= 1.3.0`. The plugin captures and asserts through `I.takeScreenshot`,
21
+ `I.captureScreenshot` and `I.assertVisualMatch`.
19
22
 
20
23
  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
24
 
25
+ ### Tested versions
26
+
27
+ The browser suite installs the actual packed package into six fresh projects:
28
+
29
+ | Node.js | CodeceptJS | VisualHelper |
30
+ |---------------------------|------------|--------------|
31
+ | 22.19.0, 24.21.0, 26.10.0 | 4.2.0 | 1.3.0 |
32
+ | 22.19.0, 24.21.0, 26.10.0 | 4.2.0 | 2.0.3 |
33
+
34
+ Each project imports its own four packages, passes `npm audit`, records one
35
+ English journey and three French Rule cases, then reruns with strict pixel
36
+ comparison. All fourteen baseline hashes must stay unchanged and match across
37
+ the six combinations. The real gallery must link all four journeys.
38
+
39
+ Node 18 is rejected with `--engine-strict`; CodeceptJS 4.0 is rejected with
40
+ `--strict-peer-deps`. Older CodeceptJS 4.0 consumers also fail the security audit.
41
+ The declared ranges allow later compatible versions; the table states the exact
42
+ versions exercised in CI. Use the same Playwright browser and fonts when
43
+ comparing pictures across machines.
44
+
45
+ These installation tests use `npm pack` and real npm commands. They do not
46
+ authenticate a publication to the registry; the release job and npm provenance
47
+ provide that separate proof.
48
+
49
+ ## Public API and compatibility
50
+
51
+ The package root exports the CodeceptJS plugin factory and these functions.
52
+ Their signatures are defined in [src/index.d.ts](src/index.d.ts).
53
+
54
+ | Functions | Contract |
55
+ |--------------------------------------------------------------|------------------------------------------------------------------------------------------|
56
+ | `storyboardStep` | Register a literal sentence and its optional note/copy annotation. |
57
+ | `capturePageFrame`, `captureElementFrame`, `frameOutputPath` | Capture a real viewport or element and return its frame path. |
58
+ | `addStoryboardFrame`, `assertOrUpdateBaseline` | Assert pixels strictly; only `TASK_E2E_UPDATE_BASELINES=1` outside CI records baselines. |
59
+ | `begin`, `baseDir`, `panel`, `frame`, `annotate`, `panels` | Manage a scenario's cards; `frame` attaches an image without asserting it. |
60
+ | `parseScenarioLines`, `render` | Read the original Gherkin sentences and render their SVG. |
61
+ | `tryTo` | Re-export the CodeceptJS effect for an optional action. |
62
+
63
+ The supported plugin options are `theme` and `replayCommand`; CodeceptJS owns
64
+ `require` and `enabled`. From 1.0.0, compatible releases preserve this public
65
+ API and the documented baseline recording behaviour. Removing a public
66
+ function, changing its required arguments or raising a supported minimum
67
+ requires a major release. Internal modules under `src/` are implementation
68
+ details; use the package root.
69
+
70
+ The parser follows Cucumber's Gherkin dialects. Feature and Rule backgrounds,
71
+ Scenario Outlines and Examples, inherited tags, repeated titles, data tables
72
+ and doc strings are supported. Real browser journeys cover English, French
73
+ and German; parser tests cover other dialects, including joined keywords.
74
+ Tables and doc strings are step arguments, not extra cards. A filtered run
75
+ with no matching scenario fails. Future dependency versions still need the
76
+ same compatibility checks; the matrix above identifies the versions verified.
77
+
22
78
  ## Configuration ⚙️
23
79
 
24
80
  Register the plugin next to the visual helper in `codecept.conf.js`, and point Gherkin at your step files:
@@ -169,10 +225,20 @@ Background steps and outline examples appear in execution order. Each example ro
169
225
 
170
226
  `# 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.
171
227
 
172
- 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).
228
+ Invalid syntax or an unknown dialect produces an error naming the feature file.
229
+ The enabled plugin completes CodeceptJS's Gherkin loader for `Rule` scenarios,
230
+ including localized keywords such as `Règle`. The feature background runs before
231
+ each case; a rule background runs only for cases in that rule. Outline examples
232
+ remain separate tests and rule tags can be selected with `--grep`. Repeated
233
+ scenario titles in different rules keep their own source annotations.
234
+ An empty selection fails clearly instead of succeeding with zero tests.
173
235
 
174
236
  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.
175
237
 
238
+ The [rule storyboard](tests/e2e/storyboards/07-rules/storyboard-rules.svg) executes
239
+ two French outline examples and a second rule, checks both backgrounds and the
240
+ tag filter, and proves the exact sentence of a deliberate visual regression.
241
+
176
242
  ### What you get
177
243
 
178
244
  - On every run the SVG of the scenario is written under `_output/<feature-dir>/<scenario-tag>.svg`.
@@ -221,7 +287,7 @@ The [installation storyboard](tests/e2e/storyboards/06-installation/storyboard-c
221
287
  It checks CodeceptJS 4.2.0, Playwright 1.63.0 and VisualHelper 1.3.5 in Chromium.
222
288
  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.
223
289
 
224
- 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`.
290
+ The [consumer manifest](tests/e2e/consumer/package.json) pins those tools and overrides vulnerable transitive dependencies. Its lockfile makes the test repeatable. The separate [version matrix](tests/e2e/features/08-compatibility/matrix.feature) verifies the six combinations listed above. Complete installation and run logs are kept in `tests/e2e/_output/consumer-install.log` and `tests/e2e/_output/matrix/`.
225
291
 
226
292
  The clean-consumer test also copies the replay command from the generated gallery
227
293
  and executes it unchanged, then checks that every strict baseline hash is intact.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digital-commons-official/codeceptjs-storyboard",
3
- "version": "0.4.12",
3
+ "version": "1.0.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",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@digital-commons-official/codeceptjs-visual-helper": ">=1.3.0",
31
- "codeceptjs": ">=4.0.0"
31
+ "codeceptjs": "^4.2.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@digital-commons-official/codeceptjs-visual-helper": "2.0.3",
@@ -60,6 +60,6 @@
60
60
  "author": "Digital Commons",
61
61
  "license": "EUPL-1.2",
62
62
  "engines": {
63
- "node": ">=18.0.0"
63
+ "node": ">=22.19.0"
64
64
  }
65
65
  }
package/src/index.js CHANGED
@@ -780,11 +780,14 @@ function logVisualRegression (frame, outputSvg) {
780
780
  // (feature name) in lib/mocha/gherkin.js; titles carry the tags appended.
781
781
  // ---------------------------------------------------------------------------
782
782
  module.exports = function storyboardPlugin (config = {}) {
783
- const { event, recorder } = require('codeceptjs')
783
+ const { event, recorder, container } = require('codeceptjs')
784
784
  const replayCommand = config.replayCommand ?? 'npx codeceptjs run --steps --grep "{tag}"'
785
785
  const writeGallery = require('./gallery')
786
786
  const entries = new Map()
787
787
  let themePromise
788
+ event.dispatcher.prependListener(event.all.before, () => {
789
+ require('./rules')(container.mocha())
790
+ })
788
791
  event.dispatcher.on(event.all.before, () => {
789
792
  entries.clear()
790
793
  themePromise = null
@@ -815,7 +818,7 @@ module.exports = function storyboardPlugin (config = {}) {
815
818
  scenario: stripTags(test.title),
816
819
  file,
817
820
  featureFile: test.file,
818
- occurrence: Math.max(0, (test.parent.tests || []).filter(other => other.title === test.title).indexOf(test)),
821
+ occurrence: Math.max(0, (test.parent.tests || []).filter(other => stripTags(other.title) === stripTags(test.title)).indexOf(test)),
819
822
  baseDir: base,
820
823
  rerun: tag ? replayCommand.replaceAll('{tag}', tag) : ''
821
824
  })
package/src/rules.js ADDED
@@ -0,0 +1,71 @@
1
+ const fs = require('node:fs')
2
+ const { randomUUID } = require('node:crypto')
3
+ const { AstBuilder, GherkinClassicTokenMatcher, Parser, compile } = require('@cucumber/gherkin')
4
+
5
+ function ruleSource (source, feature, rule, next) {
6
+ const lines = source.split('\n')
7
+ const end = next ? Math.min(next.location.line, ...next.tags.map(tag => tag.location.line)) - 1 : lines.length
8
+ const tags = [...feature.tags, ...rule.tags].map(tag => tag.name).join(' ')
9
+ return `# language: ${feature.language}\n${tags}\n${feature.keyword}: ${feature.name} / ${rule.name}\n` + lines.slice(rule.location.line, end).join('\n')
10
+ }
11
+
12
+ function appendRule (suite, parsed, rule) {
13
+ // Reuse CodeceptJS's wrapped tests and BDD hooks without wrapping them twice.
14
+ // The original feature hook runs first; this hook belongs only to this rule.
15
+ parsed.ctx = suite.ctx
16
+ const tests = new Set(parsed.tests)
17
+ const background = parsed._beforeEach.find(hook => hook.title.endsWith(': Before'))
18
+ if (background) {
19
+ suite.beforeEach(`storyboard rule: ${rule.name}`, function (done) {
20
+ if (tests.has(this.currentTest)) return background.fn.call(this, done)
21
+ done()
22
+ })
23
+ }
24
+ for (const test of parsed.tests) {
25
+ test.title = `${test.title} ${rule.tags.map(tag => tag.name).join(' ')}`.trim()
26
+ test.fullTitle = () => `${suite.title}: ${test.title}`
27
+ suite.addTest(test)
28
+ }
29
+ }
30
+
31
+ function completeFeature (suite) {
32
+ const source = fs.readFileSync(suite.file, 'utf8')
33
+ const parser = new Parser(new AstBuilder(randomUUID), new GherkinClassicTokenMatcher())
34
+ const document = parser.parse(source)
35
+ const expected = compile(document, suite.file, randomUUID).length
36
+ if (suite.tests.length === expected) return // A future runner may support rules itself.
37
+ const rules = document.feature.children.filter(child => child.rule).map(child => child.rule)
38
+ const module = require('codeceptjs/lib/mocha/gherkin')
39
+ const parse = module.default || module
40
+ for (const [index, rule] of rules.entries()) {
41
+ appendRule(suite, parse(ruleSource(source, document.feature, rule, rules[index + 1]), suite.file), rule)
42
+ }
43
+ if (suite.tests.length !== expected) throw new Error(`storyboard: runner loaded ${suite.tests.length} of ${expected} scenarios from ${suite.file}`)
44
+ }
45
+
46
+ function completeRules (mocha) {
47
+ for (const suite of mocha.suite.suites) {
48
+ if (suite.feature) completeFeature(suite)
49
+ }
50
+ const grep = mocha.options.grep || /.*/
51
+ const pattern = grep instanceof RegExp ? grep : new RegExp(grep)
52
+ let selected = 0
53
+ mocha.suite.eachTest(test => {
54
+ pattern.lastIndex = 0
55
+ if (pattern.test(test.fullTitle()) !== Boolean(mocha.options.invert)) selected++
56
+ })
57
+ if (!selected) throw new Error('storyboard: no executable scenarios match this run')
58
+ }
59
+
60
+ module.exports = function loadRules (mocha) {
61
+ try {
62
+ completeRules(mocha)
63
+ } catch (error) {
64
+ // CodeceptJS logs and swallows event-listener exceptions. Make loader
65
+ // failures actual failing Mocha tests, including an empty grep selection.
66
+ const { createTest } = require('codeceptjs/lib/mocha/test')
67
+ mocha.grep(/.*/)
68
+ mocha.options.invert = false
69
+ mocha.suite.addTest(createTest(error.message, () => { throw error }))
70
+ }
71
+ }