forked from firka/flutter
This reverts commit 53e6876226.
This commit is contained in:
@@ -98,14 +98,14 @@ class TestGoldenComparator {
|
||||
return _processManager.start(command, environment: environment);
|
||||
}
|
||||
|
||||
Future<String?> compareGoldens(Uri testUri, Uint8List bytes, Uri goldenKey, bool? updateGoldens, Map<String, dynamic>? customProperties) async {
|
||||
Future<String?> compareGoldens(Uri testUri, Uint8List bytes, Uri goldenKey, bool? updateGoldens) async {
|
||||
final File imageFile = await (await tempDir.createTemp('image')).childFile('image').writeAsBytes(bytes);
|
||||
final TestGoldenComparatorProcess? process = await _processForTestFile(testUri);
|
||||
if (process == null) {
|
||||
return 'process was null';
|
||||
}
|
||||
|
||||
process.sendCommand(imageFile, goldenKey, updateGoldens, customProperties);
|
||||
process.sendCommand(imageFile, goldenKey, updateGoldens);
|
||||
|
||||
final Map<String, dynamic> result = await process.getResponse();
|
||||
|
||||
@@ -152,13 +152,11 @@ class TestGoldenComparatorProcess {
|
||||
await process.exitCode;
|
||||
}
|
||||
|
||||
void sendCommand(File imageFile, Uri? goldenKey, bool? updateGoldens, Map<String, dynamic>? customProperties) {
|
||||
void sendCommand(File imageFile, Uri? goldenKey, bool? updateGoldens) {
|
||||
final Object command = jsonEncode(<String, dynamic>{
|
||||
'imageFile': imageFile.path,
|
||||
'key': goldenKey.toString(),
|
||||
'update': updateGoldens,
|
||||
if (customProperties != null)
|
||||
'customProperties': customProperties,
|
||||
});
|
||||
_logger.printTrace('Preparing to send command: $command');
|
||||
process.stdin.writeln(command);
|
||||
@@ -170,22 +168,7 @@ class TestGoldenComparatorProcess {
|
||||
return streamIterator.current;
|
||||
}
|
||||
|
||||
/// Generates the source code for the comparator process for the test file.
|
||||
///
|
||||
/// If a test configuation exists for the tested package, uses its
|
||||
/// implementation. Otherwise, uses the default implementation.
|
||||
static String generateBootstrap(File testFile, Uri testUri, {required Logger logger}) {
|
||||
final File? webTestConfigFile = findWebTestConfigFile(testFile, logger);
|
||||
if (webTestConfigFile != null) {
|
||||
return _generateBootstrapWithWebTestConfig(webTestConfigFile, testFile, testUri);
|
||||
} else {
|
||||
return _generateBasicBootstrap(testFile, testUri, logger: logger);
|
||||
}
|
||||
}
|
||||
|
||||
// Generates the bootstrap used by tests that either don't have a test
|
||||
// configuration file, or don't have a `flutter_web_test_config.dart`.
|
||||
static String _generateBasicBootstrap(File testFile, Uri testUri, {required Logger logger}) {
|
||||
final File? testConfigFile = findTestConfigFile(testFile, logger);
|
||||
// Generate comparator process for the file.
|
||||
return '''
|
||||
@@ -228,19 +211,6 @@ void main() async {
|
||||
}
|
||||
}
|
||||
${testConfigFile != null ? '});' : ''}
|
||||
}
|
||||
''';
|
||||
}
|
||||
|
||||
// Generates the bootstrap used by tests that have a `flutter_web_test_config.dart`.
|
||||
static String _generateBootstrapWithWebTestConfig(File webTestConfigFile, File testFile, Uri testUri) {
|
||||
return '''
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '${Uri.file(webTestConfigFile.path)}' as web_test_config;
|
||||
void main() async {
|
||||
final String testUri = '$testUri';
|
||||
goldenFileComparator = LocalFileComparator(Uri.parse(testUri));
|
||||
await web_test_config.startWebTestHostConfiguration(testUri);
|
||||
}
|
||||
''';
|
||||
}
|
||||
|
||||
@@ -343,9 +343,10 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
}
|
||||
|
||||
Future<shelf.Response> _goldenFileHandler(shelf.Request request) async {
|
||||
if (request.method == 'POST' && request.url.path.contains('flutter_goldens')) {
|
||||
final String requestJson = await request.readAsString();
|
||||
final Map<String, Object?> body = json.decode(requestJson) as Map<String, Object?>;
|
||||
if (request.url.path.contains('flutter_goldens')) {
|
||||
final Map<String, Object?> body = json.decode(await request.readAsString()) as Map<String, Object?>;
|
||||
final Uri goldenKey = Uri.parse(body['key']! as String);
|
||||
final Uri testUri = Uri.parse(body['testUri']! as String);
|
||||
final num width = body['width']! as num;
|
||||
final num height = body['height']! as num;
|
||||
Uint8List bytes;
|
||||
@@ -382,10 +383,7 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
return shelf.Response.ok('Unknown error, bytes is null');
|
||||
}
|
||||
|
||||
final Uri goldenKey = Uri.parse(body['key']! as String);
|
||||
final Uri testUri = Uri.parse(body['testUri']! as String);
|
||||
final Map<String, dynamic>? customProperties = body['customProperties'] as Map<String, dynamic>?;
|
||||
final String? errorMessage = await _testGoldenComparator.compareGoldens(testUri, bytes, goldenKey, updateGoldens, customProperties);
|
||||
final String? errorMessage = await _testGoldenComparator.compareGoldens(testUri, bytes, goldenKey, updateGoldens);
|
||||
return shelf.Response.ok(errorMessage ?? 'true');
|
||||
} else {
|
||||
return shelf.Response.notFound('Not Found');
|
||||
|
||||
@@ -9,36 +9,23 @@ import '../base/logger.dart';
|
||||
/// test harness if it exists in the project directory hierarchy.
|
||||
const String _kTestConfigFileName = 'flutter_test_config.dart';
|
||||
|
||||
/// The name of the web test configuration file that will be discovered by the
|
||||
/// test harness if it exists in the project directory hierarchy.
|
||||
const String _kWebTestConfigFileName = 'flutter_web_test_config.dart';
|
||||
|
||||
/// The name of the file that signals the root of the project and that will
|
||||
/// cause the test harness to stop scanning for configuration files.
|
||||
const String _kProjectRootSentinel = 'pubspec.yaml';
|
||||
|
||||
/// Find the `flutter_test_config.dart` file for a specific test file.
|
||||
File? findTestConfigFile(File testFile, Logger logger) {
|
||||
return _findConfigFile(testFile, _kTestConfigFileName, logger);
|
||||
}
|
||||
|
||||
/// Find the `flutter_web_test_config.dart` file for a specific test file.
|
||||
File? findWebTestConfigFile(File testFile, Logger logger) {
|
||||
return _findConfigFile(testFile, _kWebTestConfigFileName, logger);
|
||||
}
|
||||
|
||||
File? _findConfigFile(File testFile, String configFileName, Logger logger) {
|
||||
File? testConfigFile;
|
||||
Directory directory = testFile.parent;
|
||||
while (directory.path != directory.parent.path) {
|
||||
final File configFile = directory.childFile(configFileName);
|
||||
final File configFile = directory.childFile(_kTestConfigFileName);
|
||||
if (configFile.existsSync()) {
|
||||
logger.printTrace('Discovered $configFileName in ${directory.path}');
|
||||
logger.printTrace('Discovered $_kTestConfigFileName in ${directory.path}');
|
||||
testConfigFile = configFile;
|
||||
break;
|
||||
}
|
||||
if (directory.childFile(_kProjectRootSentinel).existsSync()) {
|
||||
logger.printTrace('Stopping scan for $configFileName; '
|
||||
logger.printTrace('Stopping scan for $_kTestConfigFileName; '
|
||||
'found project root at ${directory.path}');
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -224,8 +224,7 @@ String generateTestEntrypoint({
|
||||
Future<void> main() async {
|
||||
ui.debugEmulateFlutterTesterEnvironment = true;
|
||||
await ui.webOnlyInitializePlatform();
|
||||
webTestUri = Uri.parse('${Uri.file(absolutePath)}');
|
||||
webGoldenComparator = DefaultWebGoldenComparator(webTestUri);
|
||||
webGoldenComparator = DefaultWebGoldenComparator(Uri.parse('${Uri.file(absolutePath)}'));
|
||||
(ui.window as dynamic).debugOverrideDevicePixelRatio(3.0);
|
||||
(ui.window as dynamic).webOnlyDebugPhysicalSizeOverride = const ui.Size(2400, 1800);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user