Skip to content

Commit

Permalink
Plumbing flags required for running tests with the DDC module system. (
Browse files Browse the repository at this point in the history
…#2295)

* Updating the legacy loader to use the new DDC module loader API

* Adding tests and plumbing for the DDC module system.

* updating changelog

* Restructuring asset bundling and flags

* Restructuring asset bundling and flags

* Updating test sdk paths

* Moving the module format specifier to an enum and unioning static assets across module formats

* Fixing analysis errors

* Exposing utilities/ddc_names.dart

* removing extraneous export

* Fixing race condition without extraneous plumbing.

* Extending tests and restructuring logic into helpers

* Extending sdk config tests and moving autorun functionality into the test context.

* Fixing analysis errors

* adding missing DDC sound sdks to asset generator test

* Fixing ddc and amd paths

* Keeping the first instance of an app connection and extending timeouts

* formatting files

* Exposing utilities/ddc_names.dart

* Loosen `vm_service` constraints and prepare DWDS for release to 23.1.1 (#2329)

* Reset DWDS to version `23.2.0-wip` after release (#2334)

* Adding changelog

---------

Co-authored-by: Elliott Brooks <21270878+elliette@users.noreply.github.com>
  • Loading branch information
Markzipan and elliette authored Jan 11, 2024
1 parent 7c096a2 commit 10131b1
Show file tree
Hide file tree
Showing 26 changed files with 1,383 additions and 655 deletions.
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 23.2.0-wip

- Send untruncated `dart:developer` logs to debugging clients. - [#2333](https://github.com/dart-lang/webdev/pull/2333)
- Enabling tests that run with the DDC module system and exposing `utilities/ddc_names.dart` - [#2295](https://github.com/dart-lang/webdev/pull/2295)

## 23.1.1

Expand Down
1 change: 1 addition & 0 deletions dwds/lib/dwds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ export 'src/services/expression_compiler.dart'
CompilerOptions;
export 'src/services/expression_compiler_service.dart'
show ExpressionCompilerService;
export 'src/utilities/ddc_names.dart';
export 'src/utilities/sdk_configuration.dart'
show SdkLayout, SdkConfiguration, SdkConfigurationProvider;
1 change: 1 addition & 0 deletions dwds/lib/expression_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export 'src/services/expression_compiler.dart'
ExpressionCompilationResult,
ExpressionCompiler,
CompilerOptions,
ModuleFormat,
ModuleInfo;
6 changes: 5 additions & 1 deletion dwds/lib/src/loaders/legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ class LegacyStrategy extends LoadStrategy {
return '''
$_baseUrlScript
var scripts = ${const JsonEncoder.withIndent(" ").convert(scripts)};
window.\$dartLoader.loadScripts(scripts);
window.\$dartLoader.loadConfig.loadScriptFn = function(loader) {
loader.addScriptsToQueue(scripts, null);
loader.loadEnqueuedModules();
};
window.\$dartLoader.loader.nextAttempt();
''';
}

Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ChromeProxyService implements VmServiceInterface {
'with sound null safety: $soundNullSafety');

final compilerOptions = CompilerOptions(
moduleFormat: moduleFormat,
moduleFormat: ModuleFormat.values.byName(moduleFormat),
soundNullSafety: soundNullSafety,
canaryFeatures: canaryFeatures,
experiments: experiments,
Expand Down
5 changes: 4 additions & 1 deletion dwds/lib/src/services/expression_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/// Options passed to DDC and the expression compiler.
class CompilerOptions {
final String moduleFormat;
final ModuleFormat moduleFormat;
final bool soundNullSafety;
final bool canaryFeatures;
final List<String> experiments;
Expand All @@ -17,6 +17,9 @@ class CompilerOptions {
});
}

/// Indicates the module system DDC is targeting.
enum ModuleFormat { amd, ddc, es6 }

/// Result of compilation of dart expression to JavaScript
class ExpressionCompilationResult {
final bool isError;
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/services/expression_compiler_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class _Compiler {
'--asset-server-port',
'$port',
'--module-format',
compilerOptions.moduleFormat,
compilerOptions.moduleFormat.name,
if (verbose) '--verbose',
compilerOptions.soundNullSafety
? '--sound-null-safety'
Expand Down
5 changes: 5 additions & 0 deletions dwds/lib/utilities.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'src/utilities/ddc_names.dart';
196 changes: 101 additions & 95 deletions dwds/test/devtools_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,110 +32,115 @@ void main() {

final context = TestContext(TestProject.testWithSoundNullSafety, provider);

group('Injected client', () {
setUp(() async {
await context.setUp(
debugSettings: TestDebugSettings.withDevTools(context),
);
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
// Wait for DevTools to actually open.
await Future.delayed(const Duration(seconds: 2));
});

tearDown(() async {
await context.tearDown();
});

test(
'can launch devtools',
() async {
final windows = await context.webDriver.windows.toList();
await context.webDriver.driver.switchTo.window(windows.last);
expect(await context.webDriver.pageSource, contains('DevTools'));
expect(await context.webDriver.currentUrl, contains('ide=Dwds'));
// TODO(https://github.com/dart-lang/webdev/issues/1888): Re-enable.
},
skip: Platform.isWindows,
);

test('can not launch devtools for the same app in multiple tabs', () async {
final appUrl = await context.webDriver.currentUrl;
// Open a new tab, select it, and navigate to the app
await context.webDriver.driver
.execute("window.open('$appUrl', '_blank');", []);
await Future.delayed(const Duration(seconds: 2));
final newAppWindow = await context.webDriver.windows.last;
await newAppWindow.setAsActive();
group(
'Injected client',
() {
setUp(() async {
await context.setUp(
debugSettings: TestDebugSettings.withDevTools(context),
);
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
// Wait for DevTools to actually open.
await Future.delayed(const Duration(seconds: 2));
});

// Wait for the page to be ready before trying to open DevTools again.
await _waitForPageReady(context);
tearDown(() async {
await context.tearDown();
});

// Try to open devtools and check for the alert.
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
await Future.delayed(const Duration(seconds: 2));
final alert = context.webDriver.driver.switchTo.alert;
expect(alert, isNotNull);
expect(
await alert.text,
contains('This app is already being debugged in a different tab'),
test(
'can launch devtools',
() async {
final windows = await context.webDriver.windows.toList();
await context.webDriver.driver.switchTo.window(windows.last);
expect(await context.webDriver.pageSource, contains('DevTools'));
expect(await context.webDriver.currentUrl, contains('ide=Dwds'));
// TODO(https://github.com/dart-lang/webdev/issues/1888): Re-enable.
},
skip: Platform.isWindows,
);
await alert.accept();

var windows = await context.webDriver.windows.toList();
for (final window in windows) {
if (window.id != newAppWindow.id) {
await window.setAsActive();
await window.close();
}
}
test('can not launch devtools for the same app in multiple tabs',
() async {
final appUrl = await context.webDriver.currentUrl;
// Open a new tab, select it, and navigate to the app
await context.webDriver.driver
.execute("window.open('$appUrl', '_blank');", []);
await Future.delayed(const Duration(seconds: 2));
final newAppWindow = await context.webDriver.windows.last;
await newAppWindow.setAsActive();

await newAppWindow.setAsActive();
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
await Future.delayed(const Duration(seconds: 2));
windows = await context.webDriver.windows.toList();
final devToolsWindow =
windows.firstWhere((window) => window != newAppWindow);
await devToolsWindow.setAsActive();
expect(await context.webDriver.pageSource, contains('DevTools'));
});
// Wait for the page to be ready before trying to open DevTools again.
await _waitForPageReady(context);

test(
'destroys and recreates the isolate during a page refresh',
() async {
// This test is the same as one in reload_test, but runs here when there
// is a connected client (DevTools) since it can behave differently.
// https://github.com/dart-lang/webdev/pull/901#issuecomment-586438132
final client = context.debugConnection.vmService;
await client.streamListen('Isolate');
context.makeEditToDartEntryFile(
toReplace: 'Hello World!',
replaceWith: 'Bonjour le monde!',
);
await context.waitForSuccessfulBuild(propagateToBrowser: true);

final eventsDone = expectLater(
client.onIsolateEvent,
emitsThrough(
emitsInOrder([
_hasKind(EventKind.kIsolateExit),
_hasKind(EventKind.kIsolateStart),
_hasKind(EventKind.kIsolateRunnable),
]),
),
// Try to open devtools and check for the alert.
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
await Future.delayed(const Duration(seconds: 2));
final alert = context.webDriver.driver.switchTo.alert;
expect(alert, isNotNull);
expect(
await alert.text,
contains('This app is already being debugged in a different tab'),
);
await alert.accept();

await context.webDriver.driver.refresh();
var windows = await context.webDriver.windows.toList();
for (final window in windows) {
if (window.id != newAppWindow.id) {
await window.setAsActive();
await window.close();
}
}

await eventsDone;
// Re-set the edited file:
context.makeEditToDartEntryFile(
toReplace: 'Bonjour le monde!',
replaceWith: 'Hello World!',
);
},
skip: 'https://github.com/dart-lang/webdev/issues/1888',
);
});
await newAppWindow.setAsActive();
await context.webDriver.driver.keyboard.sendChord([Keyboard.alt, 'd']);
await Future.delayed(const Duration(seconds: 2));
windows = await context.webDriver.windows.toList();
final devToolsWindow =
windows.firstWhere((window) => window != newAppWindow);
await devToolsWindow.setAsActive();
expect(await context.webDriver.pageSource, contains('DevTools'));
});

test(
'destroys and recreates the isolate during a page refresh',
() async {
// This test is the same as one in reload_test, but runs here when there
// is a connected client (DevTools) since it can behave differently.
// https://github.com/dart-lang/webdev/pull/901#issuecomment-586438132
final client = context.debugConnection.vmService;
await client.streamListen('Isolate');
context.makeEditToDartEntryFile(
toReplace: 'Hello World!',
replaceWith: 'Bonjour le monde!',
);
await context.waitForSuccessfulBuild(propagateToBrowser: true);

final eventsDone = expectLater(
client.onIsolateEvent,
emitsThrough(
emitsInOrder([
_hasKind(EventKind.kIsolateExit),
_hasKind(EventKind.kIsolateStart),
_hasKind(EventKind.kIsolateRunnable),
]),
),
);

await context.webDriver.driver.refresh();

await eventsDone;
// Re-set the edited file:
context.makeEditToDartEntryFile(
toReplace: 'Bonjour le monde!',
replaceWith: 'Hello World!',
);
},
skip: 'https://github.com/dart-lang/webdev/issues/1888',
);
},
timeout: Timeout.factor(2),
);

group('Injected client without a DevTools server', () {
setUp(() async {
Expand Down Expand Up @@ -193,6 +198,7 @@ void main() {
},
tags: ['extension'],
skip: 'https://github.com/dart-lang/webdev/issues/2114',
timeout: Timeout.factor(2),
);
}

Expand Down
2 changes: 2 additions & 0 deletions dwds/test/evaluate_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void testAll({
await context.setUp(
testSettings: TestSettings(
compilationMode: compilationMode,
moduleFormat: provider.ddcModuleFormat,
enableExpressionEvaluation: true,
useDebuggerModuleNames: useDebuggerModuleNames,
verboseCompiler: debug,
Expand Down Expand Up @@ -821,6 +822,7 @@ void testAll({
await context.setUp(
testSettings: TestSettings(
compilationMode: compilationMode,
moduleFormat: provider.ddcModuleFormat,
enableExpressionEvaluation: false,
verboseCompiler: debug,
),
Expand Down
2 changes: 1 addition & 1 deletion dwds/test/expression_compiler_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void main() async {
);

final compilerOptions = CompilerOptions(
moduleFormat: 'amd',
moduleFormat: ModuleFormat.amd,
soundNullSafety: true,
canaryFeatures: false,
experiments: const <String>[],
Expand Down
Loading

0 comments on commit 10131b1

Please sign in to comment.