mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] remove all mocks from plugins_test (#81485)
This commit is contained in:
parent
82830fa1a0
commit
8041a2e5d5
@ -22,7 +22,7 @@ import 'package:flutter_tools/src/plugins.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/fake.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
@ -33,14 +33,14 @@ import '../src/pubspec_schema.dart';
|
||||
void main() {
|
||||
group('plugins', () {
|
||||
FileSystem fs;
|
||||
MockFlutterProject flutterProject;
|
||||
MockFlutterManifest flutterManifest;
|
||||
MockIosProject iosProject;
|
||||
MockMacOSProject macosProject;
|
||||
MockAndroidProject androidProject;
|
||||
MockWebProject webProject;
|
||||
MockWindowsProject windowsProject;
|
||||
MockLinuxProject linuxProject;
|
||||
FakeFlutterProject flutterProject;
|
||||
FakeFlutterManifest flutterManifest;
|
||||
FakeIosProject iosProject;
|
||||
FakeMacOSProject macosProject;
|
||||
FakeAndroidProject androidProject;
|
||||
FakeWebProject webProject;
|
||||
FakeWindowsProject windowsProject;
|
||||
FakeLinuxProject linuxProject;
|
||||
FakeSystemClock systemClock;
|
||||
FlutterVersion flutterVersion;
|
||||
// A Windows-style filesystem. This is not populated by default, so tests
|
||||
@ -50,73 +50,69 @@ void main() {
|
||||
|
||||
// Adds basic properties to the flutterProject and its subprojects.
|
||||
void setUpProject(FileSystem fileSystem) {
|
||||
flutterProject = MockFlutterProject();
|
||||
flutterProject = FakeFlutterProject();
|
||||
flutterManifest = FakeFlutterManifest();
|
||||
|
||||
flutterManifest = MockFlutterManifest();
|
||||
when(flutterManifest.dependencies).thenReturn(<String>{});
|
||||
flutterProject
|
||||
..manifest = flutterManifest
|
||||
..directory = fileSystem.systemTempDirectory.childDirectory('app')
|
||||
..flutterPluginsFile = flutterProject.directory.childFile('.flutter-plugins')
|
||||
..flutterPluginsDependenciesFile = flutterProject.directory.childFile('.flutter-plugins-dependencies');
|
||||
|
||||
when(flutterProject.manifest).thenReturn(flutterManifest);
|
||||
|
||||
when(flutterProject.directory).thenReturn(fileSystem.systemTempDirectory.childDirectory('app'));
|
||||
// TODO(franciscojma): Remove logic for .flutter-plugins once it's deprecated.
|
||||
when(flutterProject.flutterPluginsFile).thenReturn(flutterProject.directory.childFile('.flutter-plugins'));
|
||||
when(flutterProject.flutterPluginsDependenciesFile).thenReturn(flutterProject.directory.childFile('.flutter-plugins-dependencies'));
|
||||
|
||||
iosProject = MockIosProject();
|
||||
when(flutterProject.ios).thenReturn(iosProject);
|
||||
iosProject = FakeIosProject();
|
||||
flutterProject.ios = iosProject;
|
||||
final Directory iosDirectory = flutterProject.directory.childDirectory('ios');
|
||||
when(iosProject.pluginRegistrantHost).thenReturn(flutterProject.directory.childDirectory('Runner'));
|
||||
when(iosProject.podfile).thenReturn(iosDirectory.childFile('Podfile'));
|
||||
when(iosProject.podManifestLock).thenReturn(iosDirectory.childFile('Podfile.lock'));
|
||||
when(iosProject.pluginConfigKey).thenReturn('ios');
|
||||
when(iosProject.existsSync()).thenReturn(false);
|
||||
iosProject
|
||||
..pluginRegistrantHost = flutterProject.directory.childDirectory('Runner')
|
||||
..podfile = iosDirectory.childFile('Podfile')
|
||||
..podManifestLock = iosDirectory.childFile('Podfile.lock')
|
||||
..testExists = false;
|
||||
|
||||
macosProject = MockMacOSProject();
|
||||
when(flutterProject.macos).thenReturn(macosProject);
|
||||
macosProject = FakeMacOSProject();
|
||||
flutterProject.macos = macosProject;
|
||||
final Directory macosDirectory = flutterProject.directory.childDirectory('macos');
|
||||
when(macosProject.podfile).thenReturn(macosDirectory.childFile('Podfile'));
|
||||
when(macosProject.podManifestLock).thenReturn(macosDirectory.childFile('Podfile.lock'));
|
||||
final Directory macosManagedDirectory = macosDirectory.childDirectory('Flutter');
|
||||
when(macosProject.managedDirectory).thenReturn(macosManagedDirectory);
|
||||
when(macosProject.pluginConfigKey).thenReturn('macos');
|
||||
when(macosProject.existsSync()).thenReturn(false);
|
||||
macosProject
|
||||
..podfile = macosDirectory.childFile('Podfile')
|
||||
..podManifestLock = macosDirectory.childFile('Podfile.lock')
|
||||
..managedDirectory = macosManagedDirectory
|
||||
..exists = false;
|
||||
|
||||
androidProject = MockAndroidProject();
|
||||
when(flutterProject.android).thenReturn(androidProject);
|
||||
androidProject = FakeAndroidProject();
|
||||
flutterProject.android = androidProject;
|
||||
final Directory androidDirectory = flutterProject.directory.childDirectory('android');
|
||||
when(androidProject.pluginRegistrantHost).thenReturn(androidDirectory.childDirectory('app'));
|
||||
when(androidProject.hostAppGradleRoot).thenReturn(androidDirectory);
|
||||
when(androidProject.pluginConfigKey).thenReturn('android');
|
||||
when(androidProject.existsSync()).thenReturn(false);
|
||||
androidProject
|
||||
..pluginRegistrantHost = androidDirectory.childDirectory('app')
|
||||
..hostAppGradleRoot = androidDirectory
|
||||
..exists = false;
|
||||
|
||||
webProject = MockWebProject();
|
||||
when(flutterProject.web).thenReturn(webProject);
|
||||
when(webProject.libDirectory).thenReturn(flutterProject.directory.childDirectory('lib'));
|
||||
when(webProject.existsSync()).thenReturn(true);
|
||||
when(webProject.pluginConfigKey).thenReturn('web');
|
||||
when(webProject.existsSync()).thenReturn(false);
|
||||
webProject = FakeWebProject();
|
||||
flutterProject.web = webProject;
|
||||
webProject
|
||||
..libDirectory = flutterProject.directory.childDirectory('lib')
|
||||
..exists = false;
|
||||
|
||||
windowsProject = MockWindowsProject();
|
||||
when(flutterProject.windows).thenReturn(windowsProject);
|
||||
when(windowsProject.pluginConfigKey).thenReturn('windows');
|
||||
windowsProject = FakeWindowsProject();
|
||||
flutterProject.windows = windowsProject;
|
||||
final Directory windowsManagedDirectory = flutterProject.directory.childDirectory('windows').childDirectory('flutter');
|
||||
when(windowsProject.managedDirectory).thenReturn(windowsManagedDirectory);
|
||||
when(windowsProject.cmakeFile).thenReturn(windowsManagedDirectory.parent.childFile('CMakeLists.txt'));
|
||||
when(windowsProject.generatedPluginCmakeFile).thenReturn(windowsManagedDirectory.childFile('generated_plugins.mk'));
|
||||
when(windowsProject.pluginSymlinkDirectory).thenReturn(windowsManagedDirectory.childDirectory('ephemeral').childDirectory('.plugin_symlinks'));
|
||||
when(windowsProject.existsSync()).thenReturn(false);
|
||||
windowsProject
|
||||
..managedDirectory = windowsManagedDirectory
|
||||
..cmakeFile = windowsManagedDirectory.parent.childFile('CMakeLists.txt')
|
||||
..generatedPluginCmakeFile = windowsManagedDirectory.childFile('generated_plugins.mk')
|
||||
..pluginSymlinkDirectory = windowsManagedDirectory.childDirectory('ephemeral').childDirectory('.plugin_symlinks')
|
||||
..exists = false;
|
||||
|
||||
linuxProject = MockLinuxProject();
|
||||
when(flutterProject.linux).thenReturn(linuxProject);
|
||||
when(linuxProject.pluginConfigKey).thenReturn('linux');
|
||||
linuxProject = FakeLinuxProject();
|
||||
flutterProject.linux = linuxProject;
|
||||
final Directory linuxManagedDirectory = flutterProject.directory.childDirectory('linux').childDirectory('flutter');
|
||||
final Directory linuxEphemeralDirectory = linuxManagedDirectory.childDirectory('ephemeral');
|
||||
when(linuxProject.managedDirectory).thenReturn(linuxManagedDirectory);
|
||||
when(linuxProject.ephemeralDirectory).thenReturn(linuxEphemeralDirectory);
|
||||
when(linuxProject.pluginSymlinkDirectory).thenReturn(linuxEphemeralDirectory.childDirectory('.plugin_symlinks'));
|
||||
when(linuxProject.cmakeFile).thenReturn(linuxManagedDirectory.parent.childFile('CMakeLists.txt'));
|
||||
when(linuxProject.generatedPluginCmakeFile).thenReturn(linuxManagedDirectory.childFile('generated_plugins.mk'));
|
||||
when(linuxProject.existsSync()).thenReturn(false);
|
||||
linuxProject
|
||||
..managedDirectory = linuxManagedDirectory
|
||||
..ephemeralDirectory = linuxEphemeralDirectory
|
||||
..pluginSymlinkDirectory = linuxEphemeralDirectory.childDirectory('.plugin_symlinks')
|
||||
..cmakeFile = linuxManagedDirectory.parent.childFile('CMakeLists.txt')
|
||||
..generatedPluginCmakeFile = linuxManagedDirectory.childFile('generated_plugins.mk')
|
||||
..exists = false;
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
@ -404,7 +400,7 @@ dependencies:
|
||||
'/local_plugins/plugin_b'
|
||||
]);
|
||||
|
||||
when(iosProject.existsSync()).thenReturn(true);
|
||||
iosProject.testExists = true;
|
||||
|
||||
await refreshPluginsList(flutterProject);
|
||||
|
||||
@ -426,7 +422,7 @@ dependencies:
|
||||
final Directory pluginA = createPluginWithDependencies(name: 'plugin-a', dependencies: const <String>['plugin-b', 'plugin-c', 'random-package']);
|
||||
final Directory pluginB = createPluginWithDependencies(name: 'plugin-b', dependencies: const <String>['plugin-c']);
|
||||
final Directory pluginC = createPluginWithDependencies(name: 'plugin-c', dependencies: const <String>[]);
|
||||
when(iosProject.existsSync()).thenReturn(true);
|
||||
iosProject.testExists = true;
|
||||
|
||||
final DateTime dateCreated = DateTime(1970, 1, 1);
|
||||
systemClock.currentTime = dateCreated;
|
||||
@ -522,8 +518,8 @@ dependencies:
|
||||
simulatePodInstallRun(iosProject);
|
||||
simulatePodInstallRun(macosProject);
|
||||
createFakePlugin(fs);
|
||||
when(iosProject.existsSync()).thenReturn(true);
|
||||
when(macosProject.existsSync()).thenReturn(true);
|
||||
iosProject.testExists = true;
|
||||
macosProject.exists = true;
|
||||
|
||||
await refreshPluginsList(flutterProject, iosPlatform: true, macOSPlatform: true);
|
||||
expect(iosProject.podManifestLock.existsSync(), false);
|
||||
@ -537,8 +533,8 @@ dependencies:
|
||||
|
||||
testUsingContext('No changes to the plugin list does not invalidate the Cocoapod lockfiles', () async {
|
||||
createFakePlugin(fs);
|
||||
when(iosProject.existsSync()).thenReturn(true);
|
||||
when(macosProject.existsSync()).thenReturn(true);
|
||||
iosProject.testExists = true;
|
||||
macosProject.exists = true;
|
||||
|
||||
// First call will create the .flutter-plugins-dependencies and the legacy .flutter-plugins file.
|
||||
// Since there was no plugins list, the lock files will be invalidated.
|
||||
@ -560,16 +556,14 @@ dependencies:
|
||||
});
|
||||
|
||||
group('injectPlugins', () {
|
||||
MockXcodeProjectInterpreter xcodeProjectInterpreter;
|
||||
FakeXcodeProjectInterpreter xcodeProjectInterpreter;
|
||||
|
||||
setUp(() {
|
||||
xcodeProjectInterpreter = MockXcodeProjectInterpreter();
|
||||
when(xcodeProjectInterpreter.isInstalled).thenReturn(false);
|
||||
xcodeProjectInterpreter = FakeXcodeProjectInterpreter();
|
||||
});
|
||||
|
||||
testUsingContext('Registrant uses old embedding in app project', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||
|
||||
await injectPlugins(flutterProject, androidPlatform: true);
|
||||
|
||||
@ -587,8 +581,7 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Registrant uses new embedding if app uses new embedding', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
await injectPlugins(flutterProject, androidPlatform: true);
|
||||
|
||||
@ -606,8 +599,7 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Registrant uses shim for plugins using old embedding if app uses new embedding', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
createNewJavaPlugin1();
|
||||
createNewKotlinPlugin2();
|
||||
@ -635,8 +627,7 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('exits the tool if an app uses the v1 embedding and a plugin only supports the v2 embedding', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||
|
||||
createNewJavaPlugin1();
|
||||
|
||||
@ -657,8 +648,7 @@ dependencies:
|
||||
|
||||
// Issue: https://github.com/flutter/flutter/issues/47803
|
||||
testUsingContext('exits the tool if a plugin sets an invalid android package in pubspec.yaml', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||
|
||||
final Directory pluginDir = createPluginWithInvalidAndroidPackage();
|
||||
|
||||
@ -682,8 +672,7 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('old embedding app uses a plugin that supports v1 and v2 embedding works', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v1);
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v1;
|
||||
|
||||
createDualSupportJavaPlugin4();
|
||||
|
||||
@ -705,8 +694,7 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('new embedding app uses a plugin that supports v1 and v2 embedding', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
createDualSupportJavaPlugin4();
|
||||
|
||||
@ -728,8 +716,8 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Modules use new embedding', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
flutterProject.isModule = true;
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
await injectPlugins(flutterProject, androidPlatform: true);
|
||||
|
||||
@ -747,8 +735,8 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Module using old plugin shows warning', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
flutterProject.isModule = true;
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
createOldJavaPlugin('plugin3');
|
||||
|
||||
@ -767,8 +755,8 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Module using new plugin shows no warnings', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
flutterProject.isModule = true;
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
createNewJavaPlugin1();
|
||||
|
||||
@ -788,8 +776,8 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Module using plugin with v1 and v2 support shows no warning', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
flutterProject.isModule = true;
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
createDualSupportJavaPlugin4();
|
||||
|
||||
@ -809,8 +797,8 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Module using multiple old plugins all show warnings', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
flutterProject.isModule = true;
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
createOldJavaPlugin('plugin3');
|
||||
createOldJavaPlugin('plugin4');
|
||||
@ -833,8 +821,8 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Module using multiple old and new plugins should be wrapped with try catch', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
when(androidProject.getEmbeddingVersion()).thenReturn(AndroidEmbeddingVersion.v2);
|
||||
flutterProject.isModule = true;
|
||||
androidProject.embeddingVersion = AndroidEmbeddingVersion.v2;
|
||||
|
||||
createOldJavaPlugin('abcplugin1');
|
||||
createNewJavaPlugin1();
|
||||
@ -859,20 +847,17 @@ dependencies:
|
||||
});
|
||||
|
||||
testUsingContext('Does not throw when AndroidManifest.xml is not found', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
|
||||
final File manifest = fs.file('AndroidManifest.xml');
|
||||
when(androidProject.appManifestFile).thenReturn(manifest);
|
||||
androidProject.appManifestFile = manifest;
|
||||
|
||||
await injectPlugins(flutterProject, androidPlatform: true);
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext("Registrant for web doesn't escape slashes in imports", () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
flutterProject.isModule = true;
|
||||
final Directory webPluginWithNestedFile =
|
||||
fs.systemTempDirectory.createTempSync('flutter_web_plugin_with_nested.');
|
||||
webPluginWithNestedFile.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
@ -909,7 +894,7 @@ web_plugin_with_nested:${webPluginWithNestedFile.childDirectory('lib').uri.toStr
|
||||
});
|
||||
|
||||
testUsingContext('Injecting creates generated macos registrant, but does not include Dart-only plugins', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
flutterProject.isModule = true;
|
||||
// Create a plugin without a pluginClass.
|
||||
final Directory pluginDirectory = createFakePlugin(fs);
|
||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
@ -932,7 +917,7 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on macOS', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
flutterProject.isModule = true;
|
||||
// Create a plugin without a pluginClass.
|
||||
final Directory pluginDirectory = createFakePlugin(fs);
|
||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
@ -957,7 +942,7 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Invalid yaml does not crash plugin lookup.', () async {
|
||||
when(flutterProject.isModule).thenReturn(true);
|
||||
flutterProject.isModule = true;
|
||||
// Create a plugin without a pluginClass.
|
||||
final Directory pluginDirectory = createFakePlugin(fs);
|
||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync(r'''
|
||||
@ -975,7 +960,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Injecting creates generated Linux registrant', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
createFakePlugin(fs);
|
||||
|
||||
await injectPlugins(flutterProject, linuxPlatform: true);
|
||||
@ -992,7 +976,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Injecting creates generated Linux registrant, but does not include Dart-only plugins', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
// Create a plugin without a pluginClass.
|
||||
final Directory pluginDirectory = createFakePlugin(fs);
|
||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
@ -1016,7 +999,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Linux', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
// Create a plugin without a pluginClass.
|
||||
final Directory pluginDirectory = createFakePlugin(fs);
|
||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
@ -1041,7 +1023,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Injecting creates generated Linux plugin Cmake file', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
createFakePlugin(fs);
|
||||
|
||||
await injectPlugins(flutterProject, linuxPlatform: true);
|
||||
@ -1060,7 +1041,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Generated Linux plugin files sorts by plugin name', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
createFakePlugins(fs, <String>[
|
||||
'plugin_d',
|
||||
'plugin_a',
|
||||
@ -1084,7 +1064,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Injecting creates generated Windows registrant', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
createFakePlugin(fs);
|
||||
|
||||
await injectPlugins(flutterProject, windowsPlatform: true);
|
||||
@ -1101,7 +1080,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Injecting creates generated Windows registrant, but does not include Dart-only plugins', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
// Create a plugin without a pluginClass.
|
||||
final Directory pluginDirectory = createFakePlugin(fs);
|
||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
@ -1124,7 +1102,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('pluginClass: none doesn\'t trigger registrant entry on Windows', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
// Create a plugin without a pluginClass.
|
||||
final Directory pluginDirectory = createFakePlugin(fs);
|
||||
pluginDirectory.childFile('pubspec.yaml').writeAsStringSync('''
|
||||
@ -1149,7 +1126,6 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Generated Windows plugin files sorts by plugin name', () async {
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
createFakePlugins(fs, <String>[
|
||||
'plugin_d',
|
||||
'plugin_a',
|
||||
@ -1177,8 +1153,6 @@ flutter:
|
||||
setUpProject(fsWindows);
|
||||
createFakePlugin(fsWindows);
|
||||
|
||||
when(flutterProject.isModule).thenReturn(false);
|
||||
|
||||
await injectPlugins(flutterProject, linuxPlatform: true, windowsPlatform: true);
|
||||
|
||||
for (final CmakeBasedProject project in <CmakeBasedProject>[linuxProject, windowsProject]) {
|
||||
@ -1202,7 +1176,7 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Symlinks are created for Linux plugins', () async {
|
||||
when(linuxProject.existsSync()).thenReturn(true);
|
||||
linuxProject.exists = true;
|
||||
createFakePlugin(fs);
|
||||
// refreshPluginsList should call createPluginSymlinks.
|
||||
await refreshPluginsList(flutterProject);
|
||||
@ -1215,7 +1189,7 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Symlinks are created for Windows plugins', () async {
|
||||
when(windowsProject.existsSync()).thenReturn(true);
|
||||
windowsProject.exists = true;
|
||||
createFakePlugin(fs);
|
||||
// refreshPluginsList should call createPluginSymlinks.
|
||||
await refreshPluginsList(flutterProject);
|
||||
@ -1228,8 +1202,8 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Existing symlinks are removed when no longer in use with force', () {
|
||||
when(linuxProject.existsSync()).thenReturn(true);
|
||||
when(windowsProject.existsSync()).thenReturn(true);
|
||||
linuxProject.exists = true;
|
||||
windowsProject.exists = true;
|
||||
|
||||
final List<File> dummyFiles = <File>[
|
||||
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
||||
@ -1251,8 +1225,8 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('Existing symlinks are removed automatically on refresh when no longer in use', () async {
|
||||
when(linuxProject.existsSync()).thenReturn(true);
|
||||
when(windowsProject.existsSync()).thenReturn(true);
|
||||
linuxProject.exists = true;
|
||||
windowsProject.exists = true;
|
||||
|
||||
final List<File> dummyFiles = <File>[
|
||||
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
||||
@ -1276,8 +1250,8 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('createPluginSymlinks is a no-op without force when up to date', () {
|
||||
when(linuxProject.existsSync()).thenReturn(true);
|
||||
when(windowsProject.existsSync()).thenReturn(true);
|
||||
linuxProject.exists = true;
|
||||
windowsProject.exists = true;
|
||||
|
||||
final List<File> dummyFiles = <File>[
|
||||
flutterProject.linux.pluginSymlinkDirectory.childFile('dummy'),
|
||||
@ -1300,8 +1274,8 @@ flutter:
|
||||
});
|
||||
|
||||
testUsingContext('createPluginSymlinks repairs missing links', () async {
|
||||
when(linuxProject.existsSync()).thenReturn(true);
|
||||
when(windowsProject.existsSync()).thenReturn(true);
|
||||
linuxProject.exists = true;
|
||||
windowsProject.exists = true;
|
||||
createFakePlugin(fs);
|
||||
await refreshPluginsList(flutterProject);
|
||||
|
||||
@ -1325,9 +1299,9 @@ flutter:
|
||||
});
|
||||
|
||||
group('pubspec', () {
|
||||
|
||||
Directory projectDir;
|
||||
Directory tempDir;
|
||||
|
||||
setUp(() {
|
||||
tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_plugin_test.');
|
||||
projectDir = tempDir.childDirectory('flutter_project');
|
||||
@ -1419,15 +1393,182 @@ flutter:
|
||||
});
|
||||
}
|
||||
|
||||
class MockAndroidProject extends Mock implements AndroidProject {}
|
||||
class MockFlutterManifest extends Mock implements FlutterManifest {}
|
||||
class MockFlutterProject extends Mock implements FlutterProject {}
|
||||
class MockIosProject extends Mock implements IosProject {}
|
||||
class MockMacOSProject extends Mock implements MacOSProject {}
|
||||
class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
|
||||
class MockWebProject extends Mock implements WebProject {}
|
||||
class MockWindowsProject extends Mock implements WindowsProject {}
|
||||
class MockLinuxProject extends Mock implements LinuxProject {}
|
||||
class FakeFlutterManifest extends Fake implements FlutterManifest {
|
||||
@override
|
||||
Set<String> get dependencies => <String>{};
|
||||
}
|
||||
|
||||
class FakeXcodeProjectInterpreter extends Fake implements XcodeProjectInterpreter {
|
||||
@override
|
||||
bool get isInstalled => false;
|
||||
}
|
||||
|
||||
class FakeFlutterProject extends Fake implements FlutterProject {
|
||||
@override
|
||||
bool isModule = false;
|
||||
|
||||
@override
|
||||
FlutterManifest manifest;
|
||||
|
||||
@override
|
||||
Directory directory;
|
||||
|
||||
@override
|
||||
File flutterPluginsFile;
|
||||
|
||||
@override
|
||||
File flutterPluginsDependenciesFile;
|
||||
|
||||
@override
|
||||
IosProject ios;
|
||||
|
||||
@override
|
||||
AndroidProject android;
|
||||
|
||||
@override
|
||||
WebProject web;
|
||||
|
||||
@override
|
||||
MacOSProject macos;
|
||||
|
||||
@override
|
||||
LinuxProject linux;
|
||||
|
||||
@override
|
||||
WindowsProject windows;
|
||||
|
||||
@override
|
||||
WindowsUwpProject windowsUwp;
|
||||
}
|
||||
|
||||
class FakeMacOSProject extends Fake implements MacOSProject {
|
||||
@override
|
||||
String pluginConfigKey = 'macos';
|
||||
|
||||
bool exists = false;
|
||||
|
||||
@override
|
||||
File podfile;
|
||||
|
||||
@override
|
||||
File podManifestLock;
|
||||
|
||||
@override
|
||||
Directory managedDirectory;
|
||||
|
||||
@override
|
||||
bool existsSync() => exists;
|
||||
}
|
||||
|
||||
class FakeIosProject extends Fake implements IosProject {
|
||||
@override
|
||||
String pluginConfigKey = 'ios';
|
||||
|
||||
bool testExists = false;
|
||||
|
||||
@override
|
||||
bool existsSync() => testExists;
|
||||
|
||||
@override
|
||||
bool get exists => testExists;
|
||||
|
||||
@override
|
||||
Directory pluginRegistrantHost;
|
||||
|
||||
@override
|
||||
File podfile;
|
||||
|
||||
@override
|
||||
File podManifestLock;
|
||||
}
|
||||
|
||||
class FakeAndroidProject extends Fake implements AndroidProject {
|
||||
@override
|
||||
String pluginConfigKey = 'android';
|
||||
|
||||
bool exists = false;
|
||||
|
||||
@override
|
||||
Directory pluginRegistrantHost;
|
||||
|
||||
@override
|
||||
Directory hostAppGradleRoot;
|
||||
|
||||
@override
|
||||
File appManifestFile;
|
||||
|
||||
AndroidEmbeddingVersion embeddingVersion;
|
||||
|
||||
@override
|
||||
bool existsSync() => exists;
|
||||
|
||||
@override
|
||||
AndroidEmbeddingVersion getEmbeddingVersion() {
|
||||
return embeddingVersion;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeWebProject extends Fake implements WebProject {
|
||||
@override
|
||||
String pluginConfigKey = 'web';
|
||||
|
||||
@override
|
||||
Directory libDirectory;
|
||||
|
||||
bool exists = false;
|
||||
|
||||
@override
|
||||
bool existsSync() => exists;
|
||||
}
|
||||
|
||||
class FakeWindowsProject extends Fake implements WindowsProject {
|
||||
@override
|
||||
String pluginConfigKey = 'windows';
|
||||
|
||||
@override
|
||||
Directory managedDirectory;
|
||||
|
||||
@override
|
||||
Directory ephemeralDirectory;
|
||||
|
||||
@override
|
||||
Directory pluginSymlinkDirectory;
|
||||
|
||||
@override
|
||||
File cmakeFile;
|
||||
|
||||
@override
|
||||
File generatedPluginCmakeFile;
|
||||
bool exists = false;
|
||||
|
||||
@override
|
||||
bool existsSync() => exists;
|
||||
}
|
||||
|
||||
class FakeLinuxProject extends Fake implements LinuxProject {
|
||||
@override
|
||||
String pluginConfigKey = 'linux';
|
||||
|
||||
@override
|
||||
Directory managedDirectory;
|
||||
|
||||
@override
|
||||
Directory ephemeralDirectory;
|
||||
|
||||
@override
|
||||
Directory pluginSymlinkDirectory;
|
||||
|
||||
@override
|
||||
File cmakeFile;
|
||||
|
||||
@override
|
||||
File generatedPluginCmakeFile;
|
||||
bool exists = false;
|
||||
|
||||
@override
|
||||
bool existsSync() => exists;
|
||||
|
||||
}
|
||||
|
||||
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
||||
FakeOperatingSystemUtils(this.name);
|
||||
|
Loading…
Reference in New Issue
Block a user