From 9be9a40948e0ab84a78fa8c74e08dc2dfe596be2 Mon Sep 17 00:00:00 2001 From: Mikkel Nygaard Ravn Date: Tue, 5 Sep 2017 13:17:14 +0200 Subject: [PATCH] Avoid running pub get and analyze on every project during create_test (#11932) --- .../test/commands/create_test.dart | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/flutter_tools/test/commands/create_test.dart b/packages/flutter_tools/test/commands/create_test.dart index 065c34444e..359fdd93ad 100644 --- a/packages/flutter_tools/test/commands/create_test.dart +++ b/packages/flutter_tools/test/commands/create_test.dart @@ -49,12 +49,12 @@ void main() { 'test/widget_test.dart' ], ); - }); + }, timeout: const Timeout.factor(2.0)); testUsingContext('kotlin/swift project', () async { - return _createAndAnalyzeProject( + return _createProject( projectDir, - ['--android-language', 'kotlin', '-i', 'swift'], + ['--no-pub', '--android-language', 'kotlin', '-i', 'swift'], [ 'android/app/src/main/kotlin/com/yourcompany/flutterproject/MainActivity.kt', 'ios/Runner/AppDelegate.swift', @@ -95,7 +95,7 @@ void main() { 'test/widget_test.dart', ], ); - }); + }, timeout: const Timeout.factor(2.0)); testUsingContext('plugin project', () async { return _createAndAnalyzeProject( @@ -114,12 +114,12 @@ void main() { ], plugin: true, ); - }); + }, timeout: const Timeout.factor(2.0)); testUsingContext('plugin project (legacy)', () async { - return _createAndAnalyzeProject( + return _createProject( projectDir, - ['--plugin'], + ['--no-pub', '--plugin'], [ 'android/src/main/java/com/yourcompany/flutterproject/FlutterProjectPlugin.java', 'ios/Classes/FlutterProjectPlugin.h', @@ -136,9 +136,9 @@ void main() { }); testUsingContext('kotlin/swift plugin project', () async { - return _createAndAnalyzeProject( + return _createProject( projectDir, - ['--template=plugin', '-a', 'kotlin', '--ios-language', 'swift'], + ['--no-pub', '--template=plugin', '-a', 'kotlin', '--ios-language', 'swift'], [ 'android/src/main/kotlin/com/yourcompany/flutterproject/FlutterProjectPlugin.kt', 'ios/Classes/FlutterProjectPlugin.h', @@ -162,9 +162,9 @@ void main() { }); testUsingContext('plugin project with custom org', () async { - return _createAndAnalyzeProject( + return _createProject( projectDir, - ['--template=plugin', '--org', 'com.bar.foo'], + ['--no-pub', '--template=plugin', '--org', 'com.bar.foo'], [ 'android/src/main/java/com/bar/foo/flutterproject/FlutterProjectPlugin.java', 'example/android/app/src/main/java/com/bar/foo/flutterprojectexample/MainActivity.java', @@ -183,7 +183,7 @@ void main() { ['--with-driver-test'], ['lib/main.dart'], ); - }); + }, timeout: const Timeout.factor(2.0)); // Verify content and formatting testUsingContext('content', () async { @@ -299,9 +299,9 @@ void main() { }); } -Future _createAndAnalyzeProject( +Future _createProject( Directory dir, List createArgs, List expectedPaths, - { List unexpectedPaths = const [], bool plugin = false }) async { + { List unexpectedPaths = const [], bool plugin = false}) async { Cache.flutterRoot = '../..'; final CreateCommand command = new CreateCommand(); final CommandRunner runner = createTestCommandRunner(command); @@ -316,16 +316,21 @@ Future _createAndAnalyzeProject( for (String path in unexpectedPaths) { expect(fs.file(fs.path.join(dir.path, path)).existsSync(), false, reason: '$path exists'); } +} +Future _createAndAnalyzeProject( + Directory dir, List createArgs, List expectedPaths, + { List unexpectedPaths = const [], bool plugin = false }) async { + await _createProject(dir, createArgs, expectedPaths, unexpectedPaths: unexpectedPaths, plugin: plugin); if (plugin) { - _analyze(dir.path, target: fs.path.join(dir.path, 'lib', 'flutter_project.dart')); - _analyze(fs.path.join(dir.path, 'example')); + await _analyzeProject(dir.path, target: fs.path.join(dir.path, 'lib', 'flutter_project.dart')); + await _analyzeProject(fs.path.join(dir.path, 'example')); } else { - _analyze(dir.path); + await _analyzeProject(dir.path); } } -void _analyze(String workingDir, {String target}) { +Future _analyzeProject(String workingDir, {String target}) async { final String flutterToolsPath = fs.path.absolute(fs.path.join( 'bin', 'flutter_tools.dart', @@ -335,7 +340,7 @@ void _analyze(String workingDir, {String target}) { if (target != null) args.add(target); - final ProcessResult exec = Process.runSync( + final ProcessResult exec = await Process.run( '$dartSdkPath/bin/dart', args, workingDirectory: workingDir,