Skip to content

Commit

Permalink
Added support for flavors mmcc007#55
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcc007 committed Jul 18, 2019
1 parent 68758d1 commit 1f60b0b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
9 changes: 6 additions & 3 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import 'package:screenshots/screenshots.dart';
import 'package:path/path.dart' as path;

const usage =
'usage: screenshots [-h] [-c <config file>] [-m <normal|recording|comparison|archive>]';
'usage: screenshots [-h] [-c <config file>] [-m <normal|recording|comparison|archive>] [-f <flavor>]';
const sampleUsage = 'sample usage: screenshots';

void main(List<String> arguments) async {
ArgResults argResults;

final configArg = 'config';
final modeArg = 'mode';
final flavorArg = 'flavor';
final helpArg = 'help';
final ArgParser argParser = ArgParser(allowTrailingOptions: false)
..addOption(configArg,
Expand All @@ -24,9 +25,11 @@ void main(List<String> 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 {
Expand Down Expand Up @@ -79,7 +82,7 @@ void main(List<String> 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) {
Expand Down
5 changes: 4 additions & 1 deletion lib/src/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
39 changes: 29 additions & 10 deletions lib/src/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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();
Expand Down Expand Up @@ -59,8 +61,8 @@ Future<void> 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;

Expand Down Expand Up @@ -90,8 +92,15 @@ Future<void> 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'];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1f60b0b

Please sign in to comment.