Unverified Commit 4d0f09a2 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Migrate Flutter Tester tests to Dart 2 (#21292)

parent c1beb15f
...@@ -6,11 +6,14 @@ import 'dart:async'; ...@@ -6,11 +6,14 @@ import 'dart:async';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.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/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.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/device.dart';
import 'package:flutter_tools/src/tester/flutter_tester.dart'; import 'package:flutter_tools/src/tester/flutter_tester.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../src/common.dart'; import '../src/common.dart';
...@@ -96,6 +99,8 @@ void main() { ...@@ -96,6 +99,8 @@ void main() {
String projectPath; String projectPath;
String mainPath; String mainPath;
MockArtifacts mockArtifacts;
MockKernelCompiler mockKernelCompiler;
MockProcessManager mockProcessManager; MockProcessManager mockProcessManager;
MockProcess mockProcess; MockProcess mockProcess;
...@@ -104,6 +109,8 @@ void main() { ...@@ -104,6 +109,8 @@ void main() {
FileSystem: () => fs, FileSystem: () => fs,
Cache: () => new Cache(rootOverride: fs.directory(flutterRoot)), Cache: () => new Cache(rootOverride: fs.directory(flutterRoot)),
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
KernelCompiler: () => mockKernelCompiler,
Artifacts: () => mockArtifacts,
}; };
setUp(() { setUp(() {
...@@ -121,13 +128,20 @@ void main() { ...@@ -121,13 +128,20 @@ void main() {
mockProcessManager = new MockProcessManager(); mockProcessManager = new MockProcessManager();
mockProcessManager.processFactory = mockProcessManager.processFactory =
(List<String> commands) => mockProcess; (List<String> 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 { testUsingContext('not debug', () async {
final LaunchResult result = await device.startApp(null, final LaunchResult result = await device.startApp(null,
mainPath: mainPath, mainPath: mainPath,
debuggingOptions: new DebuggingOptions.disabled( debuggingOptions: new DebuggingOptions.disabled(
const BuildInfo(BuildMode.release, null))); const BuildInfo(BuildMode.release, null, previewDart2: true)));
expect(result.started, isFalse); expect(result.started, isFalse);
}, overrides: startOverrides); }, overrides: startOverrides);
...@@ -137,7 +151,7 @@ void main() { ...@@ -137,7 +151,7 @@ void main() {
await device.startApp(null, await device.startApp(null,
mainPath: mainPath, mainPath: mainPath,
debuggingOptions: new DebuggingOptions.disabled( debuggingOptions: new DebuggingOptions.disabled(
const BuildInfo(BuildMode.debug, null))); const BuildInfo(BuildMode.debug, null, previewDart2: true)));
}, throwsToolExit()); }, throwsToolExit());
}, overrides: startOverrides); }, overrides: startOverrides);
...@@ -152,10 +166,26 @@ Hello! ...@@ -152,10 +166,26 @@ Hello!
.codeUnits .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, final LaunchResult result = await device.startApp(null,
mainPath: mainPath, mainPath: mainPath,
debuggingOptions: new DebuggingOptions.enabled( debuggingOptions: new DebuggingOptions.enabled(
const BuildInfo(BuildMode.debug, null))); const BuildInfo(BuildMode.debug, null, previewDart2: true)));
expect(result.started, isTrue); expect(result.started, isTrue);
expect(result.observatoryUri, observatoryUri); expect(result.observatoryUri, observatoryUri);
...@@ -164,3 +194,6 @@ Hello! ...@@ -164,3 +194,6 @@ Hello!
}); });
}); });
} }
class MockArtifacts extends Mock implements Artifacts {}
class MockKernelCompiler extends Mock implements KernelCompiler {}
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