Skip to content
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

Plumbing flags required for running tests with the DDC module system. #2295

Merged
merged 29 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
61f964b
Updating the legacy loader to use the new DDC module loader API
Markzipan Nov 27, 2023
e17f872
Adding tests and plumbing for the DDC module system.
Markzipan Nov 27, 2023
6a01aad
updating changelog
Markzipan Dec 1, 2023
2e4d0a2
Merge branch 'dart-lang:master' into ddc-test-plumbing
Markzipan Dec 1, 2023
188a5ae
Restructuring asset bundling and flags
Markzipan Dec 4, 2023
c055748
Restructuring asset bundling and flags
Markzipan Dec 4, 2023
cc66e55
Updating test sdk paths
Markzipan Dec 5, 2023
e37da6b
Moving the module format specifier to an enum and unioning static ass…
Markzipan Dec 7, 2023
dcbea77
Fixing analysis errors
Markzipan Dec 7, 2023
40ac194
Exposing utilities/ddc_names.dart
Markzipan Dec 7, 2023
83d5feb
removing extraneous export
Markzipan Dec 7, 2023
6d5bcfe
Fixing race condition without extraneous plumbing.
Markzipan Dec 12, 2023
2cff2ce
Extending tests and restructuring logic into helpers
Markzipan Dec 12, 2023
84ee640
Merge branch 'master' into ddc-test-plumbing
Markzipan Dec 12, 2023
77bd6eb
Extending sdk config tests and moving autorun functionality into the …
Markzipan Dec 13, 2023
43e6446
Merge branch 'master' into ddc-test-plumbing
Markzipan Dec 13, 2023
69fa508
Merge branch 'master' into ddc-test-plumbing
Markzipan Dec 14, 2023
7330d99
Fixing analysis errors
Markzipan Dec 14, 2023
b30a41f
adding missing DDC sound sdks to asset generator test
Markzipan Dec 14, 2023
5b9854e
Fixing ddc and amd paths
Markzipan Dec 14, 2023
c606696
Keeping the first instance of an app connection and extending timeouts
Markzipan Dec 18, 2023
dafca8a
formatting files
Markzipan Dec 19, 2023
819bcf5
Merge remote-tracking branch 'origin' into ddc-test-plumbing
Markzipan Jan 9, 2024
42c674e
Exposing utilities/ddc_names.dart
Markzipan Dec 7, 2023
f4ae7e2
Loosen `vm_service` constraints and prepare DWDS for release to 23.1.…
elliette Jan 9, 2024
4f143c9
Reset DWDS to version `23.2.0-wip` after release (#2334)
elliette Jan 10, 2024
ac28b96
Adding changelog
Markzipan Jan 10, 2024
e4c7df0
Merge remote-tracking branch 'origin/master' into ddc-test-plumbing
Markzipan Jan 10, 2024
dbcb892
Merge remote-tracking branch 'origin' into ddc-test-plumbing
Markzipan Jan 11, 2024
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
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Restructure `LoadStrategy` to provide build settings. - [#2270](https://github.com/dart-lang/webdev/pull/2270)
- Add `FrontendServerLegacyStrategyProvider` and update bootstrap generation logic for `LegacyStrategy` - [#2285](https://github.com/dart-lang/webdev/pull/2285)
- Tolerate failures to detect a dart execution context. - [#2286](https://github.com/dart-lang/webdev/pull/2286)
- Enabling tests that run with the DDC module system and exposing `utilities/ddc_names.dart` - [#2295](https://github.com/dart-lang/webdev/pull/2295)

## 22.1.0
- Update `package:vm_service` constraint to `^13.0.0`. - [#2265](https://github.com/dart-lang/webdev/pull/2265)
Expand Down
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),
Markzipan marked this conversation as resolved.
Show resolved Hide resolved
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.
Markzipan marked this conversation as resolved.
Show resolved Hide resolved
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';
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
60 changes: 44 additions & 16 deletions dwds/test/fixtures/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
// 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.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:build_daemon/client.dart';
import 'package:build_daemon/data/build_status.dart';
import 'package:build_daemon/data/build_target.dart';
import 'package:dwds/asset_reader.dart';
import 'package:dwds/expression_compiler.dart';
import 'package:dwds/src/connections/app_connection.dart';
import 'package:dwds/src/connections/debug_connection.dart';
import 'package:dwds/src/debugging/webkit_debugger.dart';
import 'package:dwds/src/loaders/build_runner_require.dart';
import 'package:dwds/src/loaders/frontend_server_legacy.dart';
import 'package:dwds/src/loaders/frontend_server_require.dart';
import 'package:dwds/src/loaders/require.dart';
import 'package:dwds/src/loaders/strategy.dart';
import 'package:dwds/src/readers/proxy_server_asset_reader.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart';
import 'package:dwds/src/services/expression_compiler.dart';
import 'package:dwds/src/services/expression_compiler_service.dart';
import 'package:dwds/src/utilities/dart_uri.dart';
import 'package:dwds/src/utilities/server.dart';
Expand Down Expand Up @@ -204,7 +206,7 @@ class TestContext {
ExpressionCompiler? expressionCompiler;
AssetReader assetReader;
Stream<BuildResults> buildResults;
RequireStrategy requireStrategy;
LoadStrategy loadStrategy;
String basePath = '';
String filePathToServe = project.filePathToServe;

Expand Down Expand Up @@ -268,7 +270,7 @@ class TestContext {
expressionCompiler = ddcService;
}

requireStrategy = BuildRunnerRequireStrategyProvider(
loadStrategy = BuildRunnerRequireStrategyProvider(
assetHandler,
testSettings.reloadConfiguration,
assetReader,
Expand Down Expand Up @@ -301,6 +303,7 @@ class TestContext {
nullSafety: project.nullSafety,
experiments: buildSettings.experiments,
canaryFeatures: buildSettings.canaryFeatures,
moduleFormat: testSettings.moduleFormat,
);

_webRunner = ResidentWebRunner(
Expand Down Expand Up @@ -332,14 +335,24 @@ class TestContext {
basePath = webRunner.devFS.assetServer.basePath;
assetReader = webRunner.devFS.assetServer;
_assetHandler = webRunner.devFS.assetServer.handleRequest;
requireStrategy = FrontendServerRequireStrategyProvider(
testSettings.reloadConfiguration,
assetReader,
packageUriMapper,
() async => {},
buildSettings,
).strategy;

loadStrategy = switch (testSettings.moduleFormat) {
Markzipan marked this conversation as resolved.
Show resolved Hide resolved
ModuleFormat.amd => FrontendServerRequireStrategyProvider(
testSettings.reloadConfiguration,
assetReader,
packageUriMapper,
() async => {},
buildSettings,
).strategy,
ModuleFormat.ddc => FrontendServerLegacyStrategyProvider(
testSettings.reloadConfiguration,
assetReader,
packageUriMapper,
() async => {},
buildSettings,
).strategy,
_ => throw Exception(
'Unsupported DDC module format ${testSettings.moduleFormat.name}.')
};
buildResults = const Stream<BuildResults>.empty();
}
break;
Expand Down Expand Up @@ -380,6 +393,11 @@ class TestContext {
),
);
}

// The debugger tab must be enabled and connected before certain
// listeners in DWDS or `main` is run.
final tabConnectionCompleter = Completer();
final appConnectionCompleter = Completer();
final connection = ChromeConnection('localhost', debugPort);

_testServer = await TestServer.start(
Expand All @@ -389,13 +407,21 @@ class TestContext {
port: port,
assetHandler: assetHandler,
assetReader: assetReader,
strategy: requireStrategy,
strategy: loadStrategy,
target: project.directoryToServe,
buildResults: buildResults,
chromeConnection: () async => connection,
autoRun: testSettings.autoRun,
autoRun: false,
Markzipan marked this conversation as resolved.
Show resolved Hide resolved
);

_testServer!.dwds.connectedApps.listen((connection) async {
Markzipan marked this conversation as resolved.
Show resolved Hide resolved
// Ensure that we've established a tab connection before running main.
await tabConnectionCompleter.future;
connection.runMain();
appConnection = connection;
appConnectionCompleter.complete();
});

_appUrl = basePath.isEmpty
? 'http://localhost:$port/$filePathToServe'
: 'http://localhost:$port/$basePath/$filePathToServe';
Expand All @@ -406,7 +432,9 @@ class TestContext {
if (tab != null) {
_tabConnection = await tab.connect();
await tabConnection.runtime.enable();
await tabConnection.debugger.enable();
await tabConnection.debugger
.enable()
.then((_) => tabConnectionCompleter.complete());
} else {
throw StateError('Unable to connect to tab.');
}
Expand All @@ -417,7 +445,7 @@ class TestContext {
await extensionConnection.runtime.enable();
}

appConnection = await testServer.dwds.connectedApps.first;
await appConnectionCompleter.future;
if (debugSettings.enableDebugging && !testSettings.waitToDebug) {
await startDebugging();
}
Expand Down
4 changes: 2 additions & 2 deletions dwds/test/fixtures/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:dwds/asset_reader.dart';
import 'package:dwds/dart_web_debug_service.dart';
import 'package:dwds/data/build_result.dart';
import 'package:dwds/src/config/tool_configuration.dart';
import 'package:dwds/src/loaders/require.dart';
import 'package:dwds/src/loaders/strategy.dart';
import 'package:dwds/src/utilities/server.dart';
import 'package:logging/logging.dart';
import 'package:shelf/shelf.dart';
Expand Down Expand Up @@ -62,7 +62,7 @@ class TestServer {
required AppMetadata appMetadata,
required Handler assetHandler,
required AssetReader assetReader,
required RequireStrategy strategy,
required LoadStrategy strategy,
required String target,
required Stream<daemon.BuildResults> buildResults,
required Future<ChromeConnection> Function() chromeConnection,
Expand Down
4 changes: 3 additions & 1 deletion dwds/test/fixtures/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class TestSettings {

// Build settings.
final CompilationMode compilationMode;
final ModuleFormat moduleFormat;
final bool canaryFeatures;
final bool isFlutterApp;
final List<String> experiments;
Expand All @@ -255,6 +256,7 @@ class TestSettings {
this.verboseCompiler = false,
this.launchChrome = true,
this.compilationMode = CompilationMode.buildDaemon,
this.moduleFormat = ModuleFormat.amd,
this.canaryFeatures = false,
this.isFlutterApp = false,
this.experiments = const <String>[],
Expand Down Expand Up @@ -296,8 +298,8 @@ class TestCompilerOptions extends CompilerOptions {
required NullSafety nullSafety,
required super.canaryFeatures,
required List<String> experiments,
super.moduleFormat = ModuleFormat.amd,
}) : super(
moduleFormat: 'amd',
soundNullSafety: nullSafety == NullSafety.sound,
experiments: const <String>[],
);
Expand Down
53 changes: 53 additions & 0 deletions dwds/test/frontend_server_ddc_evaluate_sound_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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.

@Tags(['daily'])
@TestOn('vm')
@Timeout(Duration(minutes: 5))

import 'dart:io';

import 'package:dwds/expression_compiler.dart';
import 'package:test/test.dart';
import 'package:test_common/test_sdk_configuration.dart';

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

void main() async {
// Enable verbose logging for debugging.
final debug = false;

final provider = TestSdkConfigurationProvider(
verbose: debug,
ddcModuleFormat: ModuleFormat.ddc,
);
tearDownAll(provider.dispose);

for (var useDebuggerModuleNames in [false, true]) {
group('Debugger module names: $useDebuggerModuleNames |', () {
final nullSafety = NullSafety.sound;
group('${nullSafety.name} null safety | DDC module system |', () {
for (var indexBaseMode in IndexBaseMode.values) {
group(
'with ${indexBaseMode.name} |',
() {
testAll(
provider: provider,
compilationMode: CompilationMode.frontendServer,
indexBaseMode: indexBaseMode,
nullSafety: nullSafety,
useDebuggerModuleNames: useDebuggerModuleNames,
debug: debug,
);
},
// https://github.com/dart-lang/sdk/issues/49277
skip: indexBaseMode == IndexBaseMode.base && Platform.isWindows,
);
}
});
});
}
}
Loading
Loading