diff --git a/dev/bots/service_worker_test.dart b/dev/bots/service_worker_test.dart index e228c17c54..e0ec0aca50 100644 --- a/dev/bots/service_worker_test.dart +++ b/dev/bots/service_worker_test.dart @@ -30,10 +30,16 @@ enum ServiceWorkerTestType { withFlutterJs, withFlutterJsShort, withFlutterJsEntrypointLoadedEvent, + + // Entrypoint generated by `flutter create`. + generatedEntrypoint, } // Run a web service worker test as a standalone Dart program. Future main() async { + // When updating this list, also update `dev/bots/test.dart`. This `main()` + // function is only here for convenience. Adding tests here will not add them + // to LUCI. await runWebServiceWorkerTest(headless: false, testType: ServiceWorkerTestType.withoutFlutterJs); await runWebServiceWorkerTest(headless: false, testType: ServiceWorkerTestType.withFlutterJs); await runWebServiceWorkerTest(headless: false, testType: ServiceWorkerTestType.withFlutterJsShort); @@ -42,13 +48,42 @@ Future main() async { await runWebServiceWorkerTestWithCachingResources(headless: false, testType: ServiceWorkerTestType.withFlutterJs); await runWebServiceWorkerTestWithCachingResources(headless: false, testType: ServiceWorkerTestType.withFlutterJsShort); await runWebServiceWorkerTestWithCachingResources(headless: false, testType: ServiceWorkerTestType.withFlutterJsEntrypointLoadedEvent); + await runWebServiceWorkerTestWithGeneratedEntrypoint(headless: false); await runWebServiceWorkerTestWithBlockedServiceWorkers(headless: false); + if (hasError) { print('One or more tests failed.'); reportErrorsAndExit(); } } +// Regression test for https://github.com/flutter/flutter/issues/109093. +// +// Tests the entrypoint that's generated by `flutter create`. +Future runWebServiceWorkerTestWithGeneratedEntrypoint({ + required bool headless, +}) async { + await _generateEntrypoint(); + await runWebServiceWorkerTestWithCachingResources(headless: headless, testType: ServiceWorkerTestType.generatedEntrypoint); +} + +Future _generateEntrypoint() async { + final Directory tempDirectory = Directory.systemTemp.createTempSync('flutter_web_generated_entrypoint.'); + await runCommand( + _flutter, + [ 'create', 'generated_entrypoint_test' ], + workingDirectory: tempDirectory.path, + ); + final File generatedEntrypoint = File(path.join(tempDirectory.path, 'generated_entrypoint_test', 'web', 'index.html')); + final String generatedEntrypointCode = generatedEntrypoint.readAsStringSync(); + final File testEntrypoint = File(path.join( + _testAppWebDirectory, + _testTypeToIndexFile(ServiceWorkerTestType.generatedEntrypoint), + )); + testEntrypoint.writeAsStringSync(generatedEntrypointCode); + tempDirectory.deleteSync(recursive: true); +} + Future _setAppVersion(int version) async { final File targetFile = File(_targetPath); await targetFile.writeAsString( @@ -77,6 +112,9 @@ String _testTypeToIndexFile(ServiceWorkerTestType type) { case ServiceWorkerTestType.withFlutterJsEntrypointLoadedEvent: indexFile = 'index_with_flutterjs_entrypoint_loaded.html'; break; + case ServiceWorkerTestType.generatedEntrypoint: + indexFile = 'generated_entrypoint.html'; + break; } return indexFile; } diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 098bca6497..67cd26f2f8 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -1179,6 +1179,7 @@ Future _runWebLongRunningTests() async { () => runWebServiceWorkerTestWithCachingResources(headless: true, testType: ServiceWorkerTestType.withFlutterJs), () => runWebServiceWorkerTestWithCachingResources(headless: true, testType: ServiceWorkerTestType.withFlutterJsShort), () => runWebServiceWorkerTestWithCachingResources(headless: true, testType: ServiceWorkerTestType.withFlutterJsEntrypointLoadedEvent), + () => runWebServiceWorkerTestWithGeneratedEntrypoint(headless: true), () => runWebServiceWorkerTestWithBlockedServiceWorkers(headless: true), () => _runWebStackTraceTest('profile', 'lib/stack_trace.dart'), () => _runWebStackTraceTest('release', 'lib/stack_trace.dart'), diff --git a/dev/integration_tests/web/web/.gitignore b/dev/integration_tests/web/web/.gitignore new file mode 100644 index 0000000000..8edeffb23f --- /dev/null +++ b/dev/integration_tests/web/web/.gitignore @@ -0,0 +1,2 @@ +# This file is generated by a test. It should not be committed to source control. +generated_entrypoint.html diff --git a/packages/flutter_tools/templates/app_shared/web/index.html.tmpl b/packages/flutter_tools/templates/app_shared/web/index.html.tmpl index 2ac781ff3b..6d9aa4d08c 100644 --- a/packages/flutter_tools/templates/app_shared/web/index.html.tmpl +++ b/packages/flutter_tools/templates/app_shared/web/index.html.tmpl @@ -46,11 +46,12 @@ _flutter.loader.loadEntrypoint({ serviceWorker: { serviceWorkerVersion: serviceWorkerVersion, + }, + onEntrypointLoaded: function(engineInitializer) { + engineInitializer.initializeEngine().then(function(appRunner) { + appRunner.runApp(); + }); } - }).then(function(engineInitializer) { - return engineInitializer.initializeEngine(); - }).then(function(appRunner) { - return appRunner.runApp(); }); });