Skip to content

Commit 7739a11

Browse files
authored
Refactor tests to handle new ToolConfiguration (#2243)
1 parent 4e350cd commit 7739a11

17 files changed

+225
-162
lines changed

dwds/test/dart_uri_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class G3TestStrategy extends FakeStrategy {
4949
void main() {
5050
group('DartUri', () {
5151
setUpAll(() {
52-
final toolConfiguration = createToolConfiguration(
52+
final toolConfiguration = TestToolConfiguration.forTests(
5353
loadStrategy: TestStrategy(
5454
FakeAssetReader(),
5555
),
@@ -209,7 +209,7 @@ void main() {
209209

210210
group('initialized to handle g3-relative paths', () {
211211
setUpAll(() async {
212-
final toolConfiguration = createToolConfiguration(
212+
final toolConfiguration = TestToolConfiguration.forTests(
213213
loadStrategy: G3TestStrategy(FakeAssetReader()),
214214
appMetadata: AppMetadata(isInternalBuild: true),
215215
);

dwds/test/debug_extension_test.dart

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'linux': Skip('https://github.com/dart-lang/webdev/issues/2114'),
1212
})
1313

14+
import 'package:dwds/config.dart';
1415
import 'package:dwds/src/connections/debug_connection.dart';
1516
import 'package:dwds/src/handlers/injector.dart';
1617
import 'package:http/http.dart' as http;
@@ -61,9 +62,10 @@ void main() async {
6162
group('Without encoding', () {
6263
setUp(() async {
6364
await context.setUp(
64-
enableDebugExtension: true,
65-
serveDevTools: true,
66-
useSse: useSse,
65+
debugSettings: TestDebugSettings.withDevTools(context).copyWith(
66+
enableDebugExtension: true,
67+
useSse: useSse,
68+
),
6769
);
6870
await context.extensionConnection.sendCommand('Runtime.evaluate', {
6971
'expression': 'fakeClick()',
@@ -124,9 +126,10 @@ void main() async {
124126
group('With a sharded Dart app', () {
125127
setUp(() async {
126128
await context.setUp(
127-
enableDebugExtension: true,
128-
serveDevTools: true,
129-
useSse: useSse,
129+
debugSettings: TestDebugSettings.withDevTools(context).copyWith(
130+
enableDebugExtension: true,
131+
useSse: useSse,
132+
),
130133
);
131134
final htmlTag =
132135
await context.webDriver.findElement(const By.tagName('html'));
@@ -158,9 +161,10 @@ void main() async {
158161
group('With an internal Dart app', () {
159162
setUp(() async {
160163
await context.setUp(
161-
enableDebugExtension: true,
162-
serveDevTools: true,
163-
useSse: false,
164+
debugSettings: TestDebugSettings.withDevTools(context).copyWith(
165+
enableDebugExtension: true,
166+
useSse: false,
167+
),
164168
);
165169
final htmlTag =
166170
await context.webDriver.findElement(const By.tagName('html'));
@@ -227,9 +231,11 @@ void main() async {
227231
group('With encoding', () {
228232
setUp(() async {
229233
await context.setUp(
230-
enableDebugExtension: true,
231-
urlEncoder: (url) async =>
232-
url.endsWith(r'/$debug') ? 'http://some-encoded-url:8081/' : url,
234+
debugSettings: TestDebugSettings.noDevTools().copyWith(
235+
enableDebugExtension: true,
236+
urlEncoder: (url) async =>
237+
url.endsWith(r'/$debug') ? 'http://some-encoded-url:8081/' : url,
238+
),
233239
);
234240
});
235241

@@ -252,7 +258,11 @@ void main() async {
252258
final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";');
253259

254260
setUp(() async {
255-
await context.setUp(enableDebugExtension: true, hostname: 'any');
261+
await context.setUp(
262+
debugSettings:
263+
TestDebugSettings.noDevTools().copyWith(enableDebugExtension: true),
264+
appMetadata: AppMetadata(hostname: 'any'),
265+
);
256266
});
257267

258268
tearDown(() async {

dwds/test/debug_service_test.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:test_common/test_sdk_configuration.dart';
1313

1414
import 'fixtures/context.dart';
1515
import 'fixtures/project.dart';
16+
import 'fixtures/utilities.dart';
1617

1718
void main() {
1819
final provider = TestSdkConfigurationProvider();
@@ -22,7 +23,11 @@ void main() {
2223

2324
setUpAll(() async {
2425
// Disable DDS as we're testing DWDS behavior.
25-
await context.setUp(spawnDds: false);
26+
await context.setUp(
27+
debugSettings: TestDebugSettings.noDevTools().copyWith(
28+
spawnDds: false,
29+
),
30+
);
2631
});
2732

2833
tearDownAll(() async {

dwds/test/debugger_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void main() async {
8787
webkitDebugger = FakeWebkitDebugger(scripts: scripts);
8888
pausedController = StreamController<DebuggerPausedEvent>();
8989
webkitDebugger.onPaused = pausedController.stream;
90-
final toolConfiguration = createToolConfiguration(
90+
final toolConfiguration = TestToolConfiguration.forTests(
9191
loadStrategy: TestStrategy(FakeAssetReader()),
9292
);
9393
setGlobalsForTesting(

dwds/test/devtools_test.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:webdriver/io.dart';
1414

1515
import 'fixtures/context.dart';
1616
import 'fixtures/project.dart';
17+
import 'fixtures/utilities.dart';
1718

1819
Future<void> _waitForPageReady(TestContext context) async {
1920
var attempt = 100;
@@ -34,7 +35,7 @@ void main() {
3435
group('Injected client', () {
3536
setUp(() async {
3637
await context.setUp(
37-
serveDevTools: true,
38+
debugSettings: TestDebugSettings.withDevTools(context),
3839
);
3940
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
4041
// Wait for DevTools to actually open.
@@ -136,9 +137,13 @@ void main() {
136137
);
137138
});
138139

139-
group('Injected client without DevTools', () {
140+
group('Injected client without a DevTools server', () {
140141
setUp(() async {
141-
await context.setUp(serveDevTools: false);
142+
await context.setUp(
143+
debugSettings: TestDebugSettings.noDevTools().copyWith(
144+
enableDevToolsLaunch: true,
145+
),
146+
);
142147
});
143148

144149
tearDown(() async {
@@ -160,7 +165,10 @@ void main() {
160165
'Injected client with debug extension and without DevTools',
161166
() {
162167
setUp(() async {
163-
await context.setUp(enableDebugExtension: true, serveDevTools: false);
168+
await context.setUp(
169+
debugSettings: TestDebugSettings.noDevTools()
170+
.copyWith(enableDebugExtension: true),
171+
);
164172
});
165173

166174
tearDown(() async {

dwds/test/events_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'package:webdriver/async_core.dart';
1616

1717
import 'fixtures/context.dart';
1818
import 'fixtures/project.dart';
19+
import 'fixtures/utilities.dart';
1920

2021
void main() {
2122
final provider = TestSdkConfigurationProvider();
@@ -131,7 +132,7 @@ void main() {
131132
),
132133
);
133134
await context.setUp(
134-
serveDevTools: true,
135+
debugSettings: TestDebugSettings.withDevTools(context),
135136
enableExpressionEvaluation: true,
136137
);
137138
vmService = context.debugConnection.vmService;

dwds/test/expression_evaluator_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void main() async {
3636
late StreamController<Event> debugEventController;
3737
setUp(() async {
3838
final assetReader = FakeAssetReader(sourceMap: '');
39-
final toolConfiguration = createToolConfiguration(
39+
final toolConfiguration = TestToolConfiguration.forTests(
4040
loadStrategy: FakeStrategy(assetReader),
4141
);
4242
setGlobalsForTesting(

dwds/test/fixtures/context.dart

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -136,46 +136,21 @@ class TestContext {
136136

137137
Future<void> setUp({
138138
ReloadConfiguration reloadConfiguration = ReloadConfiguration.none,
139-
bool serveDevTools = false,
140-
bool enableDebugExtension = false,
139+
AppMetadata? appMetadata,
140+
TestDebugSettings? debugSettings,
141141
bool autoRun = true,
142-
bool enableDebugging = true,
143-
bool useSse = true,
144-
bool spawnDds = true,
145-
String hostname = 'localhost',
146142
bool waitToDebug = false,
147-
UrlEncoder? urlEncoder,
148143
CompilationMode compilationMode = CompilationMode.buildDaemon,
149144
bool enableExpressionEvaluation = false,
150145
bool verboseCompiler = false,
151146
bool useDebuggerModuleNames = false,
152147
bool launchChrome = true,
153-
bool isFlutterApp = false,
154-
bool isInternalBuild = false,
155148
List<String> experiments = const <String>[],
156149
bool canaryFeatures = false,
157-
String? workspaceName,
158150
}) async {
151+
appMetadata ??= TestAppMetadata.externalDartApp();
152+
debugSettings ??= TestDebugSettings.noDevTools();
159153
final sdkLayout = sdkConfigurationProvider.sdkLayout;
160-
final toolConfiguration = createToolConfiguration(
161-
debugSettings: DebugSettings(
162-
enableDebugging: enableDebugging,
163-
enableDebugExtension: enableDebugExtension,
164-
useSseForDebugBackend: useSse,
165-
useSseForDebugProxy: useSse,
166-
useSseForInjectedClient: useSse,
167-
spawnDds: spawnDds,
168-
enableDevToolsLaunch: serveDevTools,
169-
urlEncoder: urlEncoder,
170-
),
171-
appMetadata: AppMetadata(
172-
hostname: hostname,
173-
isInternalBuild: isInternalBuild,
174-
isFlutterApp: () => Future.value(isFlutterApp),
175-
workspaceName: workspaceName,
176-
),
177-
);
178-
setGlobalsForTesting(toolConfiguration: toolConfiguration);
179154
try {
180155
// Make sure configuration was created correctly.
181156
final configuration = await sdkConfigurationProvider.configuration;
@@ -333,7 +308,7 @@ class TestContext {
333308

334309
_webRunner = ResidentWebRunner(
335310
mainUri: entry,
336-
urlTunneler: urlEncoder,
311+
urlTunneler: debugSettings.urlEncoder,
337312
projectDirectory: p.toUri(project.absolutePackageDirectory),
338313
packageConfigFile: project.packageConfigFile,
339314
packageUriMapper: packageUriMapper,
@@ -350,7 +325,7 @@ class TestContext {
350325
final assetServerPort = await findUnusedPort();
351326
await webRunner.run(
352327
fileSystem,
353-
hostname,
328+
appMetadata.hostname,
354329
assetServerPort,
355330
filePathToServe,
356331
);
@@ -383,6 +358,7 @@ class TestContext {
383358
// then Chrome will be launched with a UI rather than headless.
384359
// If the extension is enabled, then Chrome will be launched with a UI
385360
// since headless Chrome does not support extensions.
361+
final enableDebugExtension = debugSettings.enableDebugExtension;
386362
final headless = Platform.environment['DWDS_DEBUG_CHROME'] != 'true' &&
387363
!enableDebugExtension;
388364
if (enableDebugExtension) {
@@ -410,27 +386,17 @@ class TestContext {
410386
final connection = ChromeConnection('localhost', debugPort);
411387

412388
_testServer = await TestServer.start(
413-
hostname,
414-
port,
415-
assetHandler,
416-
assetReader,
417-
requireStrategy,
418-
project.directoryToServe,
419-
buildResults,
420-
() async => connection,
421-
serveDevTools,
422-
enableDebugExtension,
423-
autoRun,
424-
enableDebugging,
425-
useSse,
426-
urlEncoder,
427-
expressionCompiler,
428-
spawnDds,
429-
ddcService,
430-
isFlutterApp,
431-
isInternalBuild,
432-
workspaceName,
433-
sdkLayout,
389+
debugSettings:
390+
debugSettings.copyWith(expressionCompiler: expressionCompiler),
391+
appMetadata: appMetadata,
392+
port: port,
393+
assetHandler: assetHandler,
394+
assetReader: assetReader,
395+
strategy: requireStrategy,
396+
target: project.directoryToServe,
397+
buildResults: buildResults,
398+
chromeConnection: () async => connection,
399+
autoRun: autoRun,
434400
);
435401

436402
_appUrl = basePath.isEmpty
@@ -448,14 +414,14 @@ class TestContext {
448414
throw StateError('Unable to connect to tab.');
449415
}
450416

451-
if (enableDebugExtension) {
417+
if (debugSettings.enableDebugExtension) {
452418
final extensionTab = await _fetchDartDebugExtensionTab(connection);
453419
extensionConnection = await extensionTab.connect();
454420
await extensionConnection.runtime.enable();
455421
}
456422

457423
appConnection = await testServer.dwds.connectedApps.first;
458-
if (enableDebugging && !waitToDebug) {
424+
if (debugSettings.enableDebugging && !waitToDebug) {
459425
await startDebugging();
460426
}
461427
}

dwds/test/fixtures/fakes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class FakeWebkitDebugger implements WebkitDebugger {
181181

182182
FakeWebkitDebugger({Map<String, WipScript>? scripts}) : _scripts = scripts {
183183
setGlobalsForTesting(
184-
toolConfiguration: createToolConfiguration(
184+
toolConfiguration: TestToolConfiguration.forTests(
185185
loadStrategy: RequireStrategy(
186186
ReloadConfiguration.none,
187187
(_) async => {},

0 commit comments

Comments
 (0)