bundle_shim_test.dart 2.61 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/bundle.dart';
import 'package:flutter_tools/src/project.dart';
9
import 'package:flutter_tools/src/globals.dart' as globals;
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import 'package:mockito/mockito.dart';

import '../src/common.dart';
import '../src/testbed.dart';

// Tests for the temporary flutter assemble/bundle shim.
void main() {
  Testbed testbed;

  setUp(() {
    testbed = Testbed(overrides: <Type, Generator>{
      BuildSystem: () => MockBuildSystem(),
    });
  });

  test('Copies assets to expected directory after building', () => testbed.run(() async {
26
    when(globals.buildSystem.build(any, any)).thenAnswer((Invocation invocation) async {
27
      final Environment environment = invocation.positionalArguments[1] as Environment;
28 29 30 31 32 33 34 35 36
      environment.outputDir.childFile('kernel_blob.bin').createSync(recursive: true);
      environment.outputDir.childFile('isolate_snapshot_data').createSync();
      environment.outputDir.childFile('vm_snapshot_data').createSync();
      environment.outputDir.childFile('LICENSE').createSync(recursive: true);
      return BuildResult(success: true);
    });
    await buildWithAssemble(
      buildMode: BuildMode.debug,
      flutterProject: FlutterProject.current(),
37
      mainPath: globals.fs.path.join('lib', 'main.dart'),
38 39 40
      outputDir: 'example',
      targetPlatform: TargetPlatform.ios,
      depfilePath: 'example.d',
41
      precompiled: false,
42
      treeShakeIcons: false,
43
    );
44 45 46
    expect(globals.fs.file(globals.fs.path.join('example', 'kernel_blob.bin')).existsSync(), true);
    expect(globals.fs.file(globals.fs.path.join('example', 'LICENSE')).existsSync(), true);
    expect(globals.fs.file(globals.fs.path.join('example.d')).existsSync(), false);
47 48 49
  }));

  test('Handles build system failure', () => testbed.run(() {
50
    when(globals.buildSystem.build(any, any)).thenAnswer((Invocation _) async {
51 52 53 54 55 56 57 58 59 60 61
      return BuildResult(
        success: false,
        exceptions: <String, ExceptionMeasurement>{},
      );
    });

    expect(() => buildWithAssemble(
      buildMode: BuildMode.debug,
      flutterProject: FlutterProject.current(),
      mainPath: 'lib/main.dart',
      outputDir: 'example',
62
      targetPlatform: TargetPlatform.linux_x64,
63
      depfilePath: 'example.d',
64
      precompiled: false,
65
      treeShakeIcons: false,
Dan Field's avatar
Dan Field committed
66
    ), throwsToolExit());
67 68 69 70
  }));
}

class MockBuildSystem extends Mock implements BuildSystem {}