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