forked from firka/flutter
Revert "[flutter_tools] remove mocks, globals from golden comparator and test runner tests (#81423)" (#81487)
This reverts commit 8fe4cc7964.
This commit is contained in:
committed by
GitHub
parent
8fe4cc7964
commit
027d4ecaba
@@ -4,44 +4,33 @@
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../convert.dart';
|
||||
import '../globals_null_migrated.dart' as globals;
|
||||
import 'test_compiler.dart';
|
||||
import 'test_config.dart';
|
||||
|
||||
/// Helper class to start golden file comparison in a separate process.
|
||||
///
|
||||
/// The golden file comparator is configured using flutter_test_config.dart and that
|
||||
/// Golden file comparator is configured using flutter_test_config.dart and that
|
||||
/// file can contain arbitrary Dart code that depends on dart:ui. Thus it has to
|
||||
/// be executed in a `flutter_tester` environment. This helper class generates a
|
||||
/// Dart file configured with flutter_test_config.dart to perform the comparison
|
||||
/// of golden files.
|
||||
class TestGoldenComparator {
|
||||
/// Creates a [TestGoldenComparator] instance.
|
||||
TestGoldenComparator(this.shellPath, this.compilerFactory, {
|
||||
@required Logger logger,
|
||||
@required FileSystem fileSystem,
|
||||
@required ProcessManager processManager,
|
||||
}) : tempDir = fileSystem.systemTempDirectory.createTempSync('flutter_web_platform.'),
|
||||
_logger = logger,
|
||||
_fileSystem = fileSystem,
|
||||
_processManager = processManager;
|
||||
TestGoldenComparator(this.shellPath, this.compilerFactory)
|
||||
: tempDir = globals.fs.systemTempDirectory.createTempSync('flutter_web_platform.');
|
||||
|
||||
final String shellPath;
|
||||
final Directory tempDir;
|
||||
final TestCompiler Function() compilerFactory;
|
||||
final Logger _logger;
|
||||
final FileSystem _fileSystem;
|
||||
final ProcessManager _processManager;
|
||||
|
||||
TestCompiler _compiler;
|
||||
TestGoldenComparatorProcess _previousComparator;
|
||||
@@ -60,10 +49,10 @@ class TestGoldenComparator {
|
||||
return _previousComparator;
|
||||
}
|
||||
|
||||
final String bootstrap = TestGoldenComparatorProcess.generateBootstrap(_fileSystem.file(testUri), testUri, logger: _logger);
|
||||
final String bootstrap = TestGoldenComparatorProcess.generateBootstrap(testUri);
|
||||
final Process process = await _startProcess(bootstrap);
|
||||
unawaited(_previousComparator?.close());
|
||||
_previousComparator = TestGoldenComparatorProcess(process, logger: _logger);
|
||||
_previousComparator = TestGoldenComparatorProcess(process);
|
||||
_previousTestUri = testUri;
|
||||
|
||||
return _previousComparator;
|
||||
@@ -81,7 +70,7 @@ class TestGoldenComparator {
|
||||
shellPath,
|
||||
'--disable-observatory',
|
||||
'--non-interactive',
|
||||
'--packages=${_fileSystem.path.join('.dart_tool', 'package_config.json')}',
|
||||
'--packages=${globals.fs.path.join('.dart_tool', 'package_config.json')}',
|
||||
output,
|
||||
];
|
||||
|
||||
@@ -89,7 +78,7 @@ class TestGoldenComparator {
|
||||
// Chrome is the only supported browser currently.
|
||||
'FLUTTER_TEST_BROWSER': 'chrome',
|
||||
};
|
||||
return _processManager.start(command, environment: environment);
|
||||
return globals.processManager.start(command, environment: environment);
|
||||
}
|
||||
|
||||
Future<String> compareGoldens(Uri testUri, Uint8List bytes, Uri goldenKey, bool updateGoldens) async {
|
||||
@@ -111,7 +100,7 @@ class TestGoldenComparator {
|
||||
/// handles communication with the child process.
|
||||
class TestGoldenComparatorProcess {
|
||||
/// Creates a [TestGoldenComparatorProcess] backed by [process].
|
||||
TestGoldenComparatorProcess(this.process, {@required Logger logger}) : _logger = logger {
|
||||
TestGoldenComparatorProcess(this.process) {
|
||||
// Pipe stdout and stderr to printTrace and printError.
|
||||
// Also parse stdout as a stream of JSON objects.
|
||||
streamIterator = StreamIterator<Map<String, dynamic>>(
|
||||
@@ -119,7 +108,7 @@ class TestGoldenComparatorProcess {
|
||||
.transform<String>(utf8.decoder)
|
||||
.transform<String>(const LineSplitter())
|
||||
.where((String line) {
|
||||
logger.printTrace('<<< $line');
|
||||
globals.printTrace('<<< $line');
|
||||
return line.isNotEmpty && line[0] == '{';
|
||||
})
|
||||
.map<dynamic>(jsonDecode)
|
||||
@@ -129,17 +118,16 @@ class TestGoldenComparatorProcess {
|
||||
.transform<String>(utf8.decoder)
|
||||
.transform<String>(const LineSplitter())
|
||||
.forEach((String line) {
|
||||
logger.printError('<<< $line');
|
||||
globals.printError('<<< $line');
|
||||
});
|
||||
}
|
||||
|
||||
final Logger _logger;
|
||||
final Process process;
|
||||
StreamIterator<Map<String, dynamic>> streamIterator;
|
||||
|
||||
Future<void> close() async {
|
||||
await process.stdin.close();
|
||||
process.kill();
|
||||
await process.exitCode;
|
||||
}
|
||||
|
||||
void sendCommand(File imageFile, Uri goldenKey, bool updateGoldens) {
|
||||
@@ -148,7 +136,7 @@ class TestGoldenComparatorProcess {
|
||||
'key': goldenKey.toString(),
|
||||
'update': updateGoldens,
|
||||
});
|
||||
_logger.printTrace('Preparing to send command: $command');
|
||||
globals.printTrace('Preparing to send command: $command');
|
||||
process.stdin.writeln(command);
|
||||
}
|
||||
|
||||
@@ -158,8 +146,8 @@ class TestGoldenComparatorProcess {
|
||||
return streamIterator.current;
|
||||
}
|
||||
|
||||
static String generateBootstrap(File testFile, Uri testUri, {@required Logger logger}) {
|
||||
final File testConfigFile = findTestConfigFile(testFile, logger);
|
||||
static String generateBootstrap(Uri testUri) {
|
||||
final File testConfigFile = findTestConfigFile(globals.fs.file(testUri), globals.logger);
|
||||
// Generate comparator process for the file.
|
||||
return '''
|
||||
import 'dart:convert'; // flutter_ignore: dart_convert_import
|
||||
|
||||
@@ -12,7 +12,6 @@ import 'package:http_multi_server/http_multi_server.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:package_config/package_config.dart';
|
||||
import 'package:pool/pool.dart';
|
||||
import 'package:process/process.dart';
|
||||
import 'package:shelf/shelf.dart' as shelf;
|
||||
import 'package:shelf/shelf_io.dart' as shelf_io;
|
||||
import 'package:shelf_static/shelf_static.dart';
|
||||
@@ -52,7 +51,6 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
@required ChromiumLauncher chromiumLauncher,
|
||||
@required Logger logger,
|
||||
@required Artifacts artifacts,
|
||||
@required ProcessManager processManager,
|
||||
}) : _fileSystem = fileSystem,
|
||||
_flutterToolPackageConfig = flutterToolPackageConfig,
|
||||
_chromiumLauncher = chromiumLauncher,
|
||||
@@ -77,9 +75,6 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
_testGoldenComparator = TestGoldenComparator(
|
||||
shellPath,
|
||||
() => TestCompiler(buildInfo, flutterProject),
|
||||
fileSystem: _fileSystem,
|
||||
logger: _logger,
|
||||
processManager: processManager,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,7 +111,6 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
@required Logger logger,
|
||||
@required ChromiumLauncher chromiumLauncher,
|
||||
@required Artifacts artifacts,
|
||||
@required ProcessManager processManager,
|
||||
}) async {
|
||||
final shelf_io.IOServer server = shelf_io.IOServer(await HttpMultiServer.loopback(0));
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
@@ -144,7 +138,6 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
artifacts: artifacts,
|
||||
logger: logger,
|
||||
nullAssertions: nullAssertions,
|
||||
processManager: processManager,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,6 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
|
||||
logger: globals.logger,
|
||||
fileSystem: globals.fs,
|
||||
artifacts: globals.artifacts,
|
||||
processManager: globals.processManager,
|
||||
chromiumLauncher: ChromiumLauncher(
|
||||
fileSystem: globals.fs,
|
||||
platform: globals.platform,
|
||||
|
||||
Reference in New Issue
Block a user