Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding flags to control the integration tests better with felt
  • Loading branch information
nturgut committed Nov 10, 2020
commit 5889d0cceac8992da42966f4da0ea1c8d001e968
93 changes: 90 additions & 3 deletions lib/web_ui/dev/integration_tests_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// @dart = 2.6

import 'dart:io' as io;
import 'package:args/args.dart';
import 'package:path/path.dart' as pathlib;

import 'chrome_installer.dart';
Expand Down Expand Up @@ -144,9 +145,20 @@ class IntegrationTestsManager {

int numberOfPassedTests = 0;
int numberOfFailedTests = 0;
final Set<String> buildModes = _browser == 'chrome'
? {'debug', 'profile', 'release'}
: {'profile', 'release'};

Set<String> buildModes;
if (_buildModeSelected) {
final String mode = IntegrationTestsArgumentParser.instance.buildMode;
if (mode == 'debug' && _browser != 'chrome') {
throw ToolException('Debug mode is only supported for Chrome.');
} else {
buildModes = <String>{mode};
}
} else {
buildModes = _browser == 'chrome'
? {'debug', 'profile', 'release'}
: {'profile', 'release'};
}
for (String fileName in e2eTestsToRun) {
for (String mode in buildModes) {
if (!blockedTestsListsMapForModes[mode].contains(fileName)) {
Expand Down Expand Up @@ -298,9 +310,19 @@ class IntegrationTestsManager {
}
}

bool get _buildModeSelected =>
!IntegrationTestsArgumentParser.instance.buildMode.isEmpty;

/// Validate the given `browser`, `platform` combination is suitable for
/// integration tests to run.
bool validateIfTestsShouldRun() {
if (_buildModeSelected) {
final String mode = IntegrationTestsArgumentParser.instance.buildMode;
if (mode == 'debug' && _browser != 'chrome') {
throw ToolException('Debug mode is only supported for Chrome.');
}
}

// Chrome tests should run at all Platforms (Linux, macOS, Windows).
// They can also run successfully on CI and local.
if (_browser == 'chrome') {
Expand Down Expand Up @@ -406,6 +428,71 @@ class SafariIntegrationArguments extends IntegrationArguments {
'flutter ${getTestArguments(testName, mode).join(' ')}';
}

/// Parses additional options that can be used when running integration tests.
class IntegrationTestsArgumentParser {
static final IntegrationTestsArgumentParser _singletonInstance =
IntegrationTestsArgumentParser._();

/// The [IntegrationTestsArgumentParser] singleton.
static IntegrationTestsArgumentParser get instance => _singletonInstance;

IntegrationTestsArgumentParser._();

/// If target name is provided integration tests can run that one test
/// instead of running all the tests.
String testTarget;

/// The build mode to run the integration tests.
///
/// If not specified, these tests will run using 'debug, profile, release'
/// modes on Chrome and will run using 'profile, release' on other browsers.
///
///
String buildMode;

/// Whether the rendering backend to be used is html.
///
/// If set to false canvaskit rendering backend will be used.
bool useHtmlBackend;

void populateOptions(ArgParser argParser) {
argParser
..addOption(
'target',
help: 'By default integration tests are run for all the tests under'
'flutter/e2etests/web directory. If a test name is specified, that '
'only that test will run. The test name will be the name of the '
'integration test (e2e test) file. For example: '
'text_editing_integration.dart or '
'profile_diagnostics_integration.dart',
)
..addOption('build-mode',
defaultsTo: '',
help: 'Flutter supports three modes when building your app. The By '
'default debug, profile, release modes will be used one by one '
'on Chrome and profile, release modes will be used for other '
'browsers. If a build mode is selected tests will only be run '
'using that mode. ')
..addFlag('html-backend',
defaultsTo: true,
help: 'Default rendering backend is HTML. If this flag is set to '
'false canvaskit backend will be used for rendering when running '
'integration tests.');
}

/// Populate browser with results of the arguments passed.
void parseOptions(ArgResults argResults) {
testTarget = argResults['target'] as String;
buildMode = argResults['build-mode'] as String;
if (buildMode.toLowerCase() != 'debug' &&
buildMode.toLowerCase() != 'profile' &&
buildMode.toLowerCase() != 'release') {
throw ArgumentError('Unexpected build mode: $buildMode');
}
useHtmlBackend = argResults['html-backend'] as bool;
}
}

/// Prepares a key for the [blackList] map.
///
/// Uses the browser name and the operating system name.
Expand Down
11 changes: 7 additions & 4 deletions lib/web_ui/dev/test_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class TestCommand extends Command<bool> with ArgUtils {

SupportedBrowsers.instance.argParsers
.forEach((t) => t.populateOptions(argParser));
IntegrationTestsArgumentParser.instance.populateOptions(argParser);
}

@override
Expand Down Expand Up @@ -147,6 +148,8 @@ class TestCommand extends Command<bool> with ArgUtils {
case TestTypesRequested.unit:
return runUnitTests();
case TestTypesRequested.integration:
// Parse additional arguments specific for integration testing.
IntegrationTestsArgumentParser.instance.parseOptions(argResults);
return runIntegrationTests();
case TestTypesRequested.all:
if (runAllTests && isIntegrationTestsAvailable) {
Expand All @@ -165,9 +168,9 @@ class TestCommand extends Command<bool> with ArgUtils {
}

Future<bool> runIntegrationTests() async {
if(!_testPreparationReady) {
await _prepare();
}
// if(!_testPreparationReady) {
// await _prepare();
// }
return IntegrationTestsManager(
browser, useSystemFlutter, doUpdateScreenshotGoldens)
.runTests();
Expand Down Expand Up @@ -204,7 +207,7 @@ class TestCommand extends Command<bool> with ArgUtils {

// If screenshot tests are available, fetch the screenshot goldens.
if (isScreenshotTestsAvailable) {
print('screenshot tests available');
print('INFO: Screenshot tests available');
final GoldensRepoFetcher goldensRepoFetcher = GoldensRepoFetcher(
environment.webUiGoldensRepositoryDirectory,
path.join(environment.webUiDevDir.path, 'goldens_lock.yaml'));
Expand Down