From 3346c5c736cc8b376fa372f2b99dee55da22b29c Mon Sep 17 00:00:00 2001 From: Phil Quitslund Date: Thu, 14 Dec 2017 08:51:33 -0800 Subject: [PATCH] Update plugin test template. (#13516) * Update plugin test template. * Add flutter test run verification. * Tweak and test runs for package projects. --- .../create/test/widget_test.dart.tmpl | 18 +++++++ .../test/commands/create_test.dart | 49 +++++++++++++------ 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/packages/flutter_tools/templates/create/test/widget_test.dart.tmpl b/packages/flutter_tools/templates/create/test/widget_test.dart.tmpl index a5c2c03403e..1d7bae88b9b 100644 --- a/packages/flutter_tools/templates/create/test/widget_test.dart.tmpl +++ b/packages/flutter_tools/templates/create/test/widget_test.dart.tmpl @@ -9,6 +9,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:{{projectName}}/main.dart'; +{{^withPluginHook}} void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. @@ -27,3 +28,20 @@ void main() { expect(find.text('1'), findsOneWidget); }); } +{{/withPluginHook}} +{{#withPluginHook}} +void main() { + testWidgets('Verify Platform version', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(new MyApp()); + + // Verify that platform version is retrieved. + expect( + find.byWidgetPredicate( + (Widget widget) => + widget is Text && widget.data.startsWith('Running on:'), + ), + findsOneWidget); + }); +} +{{/withPluginHook}} diff --git a/packages/flutter_tools/test/commands/create_test.dart b/packages/flutter_tools/test/commands/create_test.dart index aa5bb6304ca..a6e7b1600b8 100644 --- a/packages/flutter_tools/test/commands/create_test.dart +++ b/packages/flutter_tools/test/commands/create_test.dart @@ -47,7 +47,7 @@ void main() { // Verify that we create a project that is well-formed. testUsingContext('project', () async { - return _createAndAnalyzeProject( + await _createAndAnalyzeProject( projectDir, [], [ @@ -60,6 +60,7 @@ void main() { 'flutter_project.iml', ], ); + return _runFlutterTest(projectDir); }, timeout: allowForRemotePubInvocation); testUsingContext('kotlin/swift project', () async { @@ -82,7 +83,7 @@ void main() { }, timeout: allowForCreateFlutterProject); testUsingContext('package project', () async { - return _createAndAnalyzeProject( + await _createAndAnalyzeProject( projectDir, ['--template=package'], [ @@ -106,10 +107,11 @@ void main() { 'test/widget_test.dart', ], ); + return _runFlutterTest(projectDir); }, timeout: allowForRemotePubInvocation); testUsingContext('plugin project', () async { - return _createAndAnalyzeProject( + await _createAndAnalyzeProject( projectDir, ['--template=plugin'], [ @@ -126,6 +128,7 @@ void main() { ], plugin: true, ); + return _runFlutterTest(projectDir.childDirectory('example')); }, timeout: allowForRemotePubInvocation); testUsingContext('kotlin/swift plugin project', () async { @@ -212,19 +215,7 @@ void main() { // TODO(pq): enable when sky_shell is available if (!io.Platform.isWindows) { // Verify that the sample widget test runs cleanly. - final List args = [] - ..addAll(dartVmFlags) - ..add(fs.path.absolute(fs.path.join('bin', 'flutter_tools.dart'))) - ..add('test') - ..add('--no-color') - ..add(fs.path.join(projectDir.path, 'test', 'widget_test.dart')); - - final ProcessResult result = await Process.run( - fs.path.join(dartSdkPath, 'bin', 'dart'), - args, - workingDirectory: projectDir.path, - ); - expect(result.exitCode, 0); + await _runFlutterTest(projectDir, target: fs.path.join(projectDir.path, 'test', 'widget_test.dart')); } // Generated Xcode settings @@ -395,6 +386,32 @@ Future _analyzeProject(String workingDir, {String target}) async { expect(exec.exitCode, 0); } +Future _runFlutterTest(Directory workingDir, {String target}) async { + final String flutterToolsPath = fs.path.absolute(fs.path.join( + 'bin', + 'flutter_tools.dart', + )); + + final List args = [] + ..addAll(dartVmFlags) + ..add(flutterToolsPath) + ..add('test') + ..add('--no-color'); + if (target != null) + args.add(target); + + final ProcessResult exec = await Process.run( + '$dartSdkPath/bin/dart', + args, + workingDirectory: workingDir.path, + ); + if (exec.exitCode != 0) { + print(exec.stdout); + print(exec.stderr); + } + expect(exec.exitCode, 0); +} + class MockFlutterVersion extends Mock implements FlutterVersion {} /// A ProcessManager that invokes a real process manager, but keeps