Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: unify two copies of monotonicTime (#15473)

Dmitry Gozman738d71ebc2af
diff --git a/packages/playwright-test/src/reporters/junit.ts b/packages/playwright-test/src/reporters/junit.ts
index 32eaa21b78..0ed0c1ef3e 100644
--- a/packages/playwright-test/src/reporters/junit.ts
+++ b/packages/playwright-test/src/reporters/junit.ts
@@ -17,7 +17,7 @@
import fs from 'fs';
import path from 'path';
import type { FullConfig, FullResult, Reporter, Suite, TestCase } from '../../types/testReporter';
-import { monotonicTime } from '../util';
+import { monotonicTime } from 'playwright-core/lib/utils';
import { formatFailure, formatTestTitle, stripAnsiEscapes } from './base';
class JUnitReporter implements Reporter {
diff --git a/packages/playwright-test/src/testInfo.ts b/packages/playwright-test/src/testInfo.ts
index 5036392bae..e32e3bb686 100644
--- a/packages/playwright-test/src/testInfo.ts
+++ b/packages/playwright-test/src/testInfo.ts
@@ -23,7 +23,8 @@ import type { Loader } from './loader';
import type { TestCase } from './test';
import { TimeoutManager } from './timeoutManager';
import type { Annotation, TestStepInternal } from './types';
-import { addSuffixToFilePath, getContainedPath, monotonicTime, normalizeAndSaveAttachment, sanitizeForFilePath, serializeError, trimLongString } from './util';
+import { addSuffixToFilePath, getContainedPath, normalizeAndSaveAttachment, sanitizeForFilePath, serializeError, trimLongString } from './util';
+import { monotonicTime } from 'playwright-core/lib/utils';
export class TestInfoImpl implements TestInfo {
private _addStepImpl: (data: Omit<TestStepInternal, 'complete'>) => TestStepInternal;
@@ -177,7 +178,7 @@ export class TestInfoImpl implements TestInfo {
this.status = 'timedOut';
this.errors.push(timeoutError);
}
- this.duration = monotonicTime() - this._startTime;
+ this.duration = (monotonicTime() - this._startTime) | 0;
}
async _runFn(fn: Function, skips?: 'allowSkips'): Promise<TestError | undefined> {
diff --git a/packages/playwright-test/src/util.ts b/packages/playwright-test/src/util.ts
index 81f0c9f3f0..7873fb657d 100644
--- a/packages/playwright-test/src/util.ts
+++ b/packages/playwright-test/src/util.ts
@@ -96,11 +96,6 @@ export function serializeError(error: Error | any): TestError {
};
}
-export function monotonicTime(): number {
- const [seconds, nanoseconds] = process.hrtime();
- return seconds * 1000 + (nanoseconds / 1000000 | 0);
-}
-
export type Matcher = (value: string) => boolean;
export type FilePatternFilter = {