|
|
|
|
@@ -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';
|
|
|
|
|
@@ -109,6 +110,9 @@ class IntegrationTestsManager {
|
|
|
|
|
return testResults;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _numberOfPassedTests = 0;
|
|
|
|
|
int _numberOfFailedTests = 0;
|
|
|
|
|
|
|
|
|
|
Future<bool> _runTestsInDirectory(io.Directory directory) async {
|
|
|
|
|
final io.Directory testDirectory =
|
|
|
|
|
io.Directory(pathlib.join(directory.path, 'test_driver'));
|
|
|
|
|
@@ -121,47 +125,83 @@ class IntegrationTestsManager {
|
|
|
|
|
final List<String> blockedTests =
|
|
|
|
|
blockedTestsListsMap[getBlockedTestsListMapKey(_browser)] ?? <String>[];
|
|
|
|
|
|
|
|
|
|
// The following loops over the contents of the directory and saves an
|
|
|
|
|
// expected driver file name for each e2e test assuming any dart file
|
|
|
|
|
// not ending with `_test.dart` is an e2e test.
|
|
|
|
|
// Other files are not considered since developers can add files such as
|
|
|
|
|
// README.
|
|
|
|
|
for (io.File f in entities) {
|
|
|
|
|
final String basename = pathlib.basename(f.path);
|
|
|
|
|
if (!basename.contains('_test.dart') && basename.endsWith('.dart')) {
|
|
|
|
|
// Do not add the basename if it is in the `blockedTests`.
|
|
|
|
|
if (!blockedTests.contains(basename)) {
|
|
|
|
|
e2eTestsToRun.add(basename);
|
|
|
|
|
} else {
|
|
|
|
|
print('INFO: Test $basename is skipped since it is blocked for '
|
|
|
|
|
'${getBlockedTestsListMapKey(_browser)}');
|
|
|
|
|
// If no target is specified run all the tests.
|
|
|
|
|
if (_runAllTestTargets) {
|
|
|
|
|
// The following loops over the contents of the directory and saves an
|
|
|
|
|
// expected driver file name for each e2e test assuming any dart file
|
|
|
|
|
// not ending with `_test.dart` is an e2e test.
|
|
|
|
|
// Other files are not considered since developers can add files such as
|
|
|
|
|
// README.
|
|
|
|
|
for (io.File f in entities) {
|
|
|
|
|
final String basename = pathlib.basename(f.path);
|
|
|
|
|
if (!basename.contains('_test.dart') && basename.endsWith('.dart')) {
|
|
|
|
|
// Do not add the basename if it is in the `blockedTests`.
|
|
|
|
|
if (!blockedTests.contains(basename)) {
|
|
|
|
|
e2eTestsToRun.add(basename);
|
|
|
|
|
} else {
|
|
|
|
|
print('INFO: Test $basename is skipped since it is blocked for '
|
|
|
|
|
'${getBlockedTestsListMapKey(_browser)}');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isVerboseLoggingEnabled) {
|
|
|
|
|
print(
|
|
|
|
|
'INFO: In project ${directory} ${e2eTestsToRun.length} tests to run.');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// If a target is specified it will run regardless of if it's blocked or
|
|
|
|
|
// not. There will be an info note to warn the developer.
|
|
|
|
|
final String targetTest =
|
|
|
|
|
IntegrationTestsArgumentParser.instance.testTarget;
|
|
|
|
|
final io.File file =
|
|
|
|
|
entities.singleWhere((f) => pathlib.basename(f.path) == targetTest);
|
|
|
|
|
final String basename = pathlib.basename(file.path);
|
|
|
|
|
if (blockedTests.contains(basename) && isVerboseLoggingEnabled) {
|
|
|
|
|
print('INFO: Test $basename do not run on CI environments. Please '
|
|
|
|
|
'remove it from the blocked tests list if you want to enable this '
|
|
|
|
|
'test on CI.');
|
|
|
|
|
}
|
|
|
|
|
e2eTestsToRun.add(basename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print(
|
|
|
|
|
'INFO: In project ${directory} ${e2eTestsToRun.length} tests to run.');
|
|
|
|
|
|
|
|
|
|
int numberOfPassedTests = 0;
|
|
|
|
|
int numberOfFailedTests = 0;
|
|
|
|
|
|
|
|
|
|
final Set<String> buildModes = _getBuildModes();
|
|
|
|
|
|
|
|
|
|
for (String fileName in e2eTestsToRun) {
|
|
|
|
|
final bool testResults =
|
|
|
|
|
await _runTestsInProfileMode(directory, fileName);
|
|
|
|
|
if (testResults) {
|
|
|
|
|
numberOfPassedTests++;
|
|
|
|
|
} else {
|
|
|
|
|
numberOfFailedTests++;
|
|
|
|
|
}
|
|
|
|
|
await _runTestsTarget(directory, fileName, buildModes);
|
|
|
|
|
}
|
|
|
|
|
final int numberOfTestsRun = numberOfPassedTests + numberOfFailedTests;
|
|
|
|
|
|
|
|
|
|
final int numberOfTestsRun = _numberOfPassedTests + _numberOfFailedTests;
|
|
|
|
|
|
|
|
|
|
print('INFO: ${numberOfTestsRun} tests run. ${numberOfPassedTests} passed '
|
|
|
|
|
'and ${numberOfFailedTests} failed.');
|
|
|
|
|
return numberOfFailedTests == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> _runTestsInProfileMode(
|
|
|
|
|
io.Directory directory, String testName) async {
|
|
|
|
|
Future<void> _runTestsTarget(
|
|
|
|
|
io.Directory directory, String target, Set<String> buildModes) async {
|
|
|
|
|
final Set<String> renderingBackends = _getRenderingBackends();
|
|
|
|
|
for (String renderingBackend in renderingBackends) {
|
|
|
|
|
for (String mode in buildModes) {
|
|
|
|
|
if (!blockedTestsListsMapForModes[mode].contains(target) &&
|
|
|
|
|
!blockedTestsListsMapForRenderBackends[renderingBackend]
|
|
|
|
|
.contains(target)) {
|
|
|
|
|
final bool result = await _runTestsInMode(directory, target,
|
|
|
|
|
mode: mode, webRenderer: renderingBackend);
|
|
|
|
|
if (result) {
|
|
|
|
|
_numberOfPassedTests++;
|
|
|
|
|
} else {
|
|
|
|
|
_numberOfFailedTests++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> _runTestsInMode(io.Directory directory, String testName,
|
|
|
|
|
{String mode = 'profile', String webRenderer = 'html'}) async {
|
|
|
|
|
String executable =
|
|
|
|
|
_useSystemFlutter ? 'flutter' : environment.flutterCommand.path;
|
|
|
|
|
Map<String, String> enviroment = Map<String, String>();
|
|
|
|
|
@@ -172,22 +212,54 @@ class IntegrationTestsManager {
|
|
|
|
|
IntegrationArguments.fromBrowser(_browser);
|
|
|
|
|
final int exitCode = await runProcess(
|
|
|
|
|
executable,
|
|
|
|
|
arguments.getTestArguments(testName, 'profile'),
|
|
|
|
|
arguments.getTestArguments(testName, mode, webRenderer),
|
|
|
|
|
workingDirectory: directory.path,
|
|
|
|
|
environment: enviroment,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (exitCode != 0) {
|
|
|
|
|
final String command =
|
|
|
|
|
arguments.getCommandToRun(testName, mode, webRenderer);
|
|
|
|
|
io.stderr
|
|
|
|
|
.writeln('ERROR: Failed to run test. Exited with exit code $exitCode'
|
|
|
|
|
'. To run $testName locally use the following command:'
|
|
|
|
|
'\n\n${arguments.getCommandToRun(testName, 'profile')}');
|
|
|
|
|
'\n\n$command');
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set<String> _getRenderingBackends() {
|
|
|
|
|
Set<String> renderingBackends;
|
|
|
|
|
if (_renderingBackendSelected) {
|
|
|
|
|
final String mode = IntegrationTestsArgumentParser.instance.webRenderer;
|
|
|
|
|
renderingBackends = <String>{mode};
|
|
|
|
|
} else {
|
|
|
|
|
// TODO(nurhan): Enable `auto` when recipe is sharded.
|
|
|
|
|
renderingBackends = {'html', 'canvaskit'};
|
|
|
|
|
}
|
|
|
|
|
return renderingBackends;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set<String> _getBuildModes() {
|
|
|
|
|
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 {
|
|
|
|
|
// TODO(nurhan): Enable `release` when recipe is sharded.
|
|
|
|
|
buildModes = _browser == 'chrome'
|
|
|
|
|
? {'debug', 'profile'}
|
|
|
|
|
: {'profile'};
|
|
|
|
|
}
|
|
|
|
|
return buildModes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Validate the directory has a `pubspec.yaml` file and a `test_driver`
|
|
|
|
|
/// directory.
|
|
|
|
|
///
|
|
|
|
|
@@ -290,9 +362,25 @@ class IntegrationTestsManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool get _buildModeSelected =>
|
|
|
|
|
!IntegrationTestsArgumentParser.instance.buildMode.isEmpty;
|
|
|
|
|
|
|
|
|
|
bool get _renderingBackendSelected =>
|
|
|
|
|
!IntegrationTestsArgumentParser.instance.webRenderer.isEmpty;
|
|
|
|
|
|
|
|
|
|
bool get _runAllTestTargets =>
|
|
|
|
|
IntegrationTestsArgumentParser.instance.testTarget.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') {
|
|
|
|
|
@@ -326,14 +414,16 @@ abstract class IntegrationArguments {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> getTestArguments(String testName, String mode);
|
|
|
|
|
List<String> getTestArguments(
|
|
|
|
|
String testName, String mode, String webRenderer);
|
|
|
|
|
|
|
|
|
|
String getCommandToRun(String testName, String mode);
|
|
|
|
|
String getCommandToRun(String testName, String mode, String webRenderer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Arguments to give `flutter drive` to run the integration tests on Chrome.
|
|
|
|
|
class ChromeIntegrationArguments extends IntegrationArguments {
|
|
|
|
|
List<String> getTestArguments(String testName, String mode) {
|
|
|
|
|
List<String> getTestArguments(
|
|
|
|
|
String testName, String mode, String webRenderer) {
|
|
|
|
|
return <String>[
|
|
|
|
|
'drive',
|
|
|
|
|
'--target=test_driver/${testName}',
|
|
|
|
|
@@ -344,13 +434,15 @@ class ChromeIntegrationArguments extends IntegrationArguments {
|
|
|
|
|
if (isLuci) '--chrome-binary=${preinstalledChromeExecutable()}',
|
|
|
|
|
'--headless',
|
|
|
|
|
'--local-engine=host_debug_unopt',
|
|
|
|
|
'--web-renderer=$webRenderer',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getCommandToRun(String testName, String mode) {
|
|
|
|
|
String getCommandToRun(String testName, String mode, String webRenderer) {
|
|
|
|
|
String statementToRun = 'flutter drive '
|
|
|
|
|
'--target=test_driver/${testName} -d web-server --profile '
|
|
|
|
|
'--browser-name=chrome --local-engine=host_debug_unopt';
|
|
|
|
|
'--target=test_driver/${testName} -d web-server --$mode '
|
|
|
|
|
'--browser-name=chrome --local-engine=host_debug_unopt '
|
|
|
|
|
'--web-renderer=$webRenderer';
|
|
|
|
|
if (isLuci) {
|
|
|
|
|
statementToRun = '$statementToRun --chrome-binary='
|
|
|
|
|
'${preinstalledChromeExecutable()}';
|
|
|
|
|
@@ -361,7 +453,8 @@ class ChromeIntegrationArguments extends IntegrationArguments {
|
|
|
|
|
|
|
|
|
|
/// Arguments to give `flutter drive` to run the integration tests on Firefox.
|
|
|
|
|
class FirefoxIntegrationArguments extends IntegrationArguments {
|
|
|
|
|
List<String> getTestArguments(String testName, String mode) {
|
|
|
|
|
List<String> getTestArguments(
|
|
|
|
|
String testName, String mode, String webRenderer) {
|
|
|
|
|
return <String>[
|
|
|
|
|
'drive',
|
|
|
|
|
'--target=test_driver/${testName}',
|
|
|
|
|
@@ -371,18 +464,23 @@ class FirefoxIntegrationArguments extends IntegrationArguments {
|
|
|
|
|
'--browser-name=firefox',
|
|
|
|
|
'--headless',
|
|
|
|
|
'--local-engine=host_debug_unopt',
|
|
|
|
|
'--web-renderer=$webRenderer',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getCommandToRun(String testName, String mode) =>
|
|
|
|
|
'flutter ${getTestArguments(testName, mode).join(' ')}';
|
|
|
|
|
String getCommandToRun(String testName, String mode, String webRenderer) {
|
|
|
|
|
final String arguments =
|
|
|
|
|
getTestArguments(testName, mode, webRenderer).join(' ');
|
|
|
|
|
return 'flutter $arguments';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Arguments to give `flutter drive` to run the integration tests on Safari.
|
|
|
|
|
class SafariIntegrationArguments extends IntegrationArguments {
|
|
|
|
|
SafariIntegrationArguments();
|
|
|
|
|
|
|
|
|
|
List<String> getTestArguments(String testName, String mode) {
|
|
|
|
|
List<String> getTestArguments(
|
|
|
|
|
String testName, String mode, String webRenderer) {
|
|
|
|
|
return <String>[
|
|
|
|
|
'drive',
|
|
|
|
|
'--target=test_driver/${testName}',
|
|
|
|
|
@@ -391,11 +489,96 @@ class SafariIntegrationArguments extends IntegrationArguments {
|
|
|
|
|
'--$mode',
|
|
|
|
|
'--browser-name=safari',
|
|
|
|
|
'--local-engine=host_debug_unopt',
|
|
|
|
|
'--web-renderer=$webRenderer',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String getCommandToRun(String testName, String mode) =>
|
|
|
|
|
'flutter ${getTestArguments(testName, mode).join(' ')}';
|
|
|
|
|
String getCommandToRun(String testName, String mode, String webRenderer) {
|
|
|
|
|
final String arguments =
|
|
|
|
|
getTestArguments(testName, mode, webRenderer).join(' ');
|
|
|
|
|
return 'flutter $arguments';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
|
///
|
|
|
|
|
/// In order to skip a test for one of the modes, add the test to the
|
|
|
|
|
/// `blockedTestsListsMapForModes` list for the relevant compile mode.
|
|
|
|
|
String buildMode;
|
|
|
|
|
|
|
|
|
|
/// Whether to use html, canvaskit or auto for web renderer.
|
|
|
|
|
///
|
|
|
|
|
/// If not set all backends will be used one after another for integration
|
|
|
|
|
/// tests. If set only the provided option will be used.
|
|
|
|
|
String webRenderer;
|
|
|
|
|
|
|
|
|
|
void populateOptions(ArgParser argParser) {
|
|
|
|
|
argParser
|
|
|
|
|
..addOption(
|
|
|
|
|
'target',
|
|
|
|
|
defaultsTo: '',
|
|
|
|
|
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. This '
|
|
|
|
|
'option sets the build mode for the integration tests. '
|
|
|
|
|
'By default an integration test will sequentially run on '
|
|
|
|
|
'multiple modes. All three modes (debug, release, profile) are '
|
|
|
|
|
'used for Chrome. Only profile, release modes will be used for '
|
|
|
|
|
'other browsers. In other words, if a build mode is selected '
|
|
|
|
|
'tests will only be run using that mode. '
|
|
|
|
|
'See https://flutter.dev/docs/testing/build-modes for more '
|
|
|
|
|
'details on the build modes.')
|
|
|
|
|
..addOption('web-renderer',
|
|
|
|
|
defaultsTo: '',
|
|
|
|
|
help: 'By default all three options (`html`, `canvaskit`, `auto`) '
|
|
|
|
|
' for rendering backends are tested when running integration '
|
|
|
|
|
' tests. If this option is set only the backend provided by this '
|
|
|
|
|
' option will be used. `auto`, `canvaskit` and `html`'
|
|
|
|
|
' are the available options. ');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Populate results of the arguments passed.
|
|
|
|
|
void parseOptions(ArgResults argResults) {
|
|
|
|
|
testTarget = argResults['target'] as String;
|
|
|
|
|
buildMode = argResults['build-mode'] as String;
|
|
|
|
|
if (!buildMode.isEmpty &&
|
|
|
|
|
buildMode != 'debug' &&
|
|
|
|
|
buildMode != 'profile' &&
|
|
|
|
|
buildMode != 'release') {
|
|
|
|
|
throw ArgumentError('Unexpected build mode: $buildMode');
|
|
|
|
|
}
|
|
|
|
|
webRenderer = argResults['web-renderer'] as String;
|
|
|
|
|
if (!webRenderer.isEmpty &&
|
|
|
|
|
webRenderer != 'html' &&
|
|
|
|
|
webRenderer != 'canvaskit' &&
|
|
|
|
|
webRenderer != 'auto') {
|
|
|
|
|
throw ArgumentError('Unexpected rendering backend: $webRenderer');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Prepares a key for the [blackList] map.
|
|
|
|
|
@@ -440,3 +623,32 @@ const Map<String, List<String>> blockedTestsListsMap = <String, List<String>>{
|
|
|
|
|
'target_platform_ios_integration.dart',
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Tests blocked for one of the build modes.
|
|
|
|
|
///
|
|
|
|
|
/// If a test is not supposed to run for one of the modes also add that test
|
|
|
|
|
/// to the corresponding list.
|
|
|
|
|
// TODO(nurhan): Remove the failing test after fixing.
|
|
|
|
|
const Map<String, List<String>> blockedTestsListsMapForModes =
|
|
|
|
|
<String, List<String>>{
|
|
|
|
|
'debug': [
|
|
|
|
|
'treeshaking_integration.dart',
|
|
|
|
|
'text_editing_integration.dart',
|
|
|
|
|
'url_strategy_integration.dart',
|
|
|
|
|
],
|
|
|
|
|
'profile': [],
|
|
|
|
|
'release': [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Tests blocked for one of the rendering backends.
|
|
|
|
|
///
|
|
|
|
|
/// If a test is not suppose to run for one of the backends also add that test
|
|
|
|
|
/// to the corresponding list.
|
|
|
|
|
// TODO(nurhan): Remove the failing test after fixing.
|
|
|
|
|
const Map<String, List<String>> blockedTestsListsMapForRenderBackends =
|
|
|
|
|
<String, List<String>>{
|
|
|
|
|
'auto': [],
|
|
|
|
|
'html': [],
|
|
|
|
|
// This test failed on canvaskit on all three build modes.
|
|
|
|
|
'canvaskit': ['image_loading_integration.dart'],
|
|
|
|
|
};
|
|
|
|
|
|