mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This makes several changes to flutter web app bootstrapping. * The build now produces a `flutter_bootstrap.js` file. * By default, this file does the basic streamlined startup of a flutter app with the service worker settings and no user configuration. * The user can also put a `flutter_bootstrap.js` file in the `web` subdirectory in the project directory which can have whatever custom bootstrapping logic they'd like to write instead. This file is also templated, and can use any of the tokens that can be used with the `index.html` (with the exception of `{{flutter_bootstrap_js}}`, see below). * Introduced a few new templating tokens for `index.html`: * `{{flutter_js}}` => inlines the entirety of `flutter.js` * `{{flutter_service_worker_version}}` => replaced directly by the service worker version. This can be used instead of the script that sets the `serviceWorkerVersion` local variable that we used to have by default. * `{{flutter_bootstrap_js}}` => inlines the entirety of `flutter_bootstrap.js` (this token obviously doesn't apply to `flutter_bootstrap.js` itself). * Changed `IndexHtml` to be called `WebTemplate` instead, since it is used for more than just the index.html now. * We now emit warnings at build time for certain deprecated flows: * Warn on the old service worker version pattern (i.e.`(const|var) serviceWorkerVersion = null`) and recommends using `{{flutter_service_worker_version}}` token instead * Warn on use of `FlutterLoader.loadEntrypoint` and recommend using `FlutterLoader.load` instead * Warn on manual loading of `flutter_service_worker.js`. * The default `index.html` on `flutter create` now uses an async script tag with `flutter_bootstrap.js`.
88 lines
3.6 KiB
Dart
88 lines
3.6 KiB
Dart
// Copyright 2014 The Flutter Authors. 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 'package:file/file.dart';
|
|
|
|
import '../integration.shard/test_data/hot_reload_project.dart';
|
|
import '../integration.shard/test_driver.dart';
|
|
import '../integration.shard/test_utils.dart';
|
|
import '../src/common.dart';
|
|
|
|
import 'test_data/hot_reload_index_html_samples.dart';
|
|
|
|
void main() async {
|
|
await _testProject(HotReloadProject()); // default
|
|
await _testProject(HotReloadProject(constApp: true), name: 'Default) (with `const MyApp()`)'); // runApp(const MyApp());
|
|
await _testProject(HotReloadProject(indexHtml: indexHtmlFlutterJsCallback), name: 'flutter.js (callback)');
|
|
await _testProject(HotReloadProject(indexHtml: indexHtmlFlutterJsPromisesFull), name: 'flutter.js (promises)');
|
|
await _testProject(HotReloadProject(indexHtml: indexHtmlFlutterJsPromisesShort), name: 'flutter.js (promises, short)');
|
|
await _testProject(HotReloadProject(indexHtml: indexHtmlFlutterJsLoad), name: 'flutter.js (load)');
|
|
await _testProject(HotReloadProject(indexHtml: indexHtmlNoFlutterJs), name: 'No flutter.js');
|
|
await _testProject(HotReloadProject(indexHtml: indexHtmlWithFlutterBootstrapScriptTag), name: 'Using flutter_bootstrap.js script tag');
|
|
await _testProject(HotReloadProject(indexHtml: indexHtmlWithInlinedFlutterBootstrapScript), name: 'Using inlined flutter_bootstrap.js');
|
|
}
|
|
|
|
Future<void> _testProject(HotReloadProject project, {String name = 'Default'}) async {
|
|
late Directory tempDir;
|
|
late FlutterRunTestDriver flutter;
|
|
|
|
final String testName = 'Hot reload (index.html: $name)';
|
|
|
|
setUp(() async {
|
|
tempDir = createResolvedTempDirectorySync('hot_reload_test.');
|
|
await project.setUpIn(tempDir);
|
|
flutter = FlutterRunTestDriver(tempDir);
|
|
});
|
|
|
|
tearDown(() async {
|
|
await flutter.stop();
|
|
await flutter.done;
|
|
tryToDelete(tempDir);
|
|
});
|
|
|
|
testWithoutContext('$testName: hot restart works without error', () async {
|
|
flutter.stdout.listen(printOnFailure);
|
|
await flutter.run(chrome: true, additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
|
|
await flutter.hotRestart();
|
|
});
|
|
|
|
testWithoutContext('$testName: newly added code executes during hot restart', () async {
|
|
final Completer<void> completer = Completer<void>();
|
|
final StreamSubscription<String> subscription = flutter.stdout.listen((String line) {
|
|
printOnFailure(line);
|
|
if (line.contains('(((((RELOAD WORKED)))))')) {
|
|
completer.complete();
|
|
}
|
|
});
|
|
await flutter.run(chrome: true, additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
|
|
project.uncommentHotReloadPrint();
|
|
try {
|
|
await flutter.hotRestart();
|
|
await completer.future.timeout(const Duration(seconds: 15));
|
|
} finally {
|
|
await subscription.cancel();
|
|
}
|
|
});
|
|
|
|
testWithoutContext('$testName: newly added code executes during hot restart - canvaskit', () async {
|
|
final Completer<void> completer = Completer<void>();
|
|
final StreamSubscription<String> subscription = flutter.stdout.listen((String line) {
|
|
printOnFailure(line);
|
|
if (line.contains('(((((RELOAD WORKED)))))')) {
|
|
completer.complete();
|
|
}
|
|
});
|
|
await flutter.run(chrome: true, additionalCommandArgs: <String>['--verbose', '--web-renderer=canvaskit']);
|
|
project.uncommentHotReloadPrint();
|
|
try {
|
|
await flutter.hotRestart();
|
|
await completer.future.timeout(const Duration(seconds: 15));
|
|
} finally {
|
|
await subscription.cancel();
|
|
}
|
|
}, skip: true); // Skipped for https://github.com/flutter/flutter/issues/110879.
|
|
}
|