asset_bundle_test.dart 1.8 KB
Newer Older
1 2 3 4 5
// 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';
6 7

import 'package:file/file.dart';
8
import 'package:file/memory.dart';
9

10
import 'package:flutter_tools/src/asset.dart';
11
import 'package:flutter_tools/src/base/file_system.dart';
12
import 'package:flutter_tools/src/base/platform.dart';
13
import 'package:flutter_tools/src/cache.dart';
14

15
import 'src/common.dart';
16
import 'src/context.dart';
17

18
void main() {
19 20 21 22
  setUpAll(() {
    Cache.flutterRoot = getFlutterRoot();
  });

23
  group('AssetBundle.build', () {
24
    FileSystem testFileSystem;
25 26

    setUp(() async {
27
      testFileSystem = MemoryFileSystem(
28 29 30 31 32
        style: platform.isWindows
          ? FileSystemStyle.windows
          : FileSystemStyle.posix,
      );
      testFileSystem.currentDirectory = testFileSystem.systemTempDirectory.createTempSync('flutter_asset_bundle_test.');
33 34
    });

35 36
    testUsingContext('nonempty', () async {
      final AssetBundle ab = AssetBundleFactory.instance.createBundle();
37 38
      expect(await ab.build(), 0);
      expect(ab.entries.length, greaterThan(0));
39 40
    }, overrides: <Type, Generator>{
      FileSystem: () => testFileSystem,
41
    });
42 43 44 45 46 47

    testUsingContext('empty pubspec', () async {
      fs.file('pubspec.yaml')
        ..createSync()
        ..writeAsStringSync('');

48
      final AssetBundle bundle = AssetBundleFactory.instance.createBundle();
49 50
      await bundle.build(manifestPath: 'pubspec.yaml');
      expect(bundle.entries.length, 1);
51
      const String expectedAssetManifest = '{}';
52
      expect(
53
        utf8.decode(await bundle.entries['AssetManifest.json'].contentsAsBytes()),
54 55
        expectedAssetManifest,
      );
56 57
    }, overrides: <Type, Generator>{
      FileSystem: () => testFileSystem,
58
    });
59
  });
60

61
}