Skip to content

Commit 9f15bec

Browse files
Liviu RauDevtools-frontend LUCI CQ
authored andcommitted
Handle non-hosted types for mocha
Bug: 390535614 Change-Id: I294c2e561bfb6749173d5108fe23a99e722f8cfb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6304927 Reviewed-by: Alex Rudenko <[email protected]> Reviewed-by: Simon Zünd <[email protected]> Commit-Queue: Liviu Rau <[email protected]>
1 parent 90a1201 commit 9f15bec

File tree

10 files changed

+72
-35
lines changed

10 files changed

+72
-35
lines changed

scripts/build/typescript/ts_library.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ def main():
268268
parser.add_argument('--rewrapper-binary', required=False)
269269
parser.add_argument('--rewrapper-cfg', required=False)
270270
parser.add_argument('--rewrapper-exec-root', required=False)
271+
parser.add_argument('--additional-type-definitions',
272+
nargs='*',
273+
required=False,
274+
help='List of TypeScript declaration files')
271275
parser.add_argument('--use-esbuild', action='store_true')
272276
parser.add_argument('--tsconfig-only', action='store_true')
273277
parser.set_defaults(test_only=False,
@@ -299,6 +303,10 @@ def get_relative_path_from_output_directory(file_to_resolve):
299303
sources = shlex.split(opts.sources_list.read())
300304

301305
all_ts_files = sources + GLOBAL_TYPESCRIPT_DEFINITION_FILES
306+
307+
if (opts.additional_type_definitions):
308+
all_ts_files += opts.additional_type_definitions
309+
302310
tsconfig['files'] = [
303311
get_relative_path_from_output_directory(x) for x in all_ts_files
304312
]

scripts/build/typescript/typescript.gni

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ template("ts_library") {
148148
args += [ "--tsconfig-only" ]
149149
}
150150

151+
if (defined(invoker.additional_type_definitions)) {
152+
args += [ "--additional-type-definitions" ] +
153+
rebase_path(invoker.additional_type_definitions, root_build_dir)
154+
}
155+
151156
if (defined(invoker.sourceslist)) {
152157
args += [
153158
"--sources-list",
@@ -282,6 +287,19 @@ template("node_ts_library") {
282287
inputs =
283288
[ devtools_location_prepend + "node_modules/@types/node/index.d.ts" ]
284289

290+
forward_variables_from(invoker,
291+
[
292+
"sources",
293+
"visibility",
294+
"deps",
295+
"additional_type_definitions",
296+
])
297+
}
298+
}
299+
template("ts_e2e_library") {
300+
node_ts_library(target_name) {
301+
additional_type_definitions =
302+
[ devtools_location_prepend + "test/e2e_non_hosted/types.d.ts" ]
285303
forward_variables_from(invoker,
286304
[
287305
"sources",

test/e2e_non_hosted/conductor/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ group("conductor") {
1212
]
1313
}
1414

15-
node_ts_library("implementation") {
15+
ts_e2e_library("implementation") {
1616
deps = [
1717
"../../conductor:implementation",
1818
"../shared",

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,11 @@
55
import type * as Mocha from 'mocha';
66

77
import {AsyncScope} from '../../conductor/async-scope.js';
8-
import type {Platform} from '../../conductor/platform.js';
98
import {ScreenshotError} from '../../conductor/screenshot-error.js';
109
import {TestConfig} from '../../conductor/test_config.js';
11-
import type {BrowserSettings, BrowserWrapper} from '../shared/browser-helper.js';
12-
import type {DevToolsFronendPage, DevtoolsSettings} from '../shared/frontend-helper.js';
10+
import type {BrowserWrapper} from '../shared/browser-helper.js';
11+
import type {DevToolsFronendPage} from '../shared/frontend-helper.js';
1312
import type {InspectedPage} from '../shared/target-helper.js';
14-
declare global {
15-
namespace Mocha {
16-
export interface TestFunction {
17-
(title: string, fn: TestCallbackWithState): void;
18-
19-
skipOnPlatforms: (platforms: Platform[], title: string, fn: Mocha.AsyncFunc) => void;
20-
}
21-
export interface Suite {
22-
settings: SuiteSettings;
23-
state: State;
24-
browser: BrowserWrapper;
25-
}
26-
}
27-
}
28-
29-
export type HarnessSettings = BrowserSettings&DevtoolsSettings;
30-
export type SuiteSettings = Partial<HarnessSettings>;
3113

3214
export interface State {
3315
devToolsPage: DevToolsFronendPage;

test/e2e_non_hosted/conductor/mocha-interface.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ import * as Path from 'path';
1111
import {platform, type Platform} from '../../conductor/platform.js';
1212
import {TestConfig} from '../../conductor/test_config.js';
1313

14-
import {
15-
makeInstrumentedTestFunction,
16-
type SuiteSettings,
17-
type TestCallbackWithState
18-
} from './mocha-interface-helpers.js';
14+
import {makeInstrumentedTestFunction, type TestCallbackWithState} from './mocha-interface-helpers.js';
1915
import {StateProvider} from './state-provider.js';
2016

2117
type SuiteFunction = ((this: Mocha.Suite) => void)|undefined;

test/e2e_non_hosted/conductor/state-provider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {type BrowserWrapper, DEFAULT_BROWSER_SETTINGS, Launcher} from '../shared
1313
import {DEFAULT_DEVTOOLS_SETTINGS, setupDevToolsPage} from '../shared/frontend-helper.js';
1414
import {setupInspectedPage} from '../shared/target-helper.js';
1515

16-
import type {HarnessSettings, SuiteSettings, TestCallbackWithState} from './mocha-interface-helpers.js';
16+
import type {TestCallbackWithState} from './mocha-interface-helpers.js';
1717

1818
class DebugModeNotice {
1919
/* eslint-disable no-console */
@@ -50,7 +50,7 @@ export class StateProvider {
5050
static instance = new StateProvider();
5151

5252
debugNotice: DebugModeNotice;
53-
settingsCallbackMap: Map<Mocha.Suite, SuiteSettings>;
53+
settingsCallbackMap: Map<Mocha.Suite, E2E.SuiteSettings>;
5454
browserMap: Map<string, BrowserWrapper>;
5555
static serverPort: Number;
5656

@@ -60,7 +60,7 @@ export class StateProvider {
6060
this.browserMap = new Map();
6161
}
6262

63-
registerSettingsCallback(suite: Mocha.Suite, suiteSettings: SuiteSettings) {
63+
registerSettingsCallback(suite: Mocha.Suite, suiteSettings: E2E.SuiteSettings) {
6464
this.settingsCallbackMap.set(suite, suiteSettings);
6565
}
6666

@@ -112,7 +112,7 @@ export class StateProvider {
112112
return {state, browsingContext};
113113
}
114114

115-
private async getSettings(suite: Mocha.Suite): Promise<HarnessSettings> {
115+
private async getSettings(suite: Mocha.Suite): Promise<E2E.HarnessSettings> {
116116
const settings = this.settingsCallbackMap.get(suite);
117117
if (settings) {
118118
return mergeSettings(settings, DEFAULT_SETTINGS);
@@ -138,7 +138,7 @@ export class StateProvider {
138138
}
139139
}
140140

141-
export function mergeSettings(s1: SuiteSettings, s2: HarnessSettings): HarnessSettings {
141+
export function mergeSettings(s1: E2E.SuiteSettings, s2: E2E.HarnessSettings): E2E.HarnessSettings {
142142
function mergeAsSet<T>(arr1?: T[], arr2?: T[]) {
143143
return Array.from(new Set(arr1 ?? []).union(new Set(arr2 ?? [])));
144144
}

test/e2e_non_hosted/dummy/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import("../../../scripts/build/typescript/typescript.gni")
66

7-
node_ts_library("dummy") {
7+
ts_e2e_library("dummy") {
88
deps = [ "../conductor:implementation" ]
99
sources = [ "dummy_test.ts" ]
1010
}

test/e2e_non_hosted/dummy/dummy_test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import '../conductor/mocha-interface-helpers.js';
6-
75
import {assert} from 'chai';
86

97
describe('Dummy', function() {

test/e2e_non_hosted/shared/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import("../../../scripts/build/typescript/typescript.gni")
66

7-
node_ts_library("shared") {
7+
ts_e2e_library("shared") {
88
deps = [
99
"../../conductor:implementation",
1010
"../../shared",

test/e2e_non_hosted/types.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
import type {Platform} from '../conductor/platform.js';
3+
4+
import type {BrowserSettings, BrowserWrapper} from './shared/browser-helper.js';
5+
import type {DevToolsFronendPage, DevtoolsSettings} from './shared/frontend-helper.js';
6+
import type {InspectedPage} from './shared/target-helper.js';
7+
8+
9+
declare global {
10+
namespace Mocha {
11+
export interface TestFunction {
12+
(title: string, fn: E2E.TestCallbackWithState): void;
13+
14+
skipOnPlatforms: (platforms: Platform[], title: string, fn: Mocha.AsyncFunc) => void;
15+
}
16+
export interface Suite {
17+
settings: E2E.SuiteSettings;
18+
state: E2E.State;
19+
browser: BrowserWrapper;
20+
}
21+
}
22+
namespace E2E {
23+
export type HarnessSettings = BrowserSettings&DevtoolsSettings;
24+
export type SuiteSettings = Partial<HarnessSettings>;
25+
26+
export interface State {
27+
devToolsPage: DevToolsFronendPage;
28+
inspectedPage: InspectedPage;
29+
browser: BrowserWrapper;
30+
}
31+
32+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
33+
export type TestCallbackWithState = (state: State) => PromiseLike<any>;
34+
}
35+
}

0 commit comments

Comments
 (0)