@@ -280,8 +280,7 @@ abstract class HotReloadSuiteRunner {
280280 final tempDirectory =
281281 Directory .fromUri (generatedCodeDir.uri.resolve ('${test .name }/' ))
282282 ..createSync ();
283- if (options.runtime == RuntimePlatforms .d8 ||
284- options.runtime == RuntimePlatforms .chrome) {
283+ if (options.runtime.emitsJS) {
285284 filesystem = HotReloadMemoryFilesystem (tempDirectory.uri);
286285 }
287286 var compileSuccess = false ;
@@ -325,14 +324,15 @@ abstract class HotReloadSuiteRunner {
325324 await reportAllResults ();
326325 }
327326
327+ /// Custom command line arguments passed to the Front End Server on startup.
328+ List <String > get platformFrontEndServerArgs;
329+
328330 /// Returns a controller for a freshly started front end server instance to
329331 /// handle compile and recompile requests for a hot reload test.
330- // TODO(nshahan): Breakout into specialized versions for each suite runner.
331332 HotReloadFrontendServerController createFrontEndServer () {
332333 _print ('Initializing the Frontend Server.' );
333- HotReloadFrontendServerController controller;
334334 final packageConfigUri = sdkRoot.resolve ('.dart_tool/package_config.json' );
335- final commonArgs = [
335+ final fesArgs = [
336336 '--incremental' ,
337337 '--filesystem-root=${snapshotDir .uri .toFilePath ()}' ,
338338 '--filesystem-scheme=$filesystemScheme ' ,
@@ -341,40 +341,17 @@ abstract class HotReloadSuiteRunner {
341341 '--packages=${packageConfigUri .toFilePath ()}' ,
342342 '--sdk-root=${sdkRoot .toFilePath ()}' ,
343343 '--verbosity=${options .verbose ? 'all' : 'info' }' ,
344+ ...platformFrontEndServerArgs,
344345 ];
345- switch (options.runtime) {
346- case RuntimePlatforms .d8:
347- case RuntimePlatforms .chrome:
348- final ddcPlatformDillFromSdkRoot = fe_shared.relativizeUri (sdkRoot,
349- buildRootUri.resolve ('ddc_outline.dill' ), fe_shared.isWindows);
350- final fesArgs = [
351- ...commonArgs,
352- '--dartdevc-module-format=ddc' ,
353- '--dartdevc-canary' ,
354- '--platform=$ddcPlatformDillFromSdkRoot ' ,
355- '--target=dartdevc' ,
356- ];
357- controller = HotReloadFrontendServerController (fesArgs);
358- case RuntimePlatforms .vm:
359- final vmPlatformDillFromSdkRoot = fe_shared.relativizeUri (
360- sdkRoot,
361- buildRootUri.resolve ('vm_platform_strong.dill' ),
362- fe_shared.isWindows);
363- final fesArgs = [
364- ...commonArgs,
365- '--platform=$vmPlatformDillFromSdkRoot ' ,
366- '--target=vm' ,
367- ];
368- controller = HotReloadFrontendServerController (fesArgs);
369- }
370- return controller..start ();
346+ return HotReloadFrontendServerController (fesArgs)..start ();
371347 }
372348
373349 Future <void > shutdown (HotReloadFrontendServerController controller) async {
374350 // Persist the temp directory for debugging.
375351 await controller.stop ();
376352 _print ('Frontend Server has shut down.' );
377- if (! debug) {
353+ if (! options.debug) {
354+ _print ('Deleting temporary directory: ${generatedCodeDir .path }.' );
378355 generatedCodeDir.deleteSync (recursive: true );
379356 }
380357 }
@@ -691,38 +668,13 @@ abstract class HotReloadSuiteRunner {
691668 List <String > updatedFiles,
692669 HotReloadFrontendServerController controller);
693670
694- // TODO(nshahan): Refactor into runtime specific implementations.
671+ /// Runs [test] from compiled and generated assets in [tempDirectory] and
672+ /// returns `true` if it passes.
673+ ///
674+ /// All output (standard and errors) from running the test is written to
675+ /// [outputSink] .
695676 Future <bool > runTest (
696- HotReloadTest test, Directory tempDirectory, IOSink outputSink) async {
697- var testPassed = false ;
698- switch (options.runtime) {
699- case RuntimePlatforms .d8:
700- throw UnsupportedError ('Now implemented in D8SuiteRunner.' );
701- case RuntimePlatforms .chrome:
702- // Run the compiled JS generations with Chrome.
703- _print ('Creating Chrome hot reload test suite.' , label: test.name);
704- // TODO(nshahan): Clean this up! The cast here just serves as a way to
705- // allow for smaller refactor changes.
706- final suite = (this as ChromeSuiteRunner )
707- ..mainEntrypointJsUri =
708- tempDirectory.uri.resolve ('generation0/main_module.bootstrap.js' )
709- ..bootstrapJsUri =
710- tempDirectory.uri.resolve ('generation0/bootstrap.js' )
711- ..bootstrapHtmlUri =
712- tempDirectory.uri.resolve ('generation0/index.html' )
713- ..outputSink = outputSink;
714- await suite.setupTest (
715- testName: test.name,
716- scriptDescriptors: filesystem! .scriptDescriptorForBootstrap,
717- generationToModifiedFiles: filesystem! .generationsToModifiedFilePaths,
718- );
719- final exitCode = await suite.runTestOld (testName: test.name);
720- testPassed = exitCode == 0 ;
721- case RuntimePlatforms .vm:
722- throw UnsupportedError ('Now implemented in VMSuiteRunner.' );
723- }
724- return testPassed;
725- }
677+ HotReloadTest test, Directory tempDirectory, IOSink outputSink);
726678
727679 /// Reports test results to standard out as well as the output .json file if
728680 /// requested.
@@ -878,8 +830,26 @@ abstract class HotReloadSuiteRunner {
878830/// Hot reload test suite runner for DDC specific behavior that is agnostic to
879831/// the environment where the compiled code is eventually run.
880832abstract class DdcSuiteRunner extends HotReloadSuiteRunner {
833+ late final String entrypointLibraryExportName =
834+ ddc_names.libraryUriToJsIdentifier (snapshotEntrypointUri);
835+ final Uri dartSdkJSUri =
836+ buildRootUri.resolve ('gen/utils/ddc/canary/sdk/ddc/dart_sdk.js' );
837+ final Uri ddcModuleLoaderJSUri =
838+ sdkRoot.resolve ('pkg/dev_compiler/lib/js/ddc/ddc_module_loader.js' );
839+ final String ddcPlatformDillFromSdkRoot = fe_shared.relativizeUri (
840+ sdkRoot, buildRootUri.resolve ('ddc_outline.dill' ), fe_shared.isWindows);
841+ final String entrypointModuleName = 'hot-reload-test:///main.dart' ;
842+
881843 DdcSuiteRunner (super .options);
882844
845+ @override
846+ List <String > get platformFrontEndServerArgs => [
847+ '--dartdevc-module-format=ddc' ,
848+ '--dartdevc-canary' ,
849+ '--platform=$ddcPlatformDillFromSdkRoot ' ,
850+ '--target=dartdevc' ,
851+ ];
852+
883853 @override
884854 Future <bool > compileGeneration (
885855 HotReloadTest test,
@@ -965,38 +935,28 @@ abstract class DdcSuiteRunner extends HotReloadSuiteRunner {
965935/// Hot reload test suite runner for behavior specific to DDC compiled code
966936/// running in D8.
967937class D8SuiteRunner extends DdcSuiteRunner {
968- final ddc_helpers.D8Configuration config =
969- ddc_helpers.D8Configuration (sdkRoot);
970- late Uri bootstrapJsUri;
971- final String entrypointModuleName = 'hot-reload-test:///main.dart' ;
972- late final String entrypointLibraryExportName =
973- ddc_names.libraryUriToJsIdentifier (snapshotEntrypointUri);
974- final Uri dartSdkJsUri =
975- buildRootUri.resolve ('gen/utils/ddc/canary/sdk/ddc/dart_sdk.js' );
976- final Uri ddcModuleLoaderJsUri =
977- sdkRoot.resolve ('pkg/dev_compiler/lib/js/ddc/ddc_module_loader.js' );
978-
979938 D8SuiteRunner (super .options);
980939
981940 @override
982941 Future <bool > runTest (
983942 HotReloadTest test, Directory tempDirectory, IOSink outputSink) async {
984- // Run the compiled JS generations with D8.
985943 _print ('Creating D8 hot reload test suite.' , label: test.name);
986- bootstrapJsUri = tempDirectory.uri.resolve ('generation0/bootstrap.js' );
944+ final bootstrapJSUri =
945+ tempDirectory.uri.resolve ('generation0/bootstrap.js' );
987946 _print ('Preparing to run D8 test.' , label: test.name);
988947 final d8BootstrapJS = ddc_helpers.generateD8Bootstrapper (
989- ddcModuleLoaderJsPath: escapedString (ddcModuleLoaderJsUri .toFilePath ()),
990- dartSdkJsPath: escapedString (dartSdkJsUri .toFilePath ()),
948+ ddcModuleLoaderJsPath: escapedString (ddcModuleLoaderJSUri .toFilePath ()),
949+ dartSdkJsPath: escapedString (dartSdkJSUri .toFilePath ()),
991950 entrypointModuleName: escapedString (entrypointModuleName),
992951 entrypointLibraryExportName: escapedString (entrypointLibraryExportName),
993952 scriptDescriptors: filesystem! .scriptDescriptorForBootstrap,
994953 modifiedFilesPerGeneration: filesystem! .generationsToModifiedFilePaths,
995954 );
996- _debugPrint ('Writing D8 bootstrapper: $bootstrapJsUri ' , label: test.name);
997- final bootstrapJSFile = File .fromUri (bootstrapJsUri )
955+ _debugPrint ('Writing D8 bootstrapper: $bootstrapJSUri ' , label: test.name);
956+ final bootstrapJSFile = File .fromUri (bootstrapJSUri )
998957 ..writeAsStringSync (d8BootstrapJS);
999958 _debugPrint ('Running test in D8.' , label: test.name);
959+ final config = ddc_helpers.D8Configuration (sdkRoot);
1000960 final process = await startProcess ('D8' , config.binary.toFilePath (), [
1001961 config.sealNativeObjectScript.toFilePath (),
1002962 config.preamblesScript.toFilePath (),
@@ -1010,81 +970,59 @@ class D8SuiteRunner extends DdcSuiteRunner {
1010970/// Hot reload test suite runner for behavior specific to DDC compiled code
1011971/// running in Chrome.
1012972class ChromeSuiteRunner extends DdcSuiteRunner {
1013- final ddc_helpers.ChromeConfiguration config =
1014- ddc_helpers.ChromeConfiguration (sdkRoot);
1015- late Uri bootstrapJsUri;
1016- late Uri mainEntrypointJsUri;
1017- late Uri bootstrapHtmlUri;
1018- final String entrypointModuleName = 'hot-reload-test:///main.dart' ;
1019- late final String entrypointLibraryExportName =
1020- ddc_names.libraryUriToJsIdentifier (snapshotEntrypointUri);
1021- final Uri dartSdkJsUri =
1022- buildRootUri.resolve ('gen/utils/ddc/canary/sdk/ddc/dart_sdk.js' );
1023- final Uri ddcModuleLoaderJsUri =
1024- sdkRoot.resolve ('pkg/dev_compiler/lib/js/ddc/ddc_module_loader.js' );
1025- late StreamSink <List <int >> outputSink;
1026-
1027973 ChromeSuiteRunner (super .options);
1028974
1029- /// Generates all files required for bootstrapping a DDC project in Chrome.
1030- void _generateBootstrapper ({
1031- required List <Map <String , String ?>> scriptDescriptors,
1032- required ddc_helpers.FileDataPerGeneration generationToModifiedFiles,
1033- }) {
975+ @override
976+ Future <bool > runTest (
977+ HotReloadTest test, Directory tempDirectory, IOSink outputSink) async {
978+ // TODO(markzipan): Chrome tests are currently only configured for
979+ // debugging a single test instance. This is due to:
980+ // 1) Our tests not capturing test success/failure signals. These must be
981+ // determined programmatically since Chrome console errors are unrelated
982+ // to the Chrome process's stderr.
983+ // 2) Chrome not closing after a test. We need to add logic to detect when
984+ // to either shut down Chrome or load the next test (reusing instances).
985+ _print ('Creating Chrome hot reload test suite.' , label: test.name);
986+ final mainEntrypointJSUri =
987+ tempDirectory.uri.resolve ('generation0/main_module.bootstrap.js' );
988+ final bootstrapJSUri =
989+ tempDirectory.uri.resolve ('generation0/bootstrap.js' );
990+ final bootstrapHtmlUri =
991+ tempDirectory.uri.resolve ('generation0/index.html' );
992+ _print ('Preparing to run Chrome test.' , label: test.name);
1034993 var bootstrapHtml = '''
1035994 <html>
1036995 <head>
1037996 <base href="/">
1038997 </head>
1039998 <body>
1040- <script src="$bootstrapJsUri "></script>
999+ <script src="$bootstrapJSUri "></script>
10411000 </body>
10421001 </html>
10431002 ''' ;
1044-
1003+ final entrypointLibraryExportName =
1004+ ddc_names.libraryUriToJsIdentifier (snapshotEntrypointUri);
10451005 final (chromeMainEntrypointJS, chromeBootstrapJS) =
10461006 ddc_helpers.generateChromeBootstrapperFiles (
1047- ddcModuleLoaderJsPath: escapedString (ddcModuleLoaderJsUri .toFilePath ()),
1048- dartSdkJsPath: escapedString (dartSdkJsUri .toFilePath ()),
1007+ ddcModuleLoaderJsPath: escapedString (ddcModuleLoaderJSUri .toFilePath ()),
1008+ dartSdkJsPath: escapedString (dartSdkJSUri .toFilePath ()),
10491009 entrypointModuleName: escapedString (entrypointModuleName),
10501010 mainModuleEntrypointJsPath:
1051- escapedString (mainEntrypointJsUri .toFilePath ()),
1011+ escapedString (mainEntrypointJSUri .toFilePath ()),
10521012 entrypointLibraryExportName: escapedString (entrypointLibraryExportName),
10531013 scriptDescriptors: filesystem! .scriptDescriptorForBootstrap,
10541014 modifiedFilesPerGeneration: filesystem! .generationsToModifiedFilePaths,
10551015 );
1056-
1057- File .fromUri (mainEntrypointJsUri).writeAsStringSync (chromeMainEntrypointJS);
1058- File .fromUri (bootstrapJsUri).writeAsStringSync (chromeBootstrapJS);
1059- File .fromUri (bootstrapHtmlUri).writeAsStringSync (bootstrapHtml);
1060- }
1061-
1062- Future <void > setupTest ({
1063- String ? testName,
1064- List <Map <String , String ?>>? scriptDescriptors,
1065- ddc_helpers.FileDataPerGeneration ? generationToModifiedFiles,
1066- }) async {
1067- _print ('Preparing to run Chrome test.' , label: testName);
1068- if (scriptDescriptors == null || generationToModifiedFiles == null ) {
1069- throw ArgumentError ('ChromeSuiteRunner requires that "scriptDescriptors" '
1070- 'and "generationToModifiedFiles" be provided during setup.' );
1071- }
1072- _generateBootstrapper (
1073- scriptDescriptors: scriptDescriptors,
1074- generationToModifiedFiles: generationToModifiedFiles);
1075- _debugPrint ('Writing Chrome bootstrapper: $bootstrapJsUri ' ,
1076- label: testName);
1077- }
1078-
1079- Future <int > runTestOld ({String ? testName}) async {
1080- // TODO(markzipan): Chrome tests are currently only configured for
1081- // debugging a single test instance. This is due to:
1082- // 1) Our tests not capturing test success/failure signals. These must be
1083- // determined programmatically since Chrome console errors are unrelated
1084- // to the Chrome process's stderr.
1085- // 2) Chrome not closing after a test. We need to add logic to detect when
1086- // to either shut down Chrome or load the next test (reusing instances).
1087-
1016+ _debugPrint (
1017+ 'Writing Chrome bootstrap files: '
1018+ '$mainEntrypointJSUri , $bootstrapJSUri , $bootstrapHtmlUri ' ,
1019+ label: test.name);
1020+ File .fromUri (mainEntrypointJSUri).writeAsStringSync (chromeMainEntrypointJS);
1021+ File .fromUri (bootstrapJSUri).writeAsStringSync (chromeBootstrapJS);
1022+ final bootstrapHtmlFile = File .fromUri (bootstrapHtmlUri)
1023+ ..writeAsStringSync (bootstrapHtml);
1024+ _debugPrint ('Running test in Chrome.' , label: test.name);
1025+ final config = ddc_helpers.ChromeConfiguration (sdkRoot);
10881026 // Specifying '--user-data-dir' forces Chrome to not reuse an instance.
10891027 final chromeDataDir = Directory .systemTemp.createTempSync ();
10901028 final process = await startProcess ('Chrome' , config.binary.toFilePath (), [
@@ -1094,7 +1032,7 @@ class ChromeSuiteRunner extends DdcSuiteRunner {
10941032 '--user-data-dir=${chromeDataDir .path }' ,
10951033 '--disable-default-apps' ,
10961034 '--disable-translate' ,
1097- bootstrapHtmlUri. toFilePath () ,
1035+ bootstrapHtmlFile.path ,
10981036 ]).then ((process) {
10991037 StreamSubscription stdoutSubscription;
11001038 StreamSubscription stderrSubscription;
@@ -1124,13 +1062,13 @@ class ChromeSuiteRunner extends DdcSuiteRunner {
11241062 });
11251063
11261064 Future .wait ([stdoutDone.future, stderrDone.future]).then ((_) {
1127- _debugPrint ('Chrome process successfully shut down.' , label: testName );
1065+ _debugPrint ('Chrome process successfully shut down.' , label: test.name );
11281066 });
11291067
11301068 return process;
11311069 });
11321070
1133- return process.exitCode;
1071+ return await process.exitCode == 0 ;
11341072 }
11351073
11361074 @override
@@ -1157,8 +1095,17 @@ class ChromeSuiteRunner extends DdcSuiteRunner {
11571095
11581096/// Hot reload test suite runner for behavior specific to the VM.
11591097class VMSuiteRunner extends HotReloadSuiteRunner {
1098+ final String vmPlatformDillFromSdkRoot = fe_shared.relativizeUri (sdkRoot,
1099+ buildRootUri.resolve ('vm_platform_strong.dill' ), fe_shared.isWindows);
1100+
11601101 VMSuiteRunner (super .options);
11611102
1103+ @override
1104+ List <String > get platformFrontEndServerArgs => [
1105+ '--platform=$vmPlatformDillFromSdkRoot ' ,
1106+ '--target=vm' ,
1107+ ];
1108+
11621109 @override
11631110 Future <bool > compileGeneration (
11641111 HotReloadTest test,
0 commit comments