Skip to content

Commit

Permalink
[flutter_tools] fix test asset loading (#103667)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored May 14, 2022
1 parent d3b80f8 commit 90a592b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 20 deletions.
1 change: 0 additions & 1 deletion dev/automated_tests/flutter_test/package_assets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void main() {
width: 54,
height: 54,
fit: BoxFit.none,
package: 'flutter_automated_tests',
),
);
});
Expand Down
2 changes: 1 addition & 1 deletion dev/automated_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ dependencies:
flutter:
uses-material-design: true
assets:
- icon/
- icon/test.png

# PUBSPEC CHECKSUM: 53c0
5 changes: 4 additions & 1 deletion packages/flutter_tools/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
);
}

String testAssetDirectory;
if (buildTestAssets) {
await _buildTestAsset();
testAssetDirectory = globals.fs.path.
join(flutterProject?.directory?.path ?? '', 'build', 'unit_test_assets');
}

final bool startPaused = boolArgDeprecated('start-paused');
Expand Down Expand Up @@ -444,7 +447,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
machine: machine,
updateGoldens: boolArgDeprecated('update-goldens'),
concurrency: jobs,
buildTestAssets: buildTestAssets,
testAssetDirectory: testAssetDirectory,
flutterProject: flutterProject,
web: stringArgDeprecated('platform') == 'chrome',
randomSeed: stringArgDeprecated('test-randomize-ordering-seed'),
Expand Down
10 changes: 5 additions & 5 deletions packages/flutter_tools/lib/src/test/flutter_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FlutterPlatform installHook({
String precompiledDillPath,
Map<String, String> precompiledDillFiles,
bool updateGoldens = false,
bool buildTestAssets = false,
String testAssetDirectory,
InternetAddressType serverType = InternetAddressType.IPv4,
Uri projectRootDirectory,
FlutterProject flutterProject,
Expand Down Expand Up @@ -86,7 +86,7 @@ FlutterPlatform installHook({
precompiledDillPath: precompiledDillPath,
precompiledDillFiles: precompiledDillFiles,
updateGoldens: updateGoldens,
buildTestAssets: buildTestAssets,
testAssetDirectory: testAssetDirectory,
projectRootDirectory: projectRootDirectory,
flutterProject: flutterProject,
icudtlPath: icudtlPath,
Expand Down Expand Up @@ -280,7 +280,7 @@ class FlutterPlatform extends PlatformPlugin {
this.precompiledDillPath,
this.precompiledDillFiles,
this.updateGoldens,
this.buildTestAssets,
this.testAssetDirectory,
this.projectRootDirectory,
this.flutterProject,
this.icudtlPath,
Expand All @@ -297,7 +297,7 @@ class FlutterPlatform extends PlatformPlugin {
final String precompiledDillPath;
final Map<String, String> precompiledDillFiles;
final bool updateGoldens;
final bool buildTestAssets;
final String testAssetDirectory;
final Uri projectRootDirectory;
final FlutterProject flutterProject;
final String icudtlPath;
Expand Down Expand Up @@ -419,7 +419,7 @@ class FlutterPlatform extends PlatformPlugin {
machine: machine,
debuggingOptions: debuggingOptions,
host: host,
buildTestAssets: buildTestAssets,
testAssetDirectory: testAssetDirectory,
flutterProject: flutterProject,
icudtlPath: icudtlPath,
compileExpression: _compileExpressionService,
Expand Down
12 changes: 7 additions & 5 deletions packages/flutter_tools/lib/src/test/flutter_tester_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FlutterTesterTestDevice extends TestDevice {
@required this.enableObservatory,
@required this.machine,
@required this.host,
@required this.buildTestAssets,
@required this.testAssetDirectory,
@required this.flutterProject,
@required this.icudtlPath,
@required this.compileExpression,
Expand All @@ -66,7 +66,7 @@ class FlutterTesterTestDevice extends TestDevice {
final bool enableObservatory;
final bool machine;
final InternetAddress host;
final bool buildTestAssets;
final String testAssetDirectory;
final FlutterProject flutterProject;
final String icudtlPath;
final CompileExpression compileExpression;
Expand All @@ -93,7 +93,6 @@ class FlutterTesterTestDevice extends TestDevice {
// Let the server choose an unused port.
_server = await bind(host, /*port*/ 0);
logger.printTrace('test $id: test harness socket server is running at port:${_server.port}');

final List<String> command = <String>[
// Until an arm64 flutter tester binary is available, force to run in Rosetta
// to avoid "unexpectedly got a signal in sigtramp" crash.
Expand Down Expand Up @@ -128,7 +127,10 @@ class FlutterTesterTestDevice extends TestDevice {
'--enable-dart-profiling',
'--non-interactive',
'--use-test-fonts',
'--disable-asset-fonts',
'--packages=${debuggingOptions.buildInfo.packagesPath}',
if (testAssetDirectory != null)
'--flutter-assets-dir=$testAssetDirectory',
if (debuggingOptions.nullAssertions)
'--dart-flags=--null_assertions',
...debuggingOptions.dartEntrypointArgs,
Expand All @@ -148,8 +150,8 @@ class FlutterTesterTestDevice extends TestDevice {
'FONTCONFIG_FILE': fontConfigManager.fontConfigFile.path,
'SERVER_PORT': _server.port.toString(),
'APP_NAME': flutterProject?.manifest?.appName ?? '',
if (buildTestAssets)
'UNIT_TEST_ASSETS': fileSystem.path.join(flutterProject?.directory?.path ?? '', 'build', 'unit_test_assets'),
if (testAssetDirectory != null)
'UNIT_TEST_ASSETS': testAssetDirectory,
};

logger.printTrace('test $id: Starting flutter_tester process with command=$command, environment=$environment');
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter_tools/lib/src/test/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class FlutterTestRunner {
bool updateGoldens = false,
TestWatcher watcher,
@required int concurrency,
bool buildTestAssets = false,
String testAssetDirectory,
FlutterProject flutterProject,
String icudtlPath,
Directory coverageDirectory,
Expand Down Expand Up @@ -78,7 +78,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
bool updateGoldens = false,
TestWatcher watcher,
@required int concurrency,
bool buildTestAssets = false,
String testAssetDirectory,
FlutterProject flutterProject,
String icudtlPath,
Directory coverageDirectory,
Expand Down Expand Up @@ -202,7 +202,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
precompiledDillPath: precompiledDillPath,
precompiledDillFiles: precompiledDillFiles,
updateGoldens: updateGoldens,
buildTestAssets: buildTestAssets,
testAssetDirectory: testAssetDirectory,
projectRootDirectory: globals.fs.currentDirectory.uri,
flutterProject: flutterProject,
icudtlPath: icudtlPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
bool updateGoldens = false,
TestWatcher watcher,
int concurrency,
bool buildTestAssets = false,
String testAssetDirectory,
FlutterProject flutterProject,
String icudtlPath,
Directory coverageDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void main() {
precompiledDillPath: 'def',
precompiledDillFiles: expectedPrecompiledDillFiles,
updateGoldens: true,
buildTestAssets: true,
testAssetDirectory: '/build/test',
serverType: InternetAddressType.IPv6,
icudtlPath: 'ghi',
platformPluginRegistration: (FlutterPlatform platform) {
Expand All @@ -114,7 +114,7 @@ void main() {
expect(flutterPlatform.precompiledDillPath, equals('def'));
expect(flutterPlatform.precompiledDillFiles, expectedPrecompiledDillFiles);
expect(flutterPlatform.updateGoldens, equals(true));
expect(flutterPlatform.buildTestAssets, equals(true));
expect(flutterPlatform.testAssetDirectory, '/build/test');
expect(flutterPlatform.icudtlPath, equals('ghi'));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void main() {
'--enable-dart-profiling',
'--non-interactive',
'--use-test-fonts',
'--disable-asset-fonts',
'--packages=.dart_tool/package_config.json',
'example.dill',
], environment: <String, String>{
Expand Down Expand Up @@ -131,6 +132,7 @@ void main() {
'--enable-dart-profiling',
'--non-interactive',
'--use-test-fonts',
'--disable-asset-fonts',
'--packages=.dart_tool/package_config.json',
'example.dill',
], environment: <String, String>{
Expand Down Expand Up @@ -203,6 +205,7 @@ void main() {
'--enable-dart-profiling',
'--non-interactive',
'--use-test-fonts',
'--disable-asset-fonts',
'--packages=.dart_tool/package_config.json',
'--foo',
'--bar',
Expand Down Expand Up @@ -244,6 +247,7 @@ void main() {
'--enable-dart-profiling',
'--non-interactive',
'--use-test-fonts',
'--disable-asset-fonts',
'--packages=.dart_tool/package_config.json',
'example.dill',
],
Expand Down Expand Up @@ -293,7 +297,7 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice {
enableObservatory: enableObservatory,
machine: false,
host: InternetAddress.loopbackIPv6,
buildTestAssets: false,
testAssetDirectory: null,
flutterProject: null,
icudtlPath: null,
compileExpression: null,
Expand Down

0 comments on commit 90a592b

Please sign in to comment.