Unverified Commit 5d61bff2 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] even more test fixes (#60156)

Fix tests broken under tester
parent 61b93d25
......@@ -4,6 +4,7 @@
import 'dart:async';
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/base/io.dart';
......@@ -25,6 +26,8 @@ void main() {
final List<Device> devices = <Device>[device1, device2, device3];
final DeviceManager deviceManager = TestDeviceManager(devices);
expect(await deviceManager.getDevices(), devices);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('getDeviceById', () async {
......@@ -43,6 +46,8 @@ void main() {
await expectDevice('Nexus 5', <Device>[device1]);
await expectDevice('0553790', <Device>[device1]);
await expectDevice('Nexus', <Device>[device1, device2]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('getAllConnectedDevices caches', () async {
......@@ -53,6 +58,8 @@ void main() {
final FakeDevice device2 = FakeDevice('Nexus 5X', '01abfc49119c410e');
deviceManager.resetDevices(<Device>[device2]);
expect(await deviceManager.getAllConnectedDevices(), <Device>[device1]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('refreshAllConnectedDevices does not cache', () async {
......@@ -63,6 +70,8 @@ void main() {
final FakeDevice device2 = FakeDevice('Nexus 5X', '01abfc49119c410e');
deviceManager.resetDevices(<Device>[device2]);
expect(await deviceManager.refreshAllConnectedDevices(), <Device>[device2]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
});
......@@ -83,6 +92,8 @@ void main() {
expect(pollingDeviceDiscovery.lastPollingTimeout, const Duration(seconds: 30));
await pollingDeviceDiscovery.stopPolling();
});
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
});
......@@ -117,6 +128,8 @@ void main() {
final List<Device> filtered = await deviceManager.findTargetDevices(FlutterProject.current());
expect(filtered.single, ephemeral);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('does not remove all non-ephemeral', () async {
......@@ -132,6 +145,8 @@ void main() {
nonEphemeralOne,
nonEphemeralTwo,
]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('Removes a single unsupported device', () async {
......@@ -143,6 +158,8 @@ void main() {
final List<Device> filtered = await deviceManager.findTargetDevices(FlutterProject.current());
expect(filtered, <Device>[]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('Removes web and fuchsia from --all', () async {
......@@ -156,6 +173,8 @@ void main() {
final List<Device> filtered = await deviceManager.findTargetDevices(FlutterProject.current());
expect(filtered, <Device>[]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('Removes unsupported devices from --all', () async {
......@@ -173,6 +192,8 @@ void main() {
nonEphemeralOne,
nonEphemeralTwo,
]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
testUsingContext('uses DeviceManager.isDeviceSupportedForProject instead of device.isSupportedForProject', () async {
......@@ -187,6 +208,8 @@ void main() {
expect(filtered, <Device>[
unsupported,
]);
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
});
});
group('ForwardedPort', () {
......
......@@ -17,6 +17,7 @@ import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/fuchsia/amber_ctl.dart';
import 'package:flutter_tools/src/fuchsia/application_package.dart';
......@@ -791,28 +792,36 @@ void main() {
});
testUsingContext('Correct flutter runner', () async {
expect(globals.artifacts.getArtifactPath(
final MockCache cache = MockCache();
final FileSystem fileSystem = MemoryFileSystem.test();
when(cache.getArtifactDirectory('flutter_runner')).thenReturn(fileSystem.directory('fuchsia'));
final CachedArtifacts artifacts = CachedArtifacts(
cache: cache,
fileSystem: fileSystem,
platform: FakePlatform(operatingSystem: 'linux'),
);
expect(artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.debug,
),
contains('flutter_jit_runner'),
);
expect(globals.artifacts.getArtifactPath(
expect(artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.profile,
),
contains('flutter_aot_runner'),
);
expect(globals.artifacts.getArtifactPath(
expect(artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.release,
),
contains('flutter_aot_product_runner'),
);
expect(globals.artifacts.getArtifactPath(
expect(artifacts.getArtifactPath(
Artifact.fuchsiaFlutterRunner,
platform: TargetPlatform.fuchsia_x64,
mode: BuildMode.jitRelease,
......@@ -1550,3 +1559,4 @@ class MockFuchsiaSdk extends Mock implements FuchsiaSdk {
}
class MockFuchsiaWorkflow extends Mock implements FuchsiaWorkflow {}
class MockCache extends Mock implements Cache {}
......@@ -4,6 +4,10 @@
import 'dart:async';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/io.dart';
......@@ -131,7 +135,7 @@ void main() {
group('hotRestart', () {
final MockResidentCompiler residentCompiler = MockResidentCompiler();
final MockDevFs mockDevFs = MockDevFs();
MockLocalEngineArtifacts mockArtifacts;
FileSystem fileSystem;
when(mockDevFs.update(
mainUri: anyNamed('mainUri'),
......@@ -155,11 +159,13 @@ void main() {
when(mockDevFs.lastCompiled).thenReturn(DateTime.now());
setUp(() {
mockArtifacts = MockLocalEngineArtifacts();
when(mockArtifacts.getArtifactPath(Artifact.flutterPatchedSdkPath)).thenReturn('some/path');
fileSystem = MemoryFileSystem.test();
});
testUsingContext('Does not hot restart when device does not support it', () async {
fileSystem.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
......@@ -174,11 +180,17 @@ void main() {
expect(result.isOk, false);
expect(result.message, 'hotRestart not supported');
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Does not hot restart when one of many devices does not support it', () async {
fileSystem.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
final MockDevice mockDevice = MockDevice();
final MockDevice mockHotDevice = MockDevice();
......@@ -196,8 +208,11 @@ void main() {
expect(result.isOk, false);
expect(result.message, 'hotRestart not supported');
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Does hot restarts when all devices support it', () async {
......@@ -294,11 +309,17 @@ void main() {
expect(result.isOk, true);
expect(result.message, isNot('hotRestart not supported'));
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('setup function fails', () async {
fileSystem.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
......@@ -310,11 +331,17 @@ void main() {
expect(result.isOk, false);
expect(result.message, 'setupHotRestart failed');
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: false),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('hot restart supported', () async {
fileSystem.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
// Setup mocks
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
......@@ -369,8 +396,11 @@ void main() {
expect(result.isOk, true);
expect(result.message, isNot('setupHotRestart failed'));
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
group('shutdown hook tests', () {
......@@ -383,6 +413,9 @@ void main() {
});
testUsingContext('shutdown hook called after signal', () async {
fileSystem.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
......@@ -393,11 +426,17 @@ void main() {
await HotRunner(devices).cleanupAfterSignal();
expect(shutdownTestingConfig.shutdownHookCalled, true);
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => shutdownTestingConfig,
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('shutdown hook called after app stop', () async {
fileSystem.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
......@@ -408,21 +447,28 @@ void main() {
await HotRunner(devices).preExit();
expect(shutdownTestingConfig.shutdownHookCalled, true);
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => shutdownTestingConfig,
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
});
});
group('hot attach', () {
MockLocalEngineArtifacts mockArtifacts;
FileSystem fileSystem;
setUp(() {
mockArtifacts = MockLocalEngineArtifacts();
fileSystem = MemoryFileSystem.test();
});
testUsingContext('Exits with code 2 when when HttpException is thrown '
'during VM service connection', () async {
fileSystem.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
final MockResidentCompiler residentCompiler = MockResidentCompiler();
final MockDevice mockDevice = MockDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
......@@ -444,8 +490,11 @@ void main() {
).attach();
expect(exitCode, 2);
}, overrides: <Type, Generator>{
Artifacts: () => mockArtifacts,
HotRunnerConfig: () => TestHotRunnerConfig(successfulSetup: true),
Artifacts: () => Artifacts.test(),
FileSystem: () => fileSystem,
Platform: () => FakePlatform(operatingSystem: 'linux'),
ProcessManager: () => FakeProcessManager.any(),
});
});
......@@ -482,8 +531,6 @@ void main() {
class MockDevFs extends Mock implements DevFS {}
class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
class MockDevice extends Mock implements Device {
MockDevice() {
when(isSupported()).thenReturn(true);
......
......@@ -92,6 +92,9 @@ void main() {
);
mockXcode = MockXcode();
when(mockXcode.isVersionSatisfactory).thenReturn(true);
fileSystem.file('foo/.packages')
..createSync(recursive: true)
..writeAsStringSync('\n');
});
testUsingContext('with buildable app', () async {
......
......@@ -37,6 +37,13 @@ class MockXcode extends Mock implements Xcode {}
class MockSimControl extends Mock implements SimControl {}
class MockPlistUtils extends Mock implements PlistParser {}
final Platform macosPlatform = FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{
'HOME': '/'
},
);
void main() {
FakePlatform osx;
FileSystemUtils fsUtils;
......@@ -458,12 +465,11 @@ void main() {
overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
FileSystem: () => fileSystem,
Platform: () => FakePlatform(
operatingSystem: 'macos',
environment: <String, String>{
'HOME': '/'
},
),
Platform: () => macosPlatform,
FileSystemUtils: () => FileSystemUtils(
fileSystem: fileSystem,
platform: macosPlatform,
)
});
testUsingContext('unified logging with app name', () async {
......
......@@ -43,7 +43,6 @@ void main() {
void podsIsInHomeDir() {
fileSystem.directory(fileSystem.path.join(
globals.fsUtils.homeDirPath,
'.cocoapods',
'repos',
'master',
......@@ -52,7 +51,6 @@ void main() {
String podsIsInCustomDir({String cocoapodsReposDir}) {
cocoapodsReposDir ??= fileSystem.path.join(
globals.fsUtils.homeDirPath,
'cache',
'cocoapods',
'repos',
......@@ -292,6 +290,9 @@ void main() {
group('Update xcconfig', () {
testUsingContext('includes Pod config in xcconfig files, if the user manually added Pod dependencies without using Flutter plugins', () async {
globals.fs.file(globals.fs.path.join('project', 'foo', '.packages'))
..createSync(recursive: true)
..writeAsStringSync('\n');
projectUnderTest.ios.podfile..createSync()..writeAsStringSync('Custom Podfile');
projectUnderTest.ios.podfileLock..createSync()..writeAsStringSync('Podfile.lock from user executed `pod install`');
projectUnderTest.packagesFile..createSync()..writeAsStringSync('');
......
......@@ -5,6 +5,7 @@
import 'dart:async';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:vm_service/vm_service.dart' as vm_service;
import 'package:file/memory.dart';
import 'package:file_testing/file_testing.dart';
......@@ -92,7 +93,7 @@ void main() {
setUp(() {
testbed = Testbed(setup: () {
globals.fs.file('.packages').writeAsStringSync('\n');
globals.fs.file(globalPackagesPath).writeAsStringSync('\n');
globals.fs.file(globals.fs.path.join('build', 'app.dill'))
..createSync(recursive: true)
..writeAsStringSync('ABC');
......@@ -844,6 +845,11 @@ void main() {
'data': <String, Object>{'A': 'B'}
});
expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{
FileSystemUtils: () => FileSystemUtils(
fileSystem: globals.fs,
platform: globals.platform,
)
}));
testUsingContext('ResidentRunner can take screenshot on debug device', () => testbed.run(() async {
......
......@@ -16,6 +16,7 @@ import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_runner/devfs_web.dart';
import 'package:flutter_tools/src/build_runner/resident_web_runner.dart';
import 'package:flutter_tools/src/compile.dart';
import 'package:flutter_tools/src/dart/package_map.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
......@@ -115,6 +116,9 @@ void main() {
});
testbed = Testbed(
setup: () {
globals.fs.file(globalPackagesPath)
..createSync(recursive: true)
..writeAsStringSync('\n');
residentWebRunner = DwdsWebRunnerFactory().createWebRunner(
mockFlutterDevice,
flutterProject: FlutterProject.current(),
......
......@@ -43,7 +43,9 @@ void main() {
MockHttpServer mockHttpServer;
setUpAll(() async {
packages = await loadPackageConfigUri(Uri.base.resolve('.packages'));
packages = PackageConfig(<Package>[
Package('flutter_tools', Uri.file('/flutter_tools/lib/').normalizePath())
]);
});
setUp(() {
......
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