From 1f60b0ba57a36b84e5af36c9d06b8dae606c8fff Mon Sep 17 00:00:00 2001 From: Maurice McCabe Date: Wed, 17 Jul 2019 22:14:32 -0700 Subject: [PATCH] Added support for flavors #55 --- bin/main.dart | 9 ++++++--- lib/src/globals.dart | 5 ++++- lib/src/run.dart | 39 +++++++++++++++++++++++++++++---------- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/bin/main.dart b/bin/main.dart index 3641324c..06603fbd 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -5,7 +5,7 @@ import 'package:screenshots/screenshots.dart'; import 'package:path/path.dart' as path; const usage = - 'usage: screenshots [-h] [-c ] [-m ]'; + 'usage: screenshots [-h] [-c ] [-m ] [-f ]'; const sampleUsage = 'sample usage: screenshots'; void main(List arguments) async { @@ -13,6 +13,7 @@ void main(List arguments) async { final configArg = 'config'; final modeArg = 'mode'; + final flavorArg = 'flavor'; final helpArg = 'help'; final ArgParser argParser = ArgParser(allowTrailingOptions: false) ..addOption(configArg, @@ -24,9 +25,11 @@ void main(List arguments) async { abbr: 'm', defaultsTo: 'normal', help: - 'If mode is recording, screenshots will be saved for later comparison. \nIf mode is archive, screenshots will be archived and cannot be uploaded via fastlane.', + 'If mode is recording, screenshots will be saved for later comparison. \nIf mode is comparison, screenshots will be compared with recorded.\nIf mode is archive, screenshots will be archived (and cannot be uploaded via fastlane).', allowed: ['normal', 'recording', 'comparison', 'archive'], valueHelp: 'normal|recording|comparison|archive') + ..addOption(flavorArg, + abbr: 'f', help: 'Flavor name.', valueHelp: 'flavor name') ..addFlag(helpArg, abbr: 'h', help: 'Display this help information.', negatable: false); try { @@ -79,7 +82,7 @@ void main(List arguments) async { _handleError(argParser, "File not found: ${argResults[configArg]}"); } - await run(argResults[configArg], argResults[modeArg]); + await run(argResults[configArg], argResults[modeArg], argResults[flavorArg]); } void _handleError(ArgParser argParser, String msg) { diff --git a/lib/src/globals.dart b/lib/src/globals.dart index fef42534..46f06730 100644 --- a/lib/src/globals.dart +++ b/lib/src/globals.dart @@ -18,5 +18,8 @@ enum DeviceType { android, ios } /// Run mode enum RunMode { normal, recording, comparison, archive } -// singleton +/// singleton ImageMagick get im => ImageMagick(); + +/// No flavor +const String kNoFlavor = 'no flavor'; diff --git a/lib/src/run.dart b/lib/src/run.dart index 1f7acc2b..8f670451 100644 --- a/lib/src/run.dart +++ b/lib/src/run.dart @@ -24,7 +24,9 @@ import 'utils.dart' as utils; /// 4. Move processed screenshots to fastlane destination for upload to stores. /// 5. If not a real device, stop emulator/simulator. Future run( - [String configPath = kConfigFileName, String _runMode = 'normal']) async { + [String configPath = kConfigFileName, + String _runMode = 'normal', + String flavor = kNoFlavor]) async { final runMode = utils.getRunModeEnum(_runMode); final screens = Screens(); @@ -59,8 +61,8 @@ Future run( } // run integration tests in each real device (or emulator/simulator) for // each locale and process screenshots - await runTestsOnAll( - daemonClient, devices, emulators, config, screens, runMode, archive); + await runTestsOnAll(daemonClient, devices, emulators, config, screens, + runMode, archive, flavor); // shutdown daemon await daemonClient.stop; @@ -90,8 +92,15 @@ Future run( /// /// Assumes the integration tests capture the screen shots into a known directory using /// provided [capture_screen.screenshot()]. -Future runTestsOnAll(DaemonClient daemonClient, List devices, List emulators, - Config config, Screens screens, RunMode runMode, Archive archive) async { +Future runTestsOnAll( + DaemonClient daemonClient, + List devices, + List emulators, + Config config, + Screens screens, + RunMode runMode, + Archive archive, + String flavor) async { final configInfo = config.configInfo; final locales = configInfo['locales']; final stagingDir = configInfo['staging']; @@ -177,7 +186,8 @@ Future runTestsOnAll(DaemonClient daemonClient, List devices, List emulators, imageProcessor, runMode, archive, - 'unknown'); + 'unknown', + flavor); } else { // Function to check for a running android device or emulator bool isRunningAndroidDeviceOrEmulator(Map device, Map emulator) { @@ -282,7 +292,8 @@ Future runTestsOnAll(DaemonClient daemonClient, List devices, List emulators, imageProcessor, runMode, archive, - deviceOrientation); + deviceOrientation, + flavor); } // if an emulator was started, revert locale if necessary and shut it down @@ -310,14 +321,22 @@ Future runProcessTests( ImageProcessor imageProcessor, RunMode runMode, Archive archive, - String orientation) async { + String orientation, + String flavor) async { // store env for later use by tests // ignore: invalid_use_of_visible_for_testing_member await config.storeEnv(screens, configDeviceName, locale, utils.getStringFromEnum(deviceType), orientation); for (final testPath in testPaths) { - print('Running $testPath on \'$configDeviceName\' in locale $locale...'); - await utils.streamCmd('flutter', ['-d', deviceId, 'drive', testPath]); + if (flavor != kNoFlavor) { + print( + 'Running $testPath on \'$configDeviceName\' in locale $locale with flavor $flavor ...'); + await utils.streamCmd('flutter', + ['-d', deviceId, 'drive', '-t', testPath, '--flavor', flavor]); + } else { + print('Running $testPath on \'$configDeviceName\' in locale $locale...'); + await utils.streamCmd('flutter', ['-d', deviceId, 'drive', testPath]); + } // process screenshots await imageProcessor.process( deviceType, configDeviceName, locale, runMode, archive);