Skip to content

Commit 5cb7bc8

Browse files
Liviu RauDevtools-frontend LUCI CQ
authored andcommitted
Provide mocha context to it.only function
On e2e_non_hosted tests it.only fails with: `ReferenceError: mocha is not defined` Bug: 400683715 Change-Id: I576eb03f5f007e032a772a3230802c06e9443812 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6387109 Commit-Queue: Liviu Rau <[email protected]> Reviewed-by: Philip Pfaffe <[email protected]>
1 parent 3872832 commit 5cb7bc8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/e2e_non_hosted/conductor/mocha-interface.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ type SuiteFunction = ((this: Mocha.Suite) => void)|undefined;
1919
function devtoolsTestInterface(rootSuite: Mocha.Suite) {
2020
let defaultImplementation: CommonFunctions;
2121
let mochaGlobals: Mocha.MochaGlobals;
22+
let mochaRoot: Mocha;
2223
rootSuite.on(
2324
Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE,
2425
(context: Mocha.MochaGlobals, file: string, mocha: Mocha) => {
2526
mochaGlobals = context;
27+
mochaRoot = mocha;
2628
// Different module outputs between tsc and esbuild.
2729
const defaultFactory = ('default' in commonInterface ? commonInterface.default : commonInterface);
2830
defaultImplementation = defaultFactory([rootSuite], context, mocha) as CommonFunctions;
@@ -47,7 +49,7 @@ function devtoolsTestInterface(rootSuite: Mocha.Suite) {
4749
mochaGlobals.setup = function(suiteSettings: SuiteSettings) {
4850
StateProvider.instance.registerSettingsCallback(suite, suiteSettings);
4951
};
50-
const it = customIt(defaultImplementation.test, suite, suite.file || '');
52+
const it = customIt(defaultImplementation.test, suite, suite.file || '', mochaRoot);
5153
// @ts-expect-error Custom interface.
5254
mochaGlobals.it = it;
5355
});
@@ -105,7 +107,7 @@ function iterationSuffix(iteration: number): string {
105107
}
106108
return ` (#${iteration})`;
107109
}
108-
function customIt(testImplementation: TestFunctions, suite: Mocha.Suite, file: string) {
110+
function customIt(testImplementation: TestFunctions, suite: Mocha.Suite, file: string, mocha: Mocha) {
109111
function instrumentWithState(fn: E2E.TestAsyncCallbackWithState) {
110112
const fnWithState = async function(this: Mocha.Context) {
111113
return await StateProvider.instance.callWithState(this, suite, fn);

0 commit comments

Comments
 (0)