forked from firka/flutter
Support deferred imports on profile/release builds of Flutter Web (#41222)
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
@@ -25,6 +29,7 @@ void main() {
|
||||
MockWebCompilationProxy mockWebCompilationProxy;
|
||||
Testbed testbed;
|
||||
MockPlatform mockPlatform;
|
||||
bool addArchive = false;
|
||||
|
||||
setUpAll(() {
|
||||
Cache.flutterRoot = '';
|
||||
@@ -32,6 +37,7 @@ void main() {
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
addArchive = false;
|
||||
mockWebCompilationProxy = MockWebCompilationProxy();
|
||||
testbed = Testbed(setup: () {
|
||||
fs.file('pubspec.yaml')
|
||||
@@ -46,9 +52,18 @@ void main() {
|
||||
mode: anyNamed('mode'),
|
||||
initializePlatform: anyNamed('initializePlatform'),
|
||||
)).thenAnswer((Invocation invocation) {
|
||||
final String path = fs.path.join('.dart_tool', 'build', 'flutter_web', 'foo', 'lib', 'main_web_entrypoint.dart.js');
|
||||
final String prefix = fs.path.join('.dart_tool', 'build', 'flutter_web', 'foo', 'lib');
|
||||
final String path = fs.path.join(prefix, 'main_web_entrypoint.dart.js');
|
||||
fs.file(path).createSync(recursive: true);
|
||||
fs.file('$path.map').createSync();
|
||||
if (addArchive) {
|
||||
final List<int> bytes = utf8.encode('void main() {}');
|
||||
final TarEncoder encoder = TarEncoder();
|
||||
final Archive archive = Archive()
|
||||
..addFile(ArchiveFile.noCompress('main_web_entrypoint.1.dart.js', bytes.length, bytes));
|
||||
fs.file(fs.path.join(prefix, 'main_web_entrypoint.dart.js.tar.gz'))
|
||||
..writeAsBytes(encoder.encode(archive));
|
||||
}
|
||||
return Future<bool>.value(true);
|
||||
});
|
||||
}, overrides: <Type, Generator>{
|
||||
@@ -59,6 +74,19 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
test('Copies generated part files out of build directory', () => testbed.run(() async {
|
||||
addArchive = true;
|
||||
await buildWeb(
|
||||
FlutterProject.current(),
|
||||
fs.path.join('lib', 'main.dart'),
|
||||
BuildInfo.release,
|
||||
false,
|
||||
);
|
||||
|
||||
expect(fs.file(fs.path.join('build', 'web', 'main_web_entrypoint.1.dart.js')), exists);
|
||||
expect(fs.file(fs.path.join('build', 'web', 'main.dart.js')), exists);
|
||||
}));
|
||||
|
||||
test('Refuses to build for web when missing index.html', () => testbed.run(() async {
|
||||
fs.file(fs.path.join('web', 'index.html')).deleteSync();
|
||||
|
||||
@@ -82,16 +110,6 @@ void main() {
|
||||
expect(await runner.run(), 1);
|
||||
}));
|
||||
|
||||
test('Can build for web', () => testbed.run(() async {
|
||||
|
||||
await buildWeb(
|
||||
FlutterProject.current(),
|
||||
fs.path.join('lib', 'main.dart'),
|
||||
BuildInfo.debug,
|
||||
false,
|
||||
);
|
||||
}));
|
||||
|
||||
test('Refuses to build a debug build for web', () => testbed.run(() async {
|
||||
final CommandRunner<void> runner = createTestCommandRunner(BuildCommand());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user