Skip to content

Commit e00382e

Browse files
committed
implement in js
1 parent 3bb5822 commit e00382e

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

javascript/package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"dependencies": {
2525
"@cucumber/query": "^13.0.2",
2626
"@teppeis/multimaps": "^3.0.0",
27+
"date-fns": "^4.1.0",
28+
"luxon": "^3.5.0",
2729
"xmlbuilder": "^15.1.1"
2830
},
2931
"peerDependencies": {
@@ -35,6 +37,7 @@
3537
"@types/chai": "^4.3.11",
3638
"@types/chai-almost": "^1.0.3",
3739
"@types/chai-xml": "^0.3.6",
40+
"@types/luxon": "^3.4.2",
3841
"@types/mocha": "^10.0.6",
3942
"@types/node": "18.11.18",
4043
"@typescript-eslint/eslint-plugin": "5.48.1",

javascript/src/helpers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import {
22
Duration,
33
PickleStep,
44
Step,
5+
TestRunStarted,
56
TestStepResultStatus,
67
TimeConversion,
78
} from '@cucumber/messages'
9+
import { DateTime } from 'luxon'
810

911
export function durationToSeconds(duration?: Duration) {
1012
if (!duration) {
@@ -29,3 +31,13 @@ export function formatStep(step: Step, pickleStep: PickleStep, status: TestStepR
2931
} while (text.length < 76)
3032
return text + status.toLowerCase()
3133
}
34+
35+
export function formatTimestamp(testRunStarted: TestRunStarted | undefined) {
36+
if (!testRunStarted) {
37+
return undefined
38+
}
39+
const millis = TimeConversion.timestampToMillisecondsSinceEpoch(testRunStarted.timestamp)
40+
return DateTime.fromMillis(millis, { zone: 'UTC' }).toISO({
41+
suppressMilliseconds: true,
42+
}) as string
43+
}

javascript/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export default {
3131
builder.att('failures', testSuite.failures)
3232
builder.att('errors', testSuite.errors)
3333

34+
if (testSuite.timestamp) {
35+
builder.att('timestamp', testSuite.timestamp)
36+
}
37+
3438
for (const testCase of testSuite.testCases) {
3539
const testcaseElement = builder.ele('testcase', {
3640
classname: testCase.classname,

javascript/src/makeReport.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Query,
1010
} from '@cucumber/query'
1111

12-
import { countStatuses, durationToSeconds, formatStep } from './helpers.js'
12+
import { countStatuses, durationToSeconds, formatStep, formatTimestamp } from './helpers.js'
1313

1414
const NAMING_STRATEGY = namingStrategy(
1515
NamingStrategyLength.LONG,
@@ -24,6 +24,7 @@ interface ReportSuite {
2424
failures: number
2525
errors: number
2626
testCases: ReadonlyArray<ReportTestCase>
27+
timestamp?: string
2728
}
2829

2930
interface ReportTestCase {
@@ -53,6 +54,7 @@ export function makeReport(query: Query): ReportSuite {
5354
),
5455
errors: 0,
5556
testCases: makeTestCases(query),
57+
timestamp: formatTimestamp(query.findTestRunStarted())
5658
}
5759
}
5860

0 commit comments

Comments
 (0)