Skip to content

Refactor tests to handle new ToolConfiguration #2243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dwds/test/dart_uri_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class G3TestStrategy extends FakeStrategy {
void main() {
group('DartUri', () {
setUpAll(() {
final toolConfiguration = createToolConfiguration(
final toolConfiguration = TestToolConfiguration.forTests(
loadStrategy: TestStrategy(
FakeAssetReader(),
),
Expand Down Expand Up @@ -209,7 +209,7 @@ void main() {

group('initialized to handle g3-relative paths', () {
setUpAll(() async {
final toolConfiguration = createToolConfiguration(
final toolConfiguration = TestToolConfiguration.forTests(
loadStrategy: G3TestStrategy(FakeAssetReader()),
appMetadata: AppMetadata(isInternalBuild: true),
);
Expand Down
36 changes: 23 additions & 13 deletions dwds/test/debug_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'linux': Skip('https://github.com/dart-lang/webdev/issues/2114'),
})

import 'package:dwds/config.dart';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/handlers/injector.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -61,9 +62,10 @@ void main() async {
group('Without encoding', () {
setUp(() async {
await context.setUp(
enableDebugExtension: true,
serveDevTools: true,
useSse: useSse,
debugSettings: TestDebugSettings.withDevTools(context).copyWith(
enableDebugExtension: true,
useSse: useSse,
),
);
await context.extensionConnection.sendCommand('Runtime.evaluate', {
'expression': 'fakeClick()',
Expand Down Expand Up @@ -124,9 +126,10 @@ void main() async {
group('With a sharded Dart app', () {
setUp(() async {
await context.setUp(
enableDebugExtension: true,
serveDevTools: true,
useSse: useSse,
debugSettings: TestDebugSettings.withDevTools(context).copyWith(
enableDebugExtension: true,
useSse: useSse,
),
);
final htmlTag =
await context.webDriver.findElement(const By.tagName('html'));
Expand Down Expand Up @@ -158,9 +161,10 @@ void main() async {
group('With an internal Dart app', () {
setUp(() async {
await context.setUp(
enableDebugExtension: true,
serveDevTools: true,
useSse: false,
debugSettings: TestDebugSettings.withDevTools(context).copyWith(
enableDebugExtension: true,
useSse: false,
),
);
final htmlTag =
await context.webDriver.findElement(const By.tagName('html'));
Expand Down Expand Up @@ -227,9 +231,11 @@ void main() async {
group('With encoding', () {
setUp(() async {
await context.setUp(
enableDebugExtension: true,
urlEncoder: (url) async =>
url.endsWith(r'/$debug') ? 'http://some-encoded-url:8081/' : url,
debugSettings: TestDebugSettings.noDevTools().copyWith(
enableDebugExtension: true,
urlEncoder: (url) async =>
url.endsWith(r'/$debug') ? 'http://some-encoded-url:8081/' : url,
),
);
});

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

setUp(() async {
await context.setUp(enableDebugExtension: true, hostname: 'any');
await context.setUp(
debugSettings:
TestDebugSettings.noDevTools().copyWith(enableDebugExtension: true),
appMetadata: AppMetadata(hostname: 'any'),
);
});

tearDown(() async {
Expand Down
7 changes: 6 additions & 1 deletion dwds/test/debug_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:test_common/test_sdk_configuration.dart';

import 'fixtures/context.dart';
import 'fixtures/project.dart';
import 'fixtures/utilities.dart';

void main() {
final provider = TestSdkConfigurationProvider();
Expand All @@ -22,7 +23,11 @@ void main() {

setUpAll(() async {
// Disable DDS as we're testing DWDS behavior.
await context.setUp(spawnDds: false);
await context.setUp(
debugSettings: TestDebugSettings.noDevTools().copyWith(
spawnDds: false,
),
);
});

tearDownAll(() async {
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/debugger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void main() async {
webkitDebugger = FakeWebkitDebugger(scripts: scripts);
pausedController = StreamController<DebuggerPausedEvent>();
webkitDebugger.onPaused = pausedController.stream;
final toolConfiguration = createToolConfiguration(
final toolConfiguration = TestToolConfiguration.forTests(
loadStrategy: TestStrategy(FakeAssetReader()),
);
setGlobalsForTesting(
Expand Down
16 changes: 12 additions & 4 deletions dwds/test/devtools_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:webdriver/io.dart';

import 'fixtures/context.dart';
import 'fixtures/project.dart';
import 'fixtures/utilities.dart';

Future<void> _waitForPageReady(TestContext context) async {
var attempt = 100;
Expand All @@ -34,7 +35,7 @@ void main() {
group('Injected client', () {
setUp(() async {
await context.setUp(
serveDevTools: true,
debugSettings: TestDebugSettings.withDevTools(context),
);
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
// Wait for DevTools to actually open.
Expand Down Expand Up @@ -136,9 +137,13 @@ void main() {
);
});

group('Injected client without DevTools', () {
group('Injected client without a DevTools server', () {
setUp(() async {
await context.setUp(serveDevTools: false);
await context.setUp(
debugSettings: TestDebugSettings.noDevTools().copyWith(
enableDevToolsLaunch: true,
),
);
});

tearDown(() async {
Expand All @@ -160,7 +165,10 @@ void main() {
'Injected client with debug extension and without DevTools',
() {
setUp(() async {
await context.setUp(enableDebugExtension: true, serveDevTools: false);
await context.setUp(
debugSettings: TestDebugSettings.noDevTools()
.copyWith(enableDebugExtension: true),
);
});

tearDown(() async {
Expand Down
3 changes: 2 additions & 1 deletion dwds/test/events_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:webdriver/async_core.dart';

import 'fixtures/context.dart';
import 'fixtures/project.dart';
import 'fixtures/utilities.dart';

void main() {
final provider = TestSdkConfigurationProvider();
Expand Down Expand Up @@ -131,7 +132,7 @@ void main() {
),
);
await context.setUp(
serveDevTools: true,
debugSettings: TestDebugSettings.withDevTools(context),
enableExpressionEvaluation: true,
);
vmService = context.debugConnection.vmService;
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/expression_evaluator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() async {
late StreamController<Event> debugEventController;
setUp(() async {
final assetReader = FakeAssetReader(sourceMap: '');
final toolConfiguration = createToolConfiguration(
final toolConfiguration = TestToolConfiguration.forTests(
loadStrategy: FakeStrategy(assetReader),
);
setGlobalsForTesting(
Expand Down
74 changes: 20 additions & 54 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,46 +136,21 @@ class TestContext {

Future<void> setUp({
ReloadConfiguration reloadConfiguration = ReloadConfiguration.none,
bool serveDevTools = false,
bool enableDebugExtension = false,
AppMetadata? appMetadata,
TestDebugSettings? debugSettings,
bool autoRun = true,
bool enableDebugging = true,
bool useSse = true,
bool spawnDds = true,
String hostname = 'localhost',
bool waitToDebug = false,
UrlEncoder? urlEncoder,
CompilationMode compilationMode = CompilationMode.buildDaemon,
bool enableExpressionEvaluation = false,
bool verboseCompiler = false,
bool useDebuggerModuleNames = false,
bool launchChrome = true,
bool isFlutterApp = false,
bool isInternalBuild = false,
List<String> experiments = const <String>[],
bool canaryFeatures = false,
String? workspaceName,
}) async {
appMetadata ??= TestAppMetadata.externalDartApp();
debugSettings ??= TestDebugSettings.noDevTools();
final sdkLayout = sdkConfigurationProvider.sdkLayout;
final toolConfiguration = createToolConfiguration(
debugSettings: DebugSettings(
enableDebugging: enableDebugging,
enableDebugExtension: enableDebugExtension,
useSseForDebugBackend: useSse,
useSseForDebugProxy: useSse,
useSseForInjectedClient: useSse,
spawnDds: spawnDds,
enableDevToolsLaunch: serveDevTools,
urlEncoder: urlEncoder,
),
appMetadata: AppMetadata(
hostname: hostname,
isInternalBuild: isInternalBuild,
isFlutterApp: () => Future.value(isFlutterApp),
workspaceName: workspaceName,
),
);
setGlobalsForTesting(toolConfiguration: toolConfiguration);
try {
// Make sure configuration was created correctly.
final configuration = await sdkConfigurationProvider.configuration;
Expand Down Expand Up @@ -333,7 +308,7 @@ class TestContext {

_webRunner = ResidentWebRunner(
mainUri: entry,
urlTunneler: urlEncoder,
urlTunneler: debugSettings.urlEncoder,
projectDirectory: p.toUri(project.absolutePackageDirectory),
packageConfigFile: project.packageConfigFile,
packageUriMapper: packageUriMapper,
Expand All @@ -350,7 +325,7 @@ class TestContext {
final assetServerPort = await findUnusedPort();
await webRunner.run(
fileSystem,
hostname,
appMetadata.hostname,
assetServerPort,
filePathToServe,
);
Expand Down Expand Up @@ -383,6 +358,7 @@ class TestContext {
// then Chrome will be launched with a UI rather than headless.
// If the extension is enabled, then Chrome will be launched with a UI
// since headless Chrome does not support extensions.
final enableDebugExtension = debugSettings.enableDebugExtension;
final headless = Platform.environment['DWDS_DEBUG_CHROME'] != 'true' &&
!enableDebugExtension;
if (enableDebugExtension) {
Expand Down Expand Up @@ -410,27 +386,17 @@ class TestContext {
final connection = ChromeConnection('localhost', debugPort);

_testServer = await TestServer.start(
hostname,
port,
assetHandler,
assetReader,
requireStrategy,
project.directoryToServe,
buildResults,
() async => connection,
serveDevTools,
enableDebugExtension,
autoRun,
enableDebugging,
useSse,
urlEncoder,
expressionCompiler,
spawnDds,
ddcService,
isFlutterApp,
isInternalBuild,
workspaceName,
sdkLayout,
debugSettings:
debugSettings.copyWith(expressionCompiler: expressionCompiler),
appMetadata: appMetadata,
port: port,
assetHandler: assetHandler,
assetReader: assetReader,
strategy: requireStrategy,
target: project.directoryToServe,
buildResults: buildResults,
chromeConnection: () async => connection,
autoRun: autoRun,
);

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

if (enableDebugExtension) {
if (debugSettings.enableDebugExtension) {
final extensionTab = await _fetchDartDebugExtensionTab(connection);
extensionConnection = await extensionTab.connect();
await extensionConnection.runtime.enable();
}

appConnection = await testServer.dwds.connectedApps.first;
if (enableDebugging && !waitToDebug) {
if (debugSettings.enableDebugging && !waitToDebug) {
await startDebugging();
}
}
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/fixtures/fakes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class FakeWebkitDebugger implements WebkitDebugger {

FakeWebkitDebugger({Map<String, WipScript>? scripts}) : _scripts = scripts {
setGlobalsForTesting(
toolConfiguration: createToolConfiguration(
toolConfiguration: TestToolConfiguration.forTests(
loadStrategy: RequireStrategy(
ReloadConfiguration.none,
(_) async => {},
Expand Down
Loading