ensure we can disable --track-widget-creation in debug mode (#43016)

This commit is contained in:
Jonah Williams
2019-10-18 12:40:50 -07:00
committed by GitHub
parent 5db53aee5e
commit e67f9a3f6c
4 changed files with 66 additions and 1 deletions

View File

@@ -6,6 +6,8 @@ import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/build_system/targets/dart.dart';
import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/build_bundle.dart';
@@ -202,6 +204,37 @@ void main() {
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
});
testUsingContext('passes track widget creation through', () async {
fs.file('lib/main.dart').createSync(recursive: true);
fs.file('pubspec.yaml').createSync();
fs.file('.packages').createSync();
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand());
when(buildSystem.build(any, any)).thenAnswer((Invocation invocation) async {
final Environment environment = invocation.positionalArguments[1];
expect(environment.defines, <String, String>{
kTargetFile: fs.path.join('lib', 'main.dart'),
kBuildMode: 'debug',
kTargetPlatform: 'android-arm',
kTrackWidgetCreation: 'true',
});
return BuildResult(success: true);
});
await runner.run(<String>[
'bundle',
'--no-pub',
'--debug',
'--target-platform=android-arm',
'--track-widget-creation'
]);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem(),
BuildSystem: () => MockBuildSystem(),
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
});
}
class MockBundleBuilder extends Mock implements BundleBuilder {}
class MockBuildSystem extends Mock implements BuildSystem {}

View File

@@ -168,6 +168,30 @@ flutter_tools:lib/''');
KernelCompilerFactory: () => MockKernelCompilerFactory(),
}));
test('kernel_snapshot can disable track-widget-creation on debug builds', () => testbed.run(() async {
final MockKernelCompiler mockKernelCompiler = MockKernelCompiler();
when(kernelCompilerFactory.create(any)).thenAnswer((Invocation _) async {
return mockKernelCompiler;
});
when(mockKernelCompiler.compile(
sdkRoot: anyNamed('sdkRoot'),
aot: anyNamed('aot'),
buildMode: anyNamed('buildMode'),
trackWidgetCreation: false,
targetModel: anyNamed('targetModel'),
outputFilePath: anyNamed('outputFilePath'),
depFilePath: anyNamed('depFilePath'),
packagesPath: anyNamed('packagesPath'),
mainPath: anyNamed('mainPath'),
)).thenAnswer((Invocation _) async {
return const CompilerOutput('example', 0, <Uri>[]);
});
await const KernelSnapshot().build(androidEnvironment..defines[kTrackWidgetCreation] = 'false');
}, overrides: <Type, Generator>{
KernelCompilerFactory: () => MockKernelCompilerFactory(),
}));
test('kernel_snapshot does use track widget creation on debug builds', () => testbed.run(() async {
final MockKernelCompiler mockKernelCompiler = MockKernelCompiler();
when(kernelCompilerFactory.create(any)).thenAnswer((Invocation _) async {