Unverified Commit 6e57ed60 authored by Yegor's avatar Yegor Committed by GitHub

[web] fix hot restart in entrypoint generated by `flutter create` (#110229)

parent db51e5d9
......@@ -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<void> 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<void> 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<void> runWebServiceWorkerTestWithGeneratedEntrypoint({
required bool headless,
}) async {
await _generateEntrypoint();
await runWebServiceWorkerTestWithCachingResources(headless: headless, testType: ServiceWorkerTestType.generatedEntrypoint);
}
Future<void> _generateEntrypoint() async {
final Directory tempDirectory = Directory.systemTemp.createTempSync('flutter_web_generated_entrypoint.');
await runCommand(
_flutter,
<String>[ '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<void> _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;
}
......
......@@ -1179,6 +1179,7 @@ Future<void> _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'),
......
# This file is generated by a test. It should not be committed to source control.
generated_entrypoint.html
......@@ -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();
});
});
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment