diff --git a/CHANGELOG.md b/CHANGELOG.md index 1614e6856..8a90d06ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ See the [migration guide](./docs/migration.md) for details of how to migrate fro [#1794](https://github.com/cucumber/cucumber-js/pull/1794) ### Changed +* Use performance timers for test case duration measurement. + [#1793](https://github.com/cucumber/cucumber-js/pull/1793) ### Deprecated diff --git a/features/support/helpers.ts b/features/support/helpers.ts index 4fa7586f0..a17b1dc57 100644 --- a/features/support/helpers.ts +++ b/features/support/helpers.ts @@ -11,8 +11,10 @@ export function normalizeText(text: string): string { .replace(/\d+(.\d+)?ms/g, 'ms') .replace(/\//g, path.sep) .replace(/ +/g, ' ') + .replace(/─+/gu, '─') .split('\n') .map((line) => line.trim()) .join('\n') + return normalizeSummaryDuration(normalized) } diff --git a/src/formatter/usage_formatter.ts b/src/formatter/usage_formatter.ts index 5b7a29ed5..ff6afe142 100644 --- a/src/formatter/usage_formatter.ts +++ b/src/formatter/usage_formatter.ts @@ -60,7 +60,7 @@ export default class UsageFormatter extends Formatter { col2.push( `${messages.TimeConversion.durationToMilliseconds( match.duration - ).toString()}ms` + ).toFixed(2)}ms` ) } else { col2.push('-') diff --git a/src/formatter/usage_formatter_spec.ts b/src/formatter/usage_formatter_spec.ts index 89da62e57..5c8545124 100644 --- a/src/formatter/usage_formatter_spec.ts +++ b/src/formatter/usage_formatter_spec.ts @@ -125,8 +125,8 @@ describe('UsageFormatter', () => { │ Pattern / Text │ Duration │ Location │ ├────────────────┼──────────┼───────────────────┤ │ /def?/ │ 1.50ms │ usage_steps.ts:16 │ - │ def │ 2ms │ a.feature:3 │ - │ de │ 1ms │ a.feature:4 │ + │ def │ 2.00ms │ a.feature:3 │ + │ de │ 1.00ms │ a.feature:4 │ ├────────────────┼──────────┼───────────────────┤ │ abc │ UNUSED │ usage_steps.ts:11 │ ├────────────────┼──────────┼───────────────────┤ diff --git a/src/time.ts b/src/time.ts index ab3d50cda..32ec1c9ed 100644 --- a/src/time.ts +++ b/src/time.ts @@ -1,3 +1,4 @@ +import { performance } from 'perf_hooks' import * as messages from '@cucumber/messages' let previousTimestamp: number @@ -14,6 +15,7 @@ const methods: any = { }, setInterval: setInterval.bind(global), setTimeout: setTimeout.bind(global), + performance, } if (typeof setImmediate !== 'undefined') { @@ -22,7 +24,7 @@ if (typeof setImmediate !== 'undefined') { } function getTimestamp(): number { - return new methods.Date().getTime() + return methods.performance.now() } export function durationBetweenTimestamps(