|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'package:file/memory.dart'; |
5 | 6 | import 'package:flutter_tools/src/asset.dart';
|
6 | 7 | import 'package:flutter_tools/src/base/file_system.dart';
|
| 8 | +import 'package:flutter_tools/src/build_info.dart'; |
7 | 9 | import 'package:flutter_tools/src/cache.dart';
|
8 | 10 | import 'package:flutter_tools/src/globals.dart' as globals;
|
9 | 11 |
|
@@ -81,6 +83,64 @@ void main() {
|
81 | 83 | );
|
82 | 84 | });
|
83 | 85 | });
|
| 86 | + |
| 87 | +const String packageConfig = ''' |
| 88 | +{ |
| 89 | + "configVersion": 2, |
| 90 | + "packages":[ |
| 91 | + { |
| 92 | + "name": "my_package", |
| 93 | + "rootUri": "file:///", |
| 94 | + "packageUri": "lib/", |
| 95 | + "languageVersion": "2.17" |
| 96 | + } |
| 97 | + ] |
| 98 | +} |
| 99 | +'''; |
| 100 | + |
| 101 | +const String pubspecDotYaml = ''' |
| 102 | +name: my_package |
| 103 | +'''; |
| 104 | + |
| 105 | + testUsingContext('Bundles material shaders on non-web platforms', () async { |
| 106 | + final String shaderPath = globals.fs.path.join( |
| 107 | + Cache.flutterRoot!, |
| 108 | + 'packages', 'flutter', 'lib', 'src', 'material', 'shaders', 'ink_sparkle.frag' |
| 109 | + ); |
| 110 | + globals.fs.file(shaderPath).createSync(recursive: true); |
| 111 | + globals.fs.file('.dart_tool/package_config.json') |
| 112 | + ..createSync(recursive: true) |
| 113 | + ..writeAsStringSync(packageConfig); |
| 114 | + globals.fs.file('pubspec.yaml').writeAsStringSync(pubspecDotYaml); |
| 115 | + final AssetBundle asset = AssetBundleFactory.instance.createBundle(); |
| 116 | + |
| 117 | + await asset.build(packagesPath: '.packages', targetPlatform: TargetPlatform.android_arm); |
| 118 | + |
| 119 | + expect(asset.entries.keys, contains('shaders/ink_sparkle.frag')); |
| 120 | + }, overrides: <Type, Generator>{ |
| 121 | + FileSystem: () => MemoryFileSystem.test(), |
| 122 | + ProcessManager: () => FakeProcessManager.empty(), |
| 123 | + }); |
| 124 | + |
| 125 | + testUsingContext('Does not bundles material shaders on web platforms', () async { |
| 126 | + final String shaderPath = globals.fs.path.join( |
| 127 | + Cache.flutterRoot!, |
| 128 | + 'packages', 'flutter', 'lib', 'src', 'material', 'shaders', 'ink_sparkle.frag' |
| 129 | + ); |
| 130 | + globals.fs.file(shaderPath).createSync(recursive: true); |
| 131 | + globals.fs.file('.dart_tool/package_config.json') |
| 132 | + ..createSync(recursive: true) |
| 133 | + ..writeAsStringSync(packageConfig); |
| 134 | + globals.fs.file('pubspec.yaml').writeAsStringSync(pubspecDotYaml); |
| 135 | + final AssetBundle asset = AssetBundleFactory.instance.createBundle(); |
| 136 | + |
| 137 | + await asset.build(packagesPath: '.packages', targetPlatform: TargetPlatform.web_javascript); |
| 138 | + |
| 139 | + expect(asset.entries.keys, isNot(contains('shaders/ink_sparkle.frag'))); |
| 140 | + }, overrides: <Type, Generator>{ |
| 141 | + FileSystem: () => MemoryFileSystem.test(), |
| 142 | + ProcessManager: () => FakeProcessManager.empty(), |
| 143 | + }); |
84 | 144 | }
|
85 | 145 |
|
86 | 146 | Future<String> getValueAsString(String key, AssetBundle asset) async {
|
|
0 commit comments