Unverified Commit a1c185f3 authored by Collin Jackson's avatar Collin Jackson Committed by GitHub

Fix plugin template app's tests (#39080)

* Fix plugin template

* Add test of plugin template working
parent 19cdb21c
......@@ -23,8 +23,8 @@ TaskFunction combine(List<TaskFunction> tasks) {
};
}
/// Defines task that creates new Flutter project, adds a plugin, and then
/// builds the specified [buildTarget].
/// Defines task that creates new Flutter project, adds a local and remote
/// plugin, and then builds the specified [buildTarget].
class PluginTest {
PluginTest(this.buildTarget, this.options);
......@@ -32,19 +32,32 @@ class PluginTest {
final List<String> options;
Future<TaskResult> call() async {
section('Create Flutter project');
final Directory tempDir = Directory.systemTemp.createTempSync('flutter_devicelab_plugin_test.');
final Directory tempDir =
Directory.systemTemp.createTempSync('flutter_devicelab_plugin_test.');
try {
final FlutterProject project = await FlutterProject.create(tempDir, options);
section('Create plugin');
final _FlutterProject plugin = await _FlutterProject.create(
tempDir, options,
name: 'plugintest', template: 'plugin');
section('Test plugin');
await plugin.test();
section('Create Flutter app');
final _FlutterProject app = await _FlutterProject.create(tempDir, options,
name: 'plugintestapp', template: 'app');
try {
if (buildTarget == 'ios')
await prepareProvisioningCertificates(project.rootPath);
section('Add plugin');
await project.addPlugin('path_provider');
section('Build');
await project.build(buildTarget);
await prepareProvisioningCertificates(app.rootPath);
section('Add plugins');
await app.addPlugin('plugintest',
pluginPath: path.join('..', 'plugintest'));
await app.addPlugin('path_provider');
section('Build app');
await app.build(buildTarget);
section('Test app');
await app.test();
} finally {
await project.delete();
await plugin.delete();
await app.delete();
}
return TaskResult.success(null);
} catch (e) {
......@@ -55,34 +68,50 @@ class PluginTest {
}
}
class FlutterProject {
FlutterProject(this.parent, this.name);
class _FlutterProject {
_FlutterProject(this.parent, this.name);
final Directory parent;
final String name;
static Future<FlutterProject> create(Directory directory, List<String> options) async {
await inDirectory(directory, () async {
await flutter(
'create',
options: <String>['--template=app', '--org', 'io.flutter.devicelab', ...options, 'plugintest'],
);
});
return FlutterProject(directory, 'plugintest');
}
String get rootPath => path.join(parent.path, name);
Future<void> addPlugin(String plugin) async {
Future<void> addPlugin(String plugin, {String pluginPath}) async {
final File pubspec = File(path.join(rootPath, 'pubspec.yaml'));
String content = await pubspec.readAsString();
final String dependency =
pluginPath != null ? '$plugin:\n path: $pluginPath' : '$plugin:';
content = content.replaceFirst(
'\ndependencies:\n',
'\ndependencies:\n $plugin:\n',
'\ndependencies:\n $dependency\n',
);
await pubspec.writeAsString(content, flush: true);
}
Future<void> test() async {
await inDirectory(Directory(rootPath), () async {
await flutter('test');
});
}
static Future<_FlutterProject> create(
Directory directory, List<String> options,
{String name, String template}) async {
await inDirectory(directory, () async {
await flutter(
'create',
options: <String>[
'--template=$template',
'--org',
'io.flutter.devicelab',
...options,
name
],
);
});
return _FlutterProject(directory, name);
}
Future<void> build(String target) async {
await inDirectory(Directory(rootPath), () async {
await flutter('build', options: <String>[target]);
......@@ -93,11 +122,11 @@ class FlutterProject {
if (Platform.isWindows) {
// A running Gradle daemon might prevent us from deleting the project
// folder on Windows.
await exec(
path.absolute(path.join(rootPath, 'android', 'gradlew.bat')),
<String>['--stop'],
canFail: true,
);
final String wrapperPath =
path.absolute(path.join(rootPath, 'android', 'gradlew.bat'));
if (File(wrapperPath).existsSync()) {
await exec(wrapperPath, <String>['--stop'], canFail: true);
}
// TODO(ianh): Investigating if flakiness is timing dependent.
await Future<void>.delayed(const Duration(seconds: 10));
}
......
......@@ -5,6 +5,8 @@ import 'package:{{projectName}}/{{projectName}}.dart';
void main() {
const MethodChannel channel = MethodChannel('{{projectName}}');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
......
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