Skip to content

Commit 286286e

Browse files
committed
fix: incorrect test duration measurement
1 parent 0573495 commit 286286e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/base/test-runner.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,27 @@ function _isTest(t: any): t is Test {
4444
return t && typeof t === "object" && t.name && t.line !== undefined;
4545
}
4646

47+
const currentMicrosecond = () => {
48+
const now = GLib.DateTime.new_now_local();
49+
return now.to_unix() * 1000000 + now.get_microsecond();
50+
};
51+
4752
class SuiteRunner {
4853
constructor(
4954
private readonly options: SuiteRunnerOptions,
5055
private readonly tracker: ProgressTracker,
5156
private readonly suiteID: symbol
5257
) {}
5358

54-
private async measureRun(action: () => void): Promise<number> {
55-
const start = GLib.DateTime.new_now_local()!.get_microsecond();
59+
private async measureRun(
60+
action: () => void | Promise<void>
61+
): Promise<number> {
62+
const start = currentMicrosecond();
5663
await action();
57-
const end = GLib.DateTime.new_now_local()!.get_microsecond();
64+
const end = currentMicrosecond();
5865

59-
return end - start;
66+
const duration = end - start;
67+
return duration;
6068
}
6169

6270
private testNameMatches(unitName: string[]) {

0 commit comments

Comments
 (0)