[flutter_tools] surface missing assets originating package (#55701)

This commit is contained in:
Jonah Williams
2020-05-16 14:52:04 -07:00
committed by GitHub
parent b026c3667a
commit afdc440840
3 changed files with 132 additions and 20 deletions

View File

@@ -173,7 +173,8 @@ $assetsSection
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('One asset is bundled when the package has and lists one asset its pubspec', () async {
testUsingContext('One asset is bundled when the package has and lists one '
'asset its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs);
@@ -201,7 +202,8 @@ $assetsSection
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext("One asset is bundled when the package has one asset, listed in the app's pubspec", () async {
testUsingContext('One asset is bundled when the package has one asset, '
"listed in the app's pubspec", () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs);
@@ -229,7 +231,8 @@ $assetsSection
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('One asset and its variant are bundled when the package has an asset and a variant, and lists the asset in its pubspec', () async {
testUsingContext('One asset and its variant are bundled when the package '
'has an asset and a variant, and lists the asset in its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs);
@@ -257,7 +260,8 @@ $assetsSection
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('One asset and its variant are bundled when the package has an asset and a variant, and the app lists the asset in its pubspec', () async {
testUsingContext('One asset and its variant are bundled when the package '
'has an asset and a variant, and the app lists the asset in its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs);
@@ -288,7 +292,8 @@ $assetsSection
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Two assets are bundled when the package has and lists two assets in its pubspec', () async {
testUsingContext('Two assets are bundled when the package has and lists '
'two assets in its pubspec', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs);
@@ -436,7 +441,8 @@ $assetsSection
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('One asset is bundled when the app depends on a package, listing in its pubspec an asset from another package', () async {
testUsingContext('One asset is bundled when the app depends on a package, '
'listing in its pubspec an asset from another package', () async {
establishFlutterRoot();
writeEmptySchemaFile(globals.fs);
writePubspecFile(
@@ -584,7 +590,9 @@ $assetsSection
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml');
assert(bundle.entries['AssetManifest.json'] == null,'Invalid pubspec.yaml should not generate AssetManifest.json' );
expect(bundle.entries['AssetManifest.json'], isNull,
reason: 'Invalid pubspec.yaml should not generate AssetManifest.json' );
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager.any(),

View File

@@ -265,6 +265,63 @@ flutter:
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
});
testUsingContext('reports package that causes asset bundle error when it is '
'a dependency', () async {
globals.fs.file('.packages').writeAsStringSync(r'''
example:lib/
foo:foo/lib/
''');
globals.fs.file(globals.fs.path.join('assets', 'foo', 'bar.txt'))
.createSync(recursive: true);
globals.fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
dependencies:
foo: any
''');
globals.fs.file('foo/pubspec.yaml')
..createSync(recursive: true)
..writeAsStringSync(r'''
name: foo
flutter:
assets:
- bar.txt
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 1);
expect(testLogger.errorText, contains('This asset was included from package foo'));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
});
testUsingContext('does not report package that causes asset bundle error '
'when it is from own pubspec', () async {
globals.fs.file('.packages').writeAsStringSync(r'''
example:lib/
''');
globals.fs.file('pubspec.yaml')
..createSync()
..writeAsStringSync(r'''
name: example
flutter:
assets:
- bar.txt
''');
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
expect(await bundle.build(manifestPath: 'pubspec.yaml'), 1);
expect(testLogger.errorText, isNot(contains('This asset was included from')));
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
});
}
class MockDirectory extends Mock implements Directory {}