2016-11-15 15:01:00 +00:00
|
|
|
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
import 'dart:convert';
|
2017-06-22 23:45:57 +00:00
|
|
|
|
|
|
|
import 'package:file/file.dart';
|
2018-09-05 18:30:32 +00:00
|
|
|
import 'package:file/memory.dart';
|
2017-06-22 23:45:57 +00:00
|
|
|
|
2016-11-15 15:01:00 +00:00
|
|
|
import 'package:flutter_tools/src/asset.dart';
|
2017-01-07 00:51:44 +00:00
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
2018-09-05 18:30:32 +00:00
|
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
2017-03-10 17:39:01 +00:00
|
|
|
import 'package:flutter_tools/src/cache.dart';
|
2017-06-22 23:45:57 +00:00
|
|
|
|
2017-03-10 17:39:01 +00:00
|
|
|
import 'src/common.dart';
|
2017-06-22 23:45:57 +00:00
|
|
|
import 'src/context.dart';
|
2017-03-10 17:39:01 +00:00
|
|
|
|
2018-02-02 22:27:29 +00:00
|
|
|
void main() {
|
2017-03-10 17:39:01 +00:00
|
|
|
setUpAll(() {
|
|
|
|
Cache.flutterRoot = getFlutterRoot();
|
|
|
|
});
|
|
|
|
|
2016-12-13 21:43:28 +00:00
|
|
|
group('AssetBundle.build', () {
|
2018-09-05 18:30:32 +00:00
|
|
|
FileSystem testFileSystem;
|
2018-01-24 21:16:23 +00:00
|
|
|
|
|
|
|
setUp(() async {
|
2018-09-12 06:29:29 +00:00
|
|
|
testFileSystem = MemoryFileSystem(
|
2018-09-05 18:30:32 +00:00
|
|
|
style: platform.isWindows
|
|
|
|
? FileSystemStyle.windows
|
|
|
|
: FileSystemStyle.posix,
|
|
|
|
);
|
|
|
|
testFileSystem.currentDirectory = testFileSystem.systemTempDirectory.createTempSync('flutter_asset_bundle_test.');
|
2018-01-24 21:16:23 +00:00
|
|
|
});
|
|
|
|
|
2018-01-29 17:40:28 +00:00
|
|
|
testUsingContext('nonempty', () async {
|
|
|
|
final AssetBundle ab = AssetBundleFactory.instance.createBundle();
|
2016-12-13 21:43:28 +00:00
|
|
|
expect(await ab.build(), 0);
|
|
|
|
expect(ab.entries.length, greaterThan(0));
|
2018-09-05 18:30:32 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FileSystem: () => testFileSystem,
|
2016-12-13 21:43:28 +00:00
|
|
|
});
|
2017-09-26 21:14:20 +00:00
|
|
|
|
|
|
|
testUsingContext('empty pubspec', () async {
|
|
|
|
fs.file('pubspec.yaml')
|
|
|
|
..createSync()
|
|
|
|
..writeAsStringSync('');
|
|
|
|
|
2018-01-29 17:40:28 +00:00
|
|
|
final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
|
2017-09-26 21:14:20 +00:00
|
|
|
await bundle.build(manifestPath: 'pubspec.yaml');
|
|
|
|
expect(bundle.entries.length, 1);
|
2018-02-01 06:51:26 +00:00
|
|
|
const String expectedAssetManifest = '{}';
|
2017-09-26 21:14:20 +00:00
|
|
|
expect(
|
2018-03-12 18:06:32 +00:00
|
|
|
utf8.decode(await bundle.entries['AssetManifest.json'].contentsAsBytes()),
|
2017-09-26 21:14:20 +00:00
|
|
|
expectedAssetManifest,
|
|
|
|
);
|
2018-09-05 18:30:32 +00:00
|
|
|
}, overrides: <Type, Generator>{
|
|
|
|
FileSystem: () => testFileSystem,
|
2018-01-24 21:16:23 +00:00
|
|
|
});
|
2016-12-13 21:43:28 +00:00
|
|
|
});
|
2017-06-22 23:45:57 +00:00
|
|
|
|
2016-11-15 15:01:00 +00:00
|
|
|
}
|