From 4d0f09a2aa98f5e435f49fa3c8507e66e0835ae9 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 31 Aug 2018 15:39:34 -0700 Subject: [PATCH] Migrate Flutter Tester tests to Dart 2 (#21292) --- .../test/tester/flutter_tester_test.dart | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/test/tester/flutter_tester_test.dart b/packages/flutter_tools/test/tester/flutter_tester_test.dart index e85edabad96..fa7a7200947 100644 --- a/packages/flutter_tools/test/tester/flutter_tester_test.dart +++ b/packages/flutter_tools/test/tester/flutter_tester_test.dart @@ -6,11 +6,14 @@ import 'dart:async'; import 'package:file/file.dart'; import 'package:file/memory.dart'; +import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/cache.dart'; +import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/tester/flutter_tester.dart'; +import 'package:mockito/mockito.dart'; import 'package:process/process.dart'; import '../src/common.dart'; @@ -96,6 +99,8 @@ void main() { String projectPath; String mainPath; + MockArtifacts mockArtifacts; + MockKernelCompiler mockKernelCompiler; MockProcessManager mockProcessManager; MockProcess mockProcess; @@ -104,6 +109,8 @@ void main() { FileSystem: () => fs, Cache: () => new Cache(rootOverride: fs.directory(flutterRoot)), ProcessManager: () => mockProcessManager, + KernelCompiler: () => mockKernelCompiler, + Artifacts: () => mockArtifacts, }; setUp(() { @@ -121,13 +128,20 @@ void main() { mockProcessManager = new MockProcessManager(); mockProcessManager.processFactory = (List commands) => mockProcess; + + mockArtifacts = new MockArtifacts(); + final String artifactPath = fs.path.join(flutterRoot, 'artifact'); + fs.file(artifactPath).createSync(recursive: true); + when(mockArtifacts.getArtifactPath(any)).thenReturn(artifactPath); + + mockKernelCompiler = new MockKernelCompiler(); }); testUsingContext('not debug', () async { final LaunchResult result = await device.startApp(null, mainPath: mainPath, debuggingOptions: new DebuggingOptions.disabled( - const BuildInfo(BuildMode.release, null))); + const BuildInfo(BuildMode.release, null, previewDart2: true))); expect(result.started, isFalse); }, overrides: startOverrides); @@ -137,7 +151,7 @@ void main() { await device.startApp(null, mainPath: mainPath, debuggingOptions: new DebuggingOptions.disabled( - const BuildInfo(BuildMode.debug, null))); + const BuildInfo(BuildMode.debug, null, previewDart2: true))); }, throwsToolExit()); }, overrides: startOverrides); @@ -152,10 +166,26 @@ Hello! .codeUnits ])); + when(mockKernelCompiler.compile( + sdkRoot: anyNamed('sdkRoot'), + incrementalCompilerByteStorePath: anyNamed('incrementalCompilerByteStorePath'), + mainPath: anyNamed('mainPath'), + outputFilePath: anyNamed('outputFilePath'), + depFilePath: anyNamed('depFilePath'), + trackWidgetCreation: anyNamed('trackWidgetCreation'), + extraFrontEndOptions: anyNamed('extraFrontEndOptions'), + fileSystemRoots: anyNamed('fileSystemRoots'), + fileSystemScheme: anyNamed('fileSystemScheme'), + packagesPath: anyNamed('packagesPath'), + )).thenAnswer((_) async { + fs.file('$mainPath.dill').createSync(recursive: true); + return new CompilerOutput('$mainPath.dill', 0); + }); + final LaunchResult result = await device.startApp(null, mainPath: mainPath, debuggingOptions: new DebuggingOptions.enabled( - const BuildInfo(BuildMode.debug, null))); + const BuildInfo(BuildMode.debug, null, previewDart2: true))); expect(result.started, isTrue); expect(result.observatoryUri, observatoryUri); @@ -164,3 +194,6 @@ Hello! }); }); } + +class MockArtifacts extends Mock implements Artifacts {} +class MockKernelCompiler extends Mock implements KernelCompiler {}