Unverified Commit fc8dbd3c authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

Move asset_bundle_variant_test over to memory file system (#21426)

parent eb9c975e
...@@ -5,36 +5,43 @@ ...@@ -5,36 +5,43 @@
import 'dart:convert'; import 'dart:convert';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/asset.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'src/common.dart'; import 'src/common.dart';
import 'src/context.dart'; import 'src/context.dart';
import 'src/pubspec_schema.dart';
void main() { void main() {
// These tests do not use a memory file system because we want to ensure that String fixPath(String path) {
// asset bundles work correctly on Windows and Posix systems. // The in-memory file system is strict about slashes on Windows being the
Directory tempDir; // correct way so until https://github.com/google/file.dart/issues/112 is
Directory oldCurrentDir; // fixed we fix them here.
// TODO(dantup): Remove this function once the above issue is fixed and
setUp(() async { // rolls into Flutter.
tempDir = fs.systemTempDirectory.createTempSync('flutter_asset_bundle_variant_test.'); return path?.replaceAll('/', fs.path.separator);
oldCurrentDir = fs.currentDirectory; }
fs.currentDirectory = tempDir;
});
tearDown(() {
fs.currentDirectory = oldCurrentDir;
tryToDelete(tempDir);
});
group('AssetBundle asset variants', () { group('AssetBundle asset variants', () {
FileSystem testFileSystem;
setUp(() async {
testFileSystem = new MemoryFileSystem(
style: platform.isWindows
? FileSystemStyle.windows
: FileSystemStyle.posix,
);
testFileSystem.currentDirectory = testFileSystem.systemTempDirectory.createTempSync('flutter_asset_bundle_variant_test.');
});
testUsingContext('main asset and variants', () async { testUsingContext('main asset and variants', () async {
// Setting flutterRoot here so that it picks up the MemoryFileSystem's // Setting flutterRoot here so that it picks up the MemoryFileSystem's
// path separator. // path separator.
Cache.flutterRoot = getFlutterRoot(); Cache.flutterRoot = getFlutterRoot();
writeEmptySchemaFile(fs);
fs.file('pubspec.yaml') fs.file('pubspec.yaml')
..createSync() ..createSync()
...@@ -58,7 +65,7 @@ flutter: ...@@ -58,7 +65,7 @@ flutter:
'a/b/c/var3/foo', 'a/b/c/var3/foo',
]; ];
for (String asset in assets) { for (String asset in assets) {
fs.file(asset) fs.file(fixPath(asset))
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(asset); ..writeAsStringSync(asset);
} }
...@@ -72,7 +79,7 @@ flutter: ...@@ -72,7 +79,7 @@ flutter:
expect(utf8.decode(await bundle.entries[asset].contentsAsBytes()), asset); expect(utf8.decode(await bundle.entries[asset].contentsAsBytes()), asset);
} }
fs.file('a/b/c/foo').deleteSync(); fs.file(fixPath('a/b/c/foo')).deleteSync();
bundle = AssetBundleFactory.instance.createBundle(); bundle = AssetBundleFactory.instance.createBundle();
await bundle.build(manifestPath: 'pubspec.yaml'); await bundle.build(manifestPath: 'pubspec.yaml');
...@@ -83,7 +90,8 @@ flutter: ...@@ -83,7 +90,8 @@ flutter:
expect(bundle.entries.containsKey(asset), true); expect(bundle.entries.containsKey(asset), true);
expect(utf8.decode(await bundle.entries[asset].contentsAsBytes()), asset); expect(utf8.decode(await bundle.entries[asset].contentsAsBytes()), asset);
} }
}, overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
}); });
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment