Skip to content

Commit b3bfdea

Browse files
committed
Ensure "last run" is present in HTML report
This fixes #798.
1 parent b7a8f36 commit b3bfdea

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Unreleased
6+
7+
- Start time and execution time is shown in HTML reports, fixes [#798](https://github.com/badeball/cypress-cucumber-preprocessor/issues/798).
8+
59
## v12.0.1
610

711
- Allow overriding env using tags, fixes [#792](https://github.com/badeball/cypress-cucumber-preprocessor/issues/792).

features/html_report.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,19 @@ Feature: html report
2424
When I run cypress
2525
Then it passes
2626
And there should be a HTML report
27+
28+
Scenario: start time
29+
Given a file named "cypress/e2e/a.feature" with:
30+
"""
31+
Feature: a feature
32+
Scenario: a scenario
33+
Given a step
34+
"""
35+
And a file named "cypress/support/step_definitions/steps.js" with:
36+
"""
37+
const { Given } = require("@badeball/cypress-cucumber-preprocessor");
38+
Given("a step", function() {})
39+
"""
40+
When I run cypress
41+
Then it passes
42+
And the report should display when last run

features/step_definitions/html_steps.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Then } from "@cucumber/cucumber";
2+
import { JSDOM } from "jsdom";
23
import path from "path";
34
import { promises as fs } from "fs";
45
import assert from "assert";
@@ -9,3 +10,26 @@ Then("there should be a HTML report", async function () {
910
"Expected there to be a HTML file"
1011
);
1112
});
13+
14+
Then("the report should display when last run", async function () {
15+
const dom = await JSDOM.fromFile(
16+
path.join(this.tmpDir, "cucumber-report.html"),
17+
{ runScripts: "dangerously" }
18+
);
19+
20+
const dt = Array.from(dom.window.document.querySelectorAll("dt")).find(
21+
(el) => el.textContent === "last run"
22+
);
23+
24+
assert(dt, "Expected to find a 'last run' dt");
25+
26+
const dd = dt.parentElement?.querySelector("dd");
27+
28+
assert(dd, "Expected to find a 'last run' dt's dd");
29+
30+
const lastRunText = dd.textContent;
31+
32+
assert(lastRunText, "Expected to find 'XX seconds ago'");
33+
34+
assert.match(lastRunText, /\d+ seconds? ago/);
35+
});

lib/create-tests.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,12 @@ export default function createTests(
673673
});
674674
}
675675

676+
messages.push({
677+
testRunStarted: {
678+
timestamp: createTimestamp(),
679+
},
680+
});
681+
676682
const tagsInDocument = collectTagNamesFromGherkinDocument(gherkinDocument);
677683

678684
const testFilter =
@@ -826,6 +832,16 @@ export default function createTests(
826832
});
827833

828834
after(function () {
835+
messages.push({
836+
testRunFinished: {
837+
/**
838+
* We're missing a "success" attribute here, but cucumber-js doesn't output it, so I won't.
839+
* Mostly because I don't want to look into the semantics of it right now.
840+
*/
841+
timestamp: createTimestamp(),
842+
} as messages.TestRunFinished,
843+
});
844+
829845
if (messagesEnabled) {
830846
cy.task(TASK_APPEND_MESSAGES, messages, { log: false });
831847
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@
6969
"@types/debug": "^4.1.7",
7070
"@types/fs-extra": "^9.0.13",
7171
"@types/glob": "^7.2.0",
72+
"@types/jsdom": "^20.0.0",
7273
"@types/prettier": "^2.6.3",
7374
"@types/stream-buffers": "^3.0.4",
7475
"ast-types": "^0.15.2",
7576
"cypress": "^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0",
7677
"esbuild": "^0.14.23",
7778
"fs-extra": "^10.1.0",
79+
"jsdom": "^20.0.0",
7880
"mocha": "^9.2.1",
7981
"pngjs": "^6.0.0",
8082
"prettier": "^2.5.1",

0 commit comments

Comments
 (0)