Skip to content

Commit 5b50760

Browse files
Merge pull request #4 from fijijavis/main
Adding duration to report.step.result
2 parents 2ab4bec + 360b626 commit 5b50760

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ plugins: {
3535
outputFile: 'file.json', // cucumber_output.json by default
3636
uniqueFileNames: false, // if true outputFile is ignored in favor of unique file names in the format of `cucumber_output_<UUID>.json`. Useful for parallel test execution
3737
includeExampleValues: false // if true incorporate actual values from Examples table along with variable placeholder when writing steps to the report
38+
timeMultiplier: 1000000, // Used when calculating duration of individual BDD steps. Defaults to nanoseconds
39+
};
3840
},
3941
}
4042
...

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const defaultConfig = {
2121
outputFile: 'cucumber_output.json',
2222
uniqueFileNames: false,
2323
includeExampleValues: false,
24+
timeMultiplier: 1000000, // nanoseconds
2425
};
2526

2627
module.exports = function (config) {
@@ -88,6 +89,9 @@ module.exports = function (config) {
8889
recorder.add('Set step position', async () => {
8990
report.step = report.scenario.steps[report.stepPosition];
9091
});
92+
recorder.add('Set step starting time', async () => {
93+
if (report && report.step) report.step.start_time = Date.now();
94+
});
9195
});
9296

9397
event.dispatcher.on(event.bddStep.after, () => {
@@ -98,6 +102,13 @@ module.exports = function (config) {
98102
// and if bddStep after event is emitted, it should have passed
99103
if (report.step.result.status === 'skipped') report.step.result.status = 'passed';
100104
});
105+
recorder.add('Set step end time and duration', async () => {
106+
if (report && report.step) {
107+
report.step.end_time = Date.now();
108+
// calculate the duration based on config timeMultiplier for reporting tools
109+
report.step.result.duration = (report.step.end_time - report.step.start_time) * config.timeMultiplier;
110+
}
111+
});
101112
});
102113

103114
// finalize and write your json file after all complete

0 commit comments

Comments
 (0)