Skip to content

Commit 90a592b

Browse files
author
Jonah Williams
authored
[flutter_tools] fix test asset loading (#103667)
1 parent d3b80f8 commit 90a592b

File tree

9 files changed

+28
-20
lines changed

9 files changed

+28
-20
lines changed

dev/automated_tests/flutter_test/package_assets_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ void main() {
1313
width: 54,
1414
height: 54,
1515
fit: BoxFit.none,
16-
package: 'flutter_automated_tests',
1716
),
1817
);
1918
});

dev/automated_tests/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ dependencies:
7070
flutter:
7171
uses-material-design: true
7272
assets:
73-
- icon/
73+
- icon/test.png
7474

7575
# PUBSPEC CHECKSUM: 53c0

packages/flutter_tools/lib/src/commands/test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,11 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
320320
);
321321
}
322322

323+
String testAssetDirectory;
323324
if (buildTestAssets) {
324325
await _buildTestAsset();
326+
testAssetDirectory = globals.fs.path.
327+
join(flutterProject?.directory?.path ?? '', 'build', 'unit_test_assets');
325328
}
326329

327330
final bool startPaused = boolArgDeprecated('start-paused');
@@ -444,7 +447,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
444447
machine: machine,
445448
updateGoldens: boolArgDeprecated('update-goldens'),
446449
concurrency: jobs,
447-
buildTestAssets: buildTestAssets,
450+
testAssetDirectory: testAssetDirectory,
448451
flutterProject: flutterProject,
449452
web: stringArgDeprecated('platform') == 'chrome',
450453
randomSeed: stringArgDeprecated('test-randomize-ordering-seed'),

packages/flutter_tools/lib/src/test/flutter_platform.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ FlutterPlatform installHook({
5555
String precompiledDillPath,
5656
Map<String, String> precompiledDillFiles,
5757
bool updateGoldens = false,
58-
bool buildTestAssets = false,
58+
String testAssetDirectory,
5959
InternetAddressType serverType = InternetAddressType.IPv4,
6060
Uri projectRootDirectory,
6161
FlutterProject flutterProject,
@@ -86,7 +86,7 @@ FlutterPlatform installHook({
8686
precompiledDillPath: precompiledDillPath,
8787
precompiledDillFiles: precompiledDillFiles,
8888
updateGoldens: updateGoldens,
89-
buildTestAssets: buildTestAssets,
89+
testAssetDirectory: testAssetDirectory,
9090
projectRootDirectory: projectRootDirectory,
9191
flutterProject: flutterProject,
9292
icudtlPath: icudtlPath,
@@ -280,7 +280,7 @@ class FlutterPlatform extends PlatformPlugin {
280280
this.precompiledDillPath,
281281
this.precompiledDillFiles,
282282
this.updateGoldens,
283-
this.buildTestAssets,
283+
this.testAssetDirectory,
284284
this.projectRootDirectory,
285285
this.flutterProject,
286286
this.icudtlPath,
@@ -297,7 +297,7 @@ class FlutterPlatform extends PlatformPlugin {
297297
final String precompiledDillPath;
298298
final Map<String, String> precompiledDillFiles;
299299
final bool updateGoldens;
300-
final bool buildTestAssets;
300+
final String testAssetDirectory;
301301
final Uri projectRootDirectory;
302302
final FlutterProject flutterProject;
303303
final String icudtlPath;
@@ -419,7 +419,7 @@ class FlutterPlatform extends PlatformPlugin {
419419
machine: machine,
420420
debuggingOptions: debuggingOptions,
421421
host: host,
422-
buildTestAssets: buildTestAssets,
422+
testAssetDirectory: testAssetDirectory,
423423
flutterProject: flutterProject,
424424
icudtlPath: icudtlPath,
425425
compileExpression: _compileExpressionService,

packages/flutter_tools/lib/src/test/flutter_tester_device.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class FlutterTesterTestDevice extends TestDevice {
3939
@required this.enableObservatory,
4040
@required this.machine,
4141
@required this.host,
42-
@required this.buildTestAssets,
42+
@required this.testAssetDirectory,
4343
@required this.flutterProject,
4444
@required this.icudtlPath,
4545
@required this.compileExpression,
@@ -66,7 +66,7 @@ class FlutterTesterTestDevice extends TestDevice {
6666
final bool enableObservatory;
6767
final bool machine;
6868
final InternetAddress host;
69-
final bool buildTestAssets;
69+
final String testAssetDirectory;
7070
final FlutterProject flutterProject;
7171
final String icudtlPath;
7272
final CompileExpression compileExpression;
@@ -93,7 +93,6 @@ class FlutterTesterTestDevice extends TestDevice {
9393
// Let the server choose an unused port.
9494
_server = await bind(host, /*port*/ 0);
9595
logger.printTrace('test $id: test harness socket server is running at port:${_server.port}');
96-
9796
final List<String> command = <String>[
9897
// Until an arm64 flutter tester binary is available, force to run in Rosetta
9998
// to avoid "unexpectedly got a signal in sigtramp" crash.
@@ -128,7 +127,10 @@ class FlutterTesterTestDevice extends TestDevice {
128127
'--enable-dart-profiling',
129128
'--non-interactive',
130129
'--use-test-fonts',
130+
'--disable-asset-fonts',
131131
'--packages=${debuggingOptions.buildInfo.packagesPath}',
132+
if (testAssetDirectory != null)
133+
'--flutter-assets-dir=$testAssetDirectory',
132134
if (debuggingOptions.nullAssertions)
133135
'--dart-flags=--null_assertions',
134136
...debuggingOptions.dartEntrypointArgs,
@@ -148,8 +150,8 @@ class FlutterTesterTestDevice extends TestDevice {
148150
'FONTCONFIG_FILE': fontConfigManager.fontConfigFile.path,
149151
'SERVER_PORT': _server.port.toString(),
150152
'APP_NAME': flutterProject?.manifest?.appName ?? '',
151-
if (buildTestAssets)
152-
'UNIT_TEST_ASSETS': fileSystem.path.join(flutterProject?.directory?.path ?? '', 'build', 'unit_test_assets'),
153+
if (testAssetDirectory != null)
154+
'UNIT_TEST_ASSETS': testAssetDirectory,
153155
};
154156

155157
logger.printTrace('test $id: Starting flutter_tester process with command=$command, environment=$environment');

packages/flutter_tools/lib/src/test/runner.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ abstract class FlutterTestRunner {
4242
bool updateGoldens = false,
4343
TestWatcher watcher,
4444
@required int concurrency,
45-
bool buildTestAssets = false,
45+
String testAssetDirectory,
4646
FlutterProject flutterProject,
4747
String icudtlPath,
4848
Directory coverageDirectory,
@@ -78,7 +78,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
7878
bool updateGoldens = false,
7979
TestWatcher watcher,
8080
@required int concurrency,
81-
bool buildTestAssets = false,
81+
String testAssetDirectory,
8282
FlutterProject flutterProject,
8383
String icudtlPath,
8484
Directory coverageDirectory,
@@ -202,7 +202,7 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
202202
precompiledDillPath: precompiledDillPath,
203203
precompiledDillFiles: precompiledDillFiles,
204204
updateGoldens: updateGoldens,
205-
buildTestAssets: buildTestAssets,
205+
testAssetDirectory: testAssetDirectory,
206206
projectRootDirectory: globals.fs.currentDirectory.uri,
207207
flutterProject: flutterProject,
208208
icudtlPath: icudtlPath,

packages/flutter_tools/test/commands.shard/hermetic/test_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
754754
bool updateGoldens = false,
755755
TestWatcher watcher,
756756
int concurrency,
757-
bool buildTestAssets = false,
757+
String testAssetDirectory,
758758
FlutterProject flutterProject,
759759
String icudtlPath,
760760
Directory coverageDirectory,

packages/flutter_tools/test/general.shard/flutter_platform_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void main() {
9595
precompiledDillPath: 'def',
9696
precompiledDillFiles: expectedPrecompiledDillFiles,
9797
updateGoldens: true,
98-
buildTestAssets: true,
98+
testAssetDirectory: '/build/test',
9999
serverType: InternetAddressType.IPv6,
100100
icudtlPath: 'ghi',
101101
platformPluginRegistration: (FlutterPlatform platform) {
@@ -114,7 +114,7 @@ void main() {
114114
expect(flutterPlatform.precompiledDillPath, equals('def'));
115115
expect(flutterPlatform.precompiledDillFiles, expectedPrecompiledDillFiles);
116116
expect(flutterPlatform.updateGoldens, equals(true));
117-
expect(flutterPlatform.buildTestAssets, equals(true));
117+
expect(flutterPlatform.testAssetDirectory, '/build/test');
118118
expect(flutterPlatform.icudtlPath, equals('ghi'));
119119
});
120120
});

packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void main() {
8787
'--enable-dart-profiling',
8888
'--non-interactive',
8989
'--use-test-fonts',
90+
'--disable-asset-fonts',
9091
'--packages=.dart_tool/package_config.json',
9192
'example.dill',
9293
], environment: <String, String>{
@@ -131,6 +132,7 @@ void main() {
131132
'--enable-dart-profiling',
132133
'--non-interactive',
133134
'--use-test-fonts',
135+
'--disable-asset-fonts',
134136
'--packages=.dart_tool/package_config.json',
135137
'example.dill',
136138
], environment: <String, String>{
@@ -203,6 +205,7 @@ void main() {
203205
'--enable-dart-profiling',
204206
'--non-interactive',
205207
'--use-test-fonts',
208+
'--disable-asset-fonts',
206209
'--packages=.dart_tool/package_config.json',
207210
'--foo',
208211
'--bar',
@@ -244,6 +247,7 @@ void main() {
244247
'--enable-dart-profiling',
245248
'--non-interactive',
246249
'--use-test-fonts',
250+
'--disable-asset-fonts',
247251
'--packages=.dart_tool/package_config.json',
248252
'example.dill',
249253
],
@@ -293,7 +297,7 @@ class TestFlutterTesterDevice extends FlutterTesterTestDevice {
293297
enableObservatory: enableObservatory,
294298
machine: false,
295299
host: InternetAddress.loopbackIPv6,
296-
buildTestAssets: false,
300+
testAssetDirectory: null,
297301
flutterProject: null,
298302
icudtlPath: null,
299303
compileExpression: null,

0 commit comments

Comments
 (0)