[web] improving felt: running target unit tests, cleaning up used proccesses (flutter/engine#17339)

* improving felt: running target unit tests, cleaning up used proccesses

* removing null check
This commit is contained in:
Nurhan Turgut
2020-03-26 14:01:36 -07:00
committed by GitHub
parent 42c22a2167
commit f844653475
3 changed files with 34 additions and 17 deletions

View File

@@ -35,6 +35,7 @@ void main(List<String> args) async {
final bool result = await runner.run(args);
if (result == false) {
print('Sub-command returned false: `${args.join(' ')}`');
_cleanup();
io.exit(1);
}
} on UsageException catch (e) {

View File

@@ -5,7 +5,6 @@
import 'dart:io' as io;
import 'package:path/path.dart' as pathlib;
import 'package:web_driver_installer/chrome_driver_installer.dart';
import 'package:yaml/yaml.dart';
import 'chrome_installer.dart';
import 'common.dart';
@@ -21,8 +20,7 @@ class IntegrationTestsManager {
/// It usually changes with each the browser version changes.
/// A better solution would be installing the browser and the driver at the
/// same time.
// TODO(nurhan): change the web installers to install driver and the browser
// at the same time.
// TODO(nurhan): https://github.com/flutter/flutter/issues/53179.
final io.Directory _browserDriverDir;
/// This is the parent directory for all drivers.
@@ -32,10 +30,10 @@ class IntegrationTestsManager {
final io.Directory _drivers;
IntegrationTestsManager(this._browser)
: this._browserDriverDir = io.Directory(
pathlib.join(environment.webUiRootDir.path, 'drivers', _browser)),
: this._browserDriverDir = io.Directory(pathlib.join(
environment.webUiDartToolDir.path, 'drivers', _browser)),
this._drivers = io.Directory(
pathlib.join(environment.webUiRootDir.path, 'drivers'));
pathlib.join(environment.webUiDartToolDir.path, 'drivers'));
Future<bool> runTests() async {
if (_browser != 'chrome') {
@@ -77,6 +75,7 @@ class IntegrationTestsManager {
startProcess(
'./chromedriver/chromedriver',
['--port=4444'],
workingDirectory: io.Directory.current.path
);
print('INFO: Driver started');
}
@@ -89,12 +88,16 @@ class IntegrationTestsManager {
_browserDriverDir.createSync(recursive: true);
temporaryDirectories.add(_drivers);
io.Directory temp = io.Directory.current;
io.Directory.current = _browserDriverDir;
// TODO(nurhan): https://github.com/flutter/flutter/issues/53179
final String chromeDriverVersion = await queryChromeDriverVersion();
ChromeDriverInstaller chromeDriverInstaller =
ChromeDriverInstaller.withVersion(chromeDriverVersion);
await chromeDriverInstaller.install(alwaysInstall: true);
await _runDriver();
io.Directory.current = temp;
}
/// Runs all the web tests under e2e_tests/web.

View File

@@ -115,13 +115,18 @@ class TestCommand extends Command<bool> {
case TestTypesRequested.integration:
return runIntegrationTests();
case TestTypesRequested.all:
bool integrationTestResult = await runIntegrationTests();
bool unitTestResult = await runUnitTests();
if (integrationTestResult != unitTestResult) {
print('Tests run. Integration tests passed: $integrationTestResult '
'unit tests passed: $unitTestResult');
// TODO(nurhan): https://github.com/flutter/flutter/issues/53322
if (runAllTests) {
bool integrationTestResult = await runIntegrationTests();
bool unitTestResult = await runUnitTests();
if (integrationTestResult != unitTestResult) {
print('Tests run. Integration tests passed: $integrationTestResult '
'unit tests passed: $unitTestResult');
}
return integrationTestResult && unitTestResult;
} else {
return await runUnitTests();
}
return integrationTestResult && unitTestResult;
}
return false;
}
@@ -145,13 +150,11 @@ class TestCommand extends Command<bool> {
await _runPubGet();
}
final List<FilePath> targets =
this.targets.map((t) => FilePath.fromCwd(t)).toList();
await _buildTests(targets: targets);
if (targets.isEmpty) {
await _buildTests(targets: targetFiles);
if (runAllTests) {
await _runAllTests();
} else {
await _runTargetTests(targets);
await _runTargetTests(targetFiles);
}
return true;
}
@@ -165,6 +168,16 @@ class TestCommand extends Command<bool> {
/// Paths to targets to run, e.g. a single test.
List<String> get targets => argResults.rest;
/// The target test files to run.
///
/// The value can be null if the developer prefers to run all the tests.
List<FilePath> get targetFiles => (targets.isEmpty)
? null
: targets.map((t) => FilePath.fromCwd(t)).toList();
/// Whether all tests should run.
bool get runAllTests => targets.isEmpty;
String get browser => argResults['browser'];
bool get isChrome => argResults['browser'] == 'chrome';