Skip to content

Commit 73ae0fc

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
Report real duration in E2E non hosted mode
Mocha track the full time including setup for the test. We create our own timer and wrap the Test object with a Proxy to make sure the reports get the correct time. Bug: none Change-Id: Ifab37c7854549ac6dc5a79676c42819bdc25fcaa Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6694755 Reviewed-by: Alex Rudenko <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 42a6a40 commit 73ae0fc

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

test/e2e_non_hosted/conductor/mocha-interface-helpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,15 @@ export class InstrumentedTestFunction {
103103
// eslint-disable-next-line no-debugger
104104
debugger; // If you're paused here while debugging, stepping into the next line will step into your test.
105105
}
106+
const start = performance.now();
106107
const testResult =
107108
await (this.state === undefined ?
108109
this.fn.call(context) :
109110
(this.fn as unknown as E2E.TestAsyncCallbackWithState).call(undefined, this.state.state));
111+
112+
if (context.test) {
113+
(context.test as Mocha.Test).realDuration = Math.ceil(performance.now() - start);
114+
}
110115
dumpCollectedErrors();
111116
return testResult;
112117
}

test/e2e_non_hosted/conductor/mocha-interface.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,23 @@ function customIt(testImplementation: TestFunctions, suite: Mocha.Suite, file: s
112112
function createTest(title: string, itBodyFn?: Mocha.AsyncFunc) {
113113
const test = new Mocha.Test(
114114
title,
115-
suite.isPending() || !itBodyFn ? undefined : InstrumentedTestFunction.instrument(itBodyFn, 'test', suite));
115+
suite.isPending() || !itBodyFn ? undefined : InstrumentedTestFunction.instrument(itBodyFn, 'test', suite),
116+
);
116117
test.file = file;
117-
suite.addTest(test);
118-
return test;
118+
119+
// Creates a proxy that changes the duration to return
120+
// our own timing.
121+
const proxyTest = new Proxy(test, {
122+
get(target, property, receiver) {
123+
if (property === 'duration' && target.realDuration) {
124+
return Reflect.get(target, 'realDuration', receiver) ?? Reflect.get(target, property, receiver);
125+
}
126+
return Reflect.get(target, property, receiver);
127+
},
128+
});
129+
130+
suite.addTest(proxyTest);
131+
return proxyTest;
119132
}
120133

121134
// Regular mocha it returns the test instance.

test/e2e_non_hosted/types.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ declare global {
4848
beforeEach: undefined;
4949
afterEach: undefined;
5050
}
51+
52+
export interface Test {
53+
realDuration?: number;
54+
}
5155
}
5256
namespace E2E {
5357
export type HarnessSettings = BrowserSettings&DevtoolsSettings;

0 commit comments

Comments
 (0)