@orieken/saturday-cucumber-formatter 0.0.0-stage → 0.1.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/LICENSE +13 -0
- package/NOTICE +5 -0
- package/README.md +61 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +95 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2026 Saturday reporting contributors
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Saturday Cucumber formatter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Saturday HTML reports for ordinary Cucumber.js projects. Features, scenario outline rows, steps, hooks, retries, attachments, and original statuses appear in the same gallery as Saturday’s Playwright reports. No Saturday framework is required.
|
|
4
|
+
|
|
5
|
+
## Install and configure
|
|
6
|
+
|
|
7
|
+
Initial compatibility: Node **24.x**, ESM, `@cucumber/cucumber` **12.9.0**. This release uses that version’s supported `Formatter` API; it does not claim compatibility with later formatter-plugin APIs.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install --save-dev @orieken/saturday-cucumber-formatter @cucumber/cucumber@12.9.0
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// cucumber.mjs
|
|
15
|
+
export default {
|
|
16
|
+
import: ['features/steps.mjs'],
|
|
17
|
+
format: ['progress', '@orieken/saturday-cucumber-formatter:saturday-formatter.log'],
|
|
18
|
+
formatOptions: {
|
|
19
|
+
saturday: { outputDir: 'saturday-report', title: 'Acceptance tests' },
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Run `npx cucumber-js`, then open `saturday-report/index.html`. The formatter supports parallel workers and retries; rendering occurs after the coordinator has collected the run. Formatter errors propagate through Cucumber’s normal completion path.
|
|
25
|
+
|
|
26
|
+
## Optional video recording
|
|
27
|
+
|
|
28
|
+
Cucumber does not record browser video. Your hooks can supply a standard attachment; the formatter itself requires no Playwright dependency:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import { Before, After } from '@cucumber/cucumber';
|
|
32
|
+
import { readFile } from 'node:fs/promises';
|
|
33
|
+
// Supply your own shared `browser`, e.g. from a BeforeAll hook.
|
|
34
|
+
Before(async function () {
|
|
35
|
+
this.context = await browser.newContext({ recordVideo: { dir: 'test-results/videos' } });
|
|
36
|
+
this.page = await this.context.newPage();
|
|
37
|
+
});
|
|
38
|
+
After(async function () {
|
|
39
|
+
if (!this.context) return;
|
|
40
|
+
const video = this.page.video();
|
|
41
|
+
await this.context.close();
|
|
42
|
+
if (video) await this.attach(await readFile(await video.path()), {
|
|
43
|
+
mediaType: 'video/webm', fileName: 'Scenario recording',
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Closing the context finalizes the video before it is attached. Attach screenshots with `image/png`. No browser or video is required for ordinary scenarios. See `examples/basic` for complete browser lifecycle hooks and a parallel scenario-outline example.
|
|
49
|
+
|
|
50
|
+
## Metadata, merging, and output
|
|
51
|
+
|
|
52
|
+
`formatOptions.saturday` accepts `outputDir`, `title`, `runId`, `shard`, and a string-map `metadata`. Tags such as `@saturday:auth=oidc` and `@saturday:persona=admin` add scenario labels and override run labels. `@saturday:recording=disabled` explicitly marks intentionally disabled recording. Runner and result filters are reserved.
|
|
53
|
+
|
|
54
|
+
Set a shared `runId` and distinct `shard` values when merging separate Cucumber invocations. Parallel workers within one invocation already form one report. Use a distinct output directory per invocation, then merge `report.json` files with `@orieken/saturday-reporting`.
|
|
55
|
+
|
|
56
|
+
Passed, failed, skipped, pending, undefined, ambiguous, and unknown statuses are preserved. A scenario passing after failure is flaky; outline rows retain separate identities and source lines. Raw errors, stacks, stdout, and unsupported attachment contents are excluded. Titles, steps, labels, and media still contain test-supplied data: review before sharing.
|
|
57
|
+
|
|
58
|
+
Archive the entire output directory for portable playback. Only Saturday-owned output directories can be replaced on a later run.
|
|
59
|
+
|
|
60
|
+
For credential-sensitive suites, set `includeSteps: false` to omit runner step titles while retaining test results and attachments. Step titles can contain entered values; this option does not redact producer-supplied test names, labels, or media.
|
|
61
|
+
|
|
62
|
+
Cucumber selects one formatter per output destination. Give this silent formatter a distinct output file when using another stdout formatter; otherwise Cucumber can replace the earlier stdout formatter. The sink file is separate from the generated HTML report.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Formatter } from '@cucumber/cucumber';
|
|
2
|
+
import type { IFormatterOptions } from '@cucumber/cucumber';
|
|
3
|
+
export default class SaturdayCucumberFormatter extends Formatter {
|
|
4
|
+
private options;
|
|
5
|
+
private run;
|
|
6
|
+
private readonly planned;
|
|
7
|
+
constructor(options: IFormatterOptions);
|
|
8
|
+
private test;
|
|
9
|
+
private collect;
|
|
10
|
+
finished(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export type { ReportOptions } from '@orieken/saturday-reporting';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { relative, resolve } from 'node:path';
|
|
2
|
+
import { Formatter, formatterHelpers } from '@cucumber/cucumber';
|
|
3
|
+
import { labelMetadata, metadata, newRunId, normalizeStatus, outcome, writeReport } from '@orieken/saturday-reporting';
|
|
4
|
+
function millis(duration) {
|
|
5
|
+
return duration ? duration.seconds * 1000 + duration.nanos / 1_000_000 : 0;
|
|
6
|
+
}
|
|
7
|
+
function attachment(item) {
|
|
8
|
+
return {
|
|
9
|
+
name: item.fileName ?? item.mediaType, contentType: item.mediaType,
|
|
10
|
+
body: Buffer.from(item.body, item.contentEncoding === 'BASE64' ? 'base64' : 'utf8'),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export default class SaturdayCucumberFormatter extends Formatter {
|
|
14
|
+
options;
|
|
15
|
+
run;
|
|
16
|
+
planned = new Set();
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options);
|
|
19
|
+
this.options = options.parsedArgvOptions.saturday ?? {};
|
|
20
|
+
this.run = {
|
|
21
|
+
id: this.options.runId ?? newRunId(), shard: this.options.shard ?? '1', runner: 'cucumber',
|
|
22
|
+
status: 'unknown', metadata: { os: process.platform, ...metadata(this.options.metadata ?? {}) }, tests: [],
|
|
23
|
+
};
|
|
24
|
+
options.eventBroadcaster.on('envelope', envelope => {
|
|
25
|
+
if (envelope.testCase)
|
|
26
|
+
this.planned.add(envelope.testCase.pickleId);
|
|
27
|
+
if (envelope.testRunStarted) {
|
|
28
|
+
const stamp = envelope.testRunStarted.timestamp;
|
|
29
|
+
this.run.startedAt = new Date(stamp.seconds * 1000 + stamp.nanos / 1_000_000).toISOString();
|
|
30
|
+
}
|
|
31
|
+
if (envelope.testRunFinished)
|
|
32
|
+
this.run.status = envelope.testRunFinished.success ? 'passed' : 'failed';
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
test(item) {
|
|
36
|
+
const locations = formatterHelpers.GherkinDocumentParser.getGherkinScenarioLocationMap(item.gherkinDocument);
|
|
37
|
+
const location = item.pickle.astNodeIds.map(id => locations[id]).filter(Boolean).at(-1);
|
|
38
|
+
return {
|
|
39
|
+
id: item.pickle.id, title: item.pickle.name, suite: [item.gherkinDocument.feature?.name ?? item.pickle.uri],
|
|
40
|
+
location: { file: relative(this.cwd, resolve(this.cwd, item.pickle.uri)).replaceAll('\\', '/'), line: location?.line ?? 0 },
|
|
41
|
+
metadata: labelMetadata(item.pickle.tags.map(tag => tag.name)), outcome: 'unknown', attempts: [],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
collect() {
|
|
45
|
+
const tests = new Map();
|
|
46
|
+
for (const item of this.eventDataCollector.getTestCaseAttempts()) {
|
|
47
|
+
const test = tests.get(item.pickle.id) ?? this.test(item);
|
|
48
|
+
tests.set(item.pickle.id, test);
|
|
49
|
+
const attachments = Object.values(item.stepAttachments).flat().map(attachment);
|
|
50
|
+
if (test.metadata.recording === 'disabled' && !attachments.some(a => a.contentType.startsWith('video/'))) {
|
|
51
|
+
attachments.push({ name: 'Video', contentType: 'video/webm', availability: 'disabled' });
|
|
52
|
+
}
|
|
53
|
+
test.attempts.push({
|
|
54
|
+
index: item.attempt, rawStatus: item.worstTestStepResult.status,
|
|
55
|
+
status: normalizeStatus(item.worstTestStepResult.status),
|
|
56
|
+
durationMs: Object.values(item.stepResults).reduce((sum, result) => sum + millis(result.duration), 0),
|
|
57
|
+
attachments,
|
|
58
|
+
steps: item.testCase.testSteps.map(step => {
|
|
59
|
+
const result = item.stepResults[step.id];
|
|
60
|
+
const pickleStep = item.pickle.steps.find(pickle => pickle.id === step.pickleStepId);
|
|
61
|
+
return {
|
|
62
|
+
title: pickleStep?.text ?? 'Hook', category: pickleStep ? 'step' : 'hook',
|
|
63
|
+
status: normalizeStatus(result?.status ?? 'UNKNOWN'), durationMs: millis(result?.duration),
|
|
64
|
+
};
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
for (const [id, test] of tests) {
|
|
69
|
+
test.attempts.sort((a, b) => a.index - b.index);
|
|
70
|
+
test.outcome = outcome(test.attempts);
|
|
71
|
+
this.planned.delete(id);
|
|
72
|
+
}
|
|
73
|
+
for (const id of this.planned) {
|
|
74
|
+
const pickle = this.eventDataCollector.getPickle(id);
|
|
75
|
+
tests.set(id, { id, title: pickle.name, suite: [pickle.uri], metadata: labelMetadata(pickle.tags.map(tag => tag.name)), outcome: 'unknown', attempts: [] });
|
|
76
|
+
}
|
|
77
|
+
this.run.tests = [...tests.values()];
|
|
78
|
+
if (this.options.includeSteps === false)
|
|
79
|
+
for (const test of this.run.tests)
|
|
80
|
+
for (const attempt of test.attempts)
|
|
81
|
+
attempt.steps = [];
|
|
82
|
+
this.run.durationMs = this.run.tests.reduce((sum, test) => sum + test.attempts.reduce((total, attempt) => total + attempt.durationMs, 0), 0);
|
|
83
|
+
}
|
|
84
|
+
async finished() {
|
|
85
|
+
try {
|
|
86
|
+
this.collect();
|
|
87
|
+
writeReport({ schemaVersion: 1, title: this.options.title ?? 'Saturday Cucumber report', runs: [this.run] }, {
|
|
88
|
+
...this.options, artifactRoots: [this.cwd, ...(this.options.artifactRoots ?? [])],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
await super.finished();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orieken/saturday-cucumber-formatter",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Saturday HTML reports for ordinary Cucumber.js projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=24 <25"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"NOTICE"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/orieken/testing-with-certs.git",
|
|
29
|
+
"directory": "packages/saturday-cucumber-formatter"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "24.10.0",
|
|
33
|
+
"typescript": "5.9.3",
|
|
34
|
+
"@cucumber/cucumber": "12.9.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@orieken/saturday-reporting": "0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@cucumber/cucumber": "12.9.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
45
|
+
}
|
|
6
46
|
}
|