hot_reload_with_asset_test.dart 2.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2014 The Flutter 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:async';

import 'package:file/file.dart';

import '../src/common.dart';
import 'test_data/hot_reload_with_asset.dart';
import 'test_driver.dart';
import 'test_utils.dart';

void main() {
15
  late Directory tempDir;
16
  final HotReloadWithAssetProject project = HotReloadWithAssetProject();
17
  late FlutterRunTestDriver flutter;
18 19 20 21 22 23 24 25

  setUp(() async {
    tempDir = createResolvedTempDirectorySync('hot_reload_test.');
    await project.setUpIn(tempDir);
    flutter = FlutterRunTestDriver(tempDir);
  });

  tearDown(() async {
26
    await flutter.stop();
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    tryToDelete(tempDir);
  });

  testWithoutContext('hot reload does not need to sync assets on the first reload', () async {
    final Completer<void> onFirstLoad = Completer<void>();
    final Completer<void> onSecondLoad = Completer<void>();

    flutter.stdout.listen((String line) {
      // If the asset fails to load, this message will be printed instead.
      // this indicates that the devFS was not able to locate the asset
      // after the hot reload.
      if (line.contains('FAILED TO LOAD')) {
        fail('Did not load asset: $line');
      }
      if (line.contains('LOADED DATA')) {
        onFirstLoad.complete();
      }
      if (line.contains('SECOND DATA')) {
        onSecondLoad.complete();
      }
    });
48
    flutter.stdout.listen(printOnFailure);
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    await flutter.run();
    await onFirstLoad.future;

    project.uncommentHotReloadPrint();
    await flutter.hotReload();
    await onSecondLoad.future;
  });

  testWithoutContext('hot restart does not need to sync assets on the first reload', () async {
    final Completer<void> onFirstLoad = Completer<void>();
    final Completer<void> onSecondLoad = Completer<void>();

    flutter.stdout.listen((String line) {
      // If the asset fails to load, this message will be printed instead.
      // this indicates that the devFS was not able to locate the asset
      // after the hot reload.
      if (line.contains('FAILED TO LOAD')) {
        fail('Did not load asset: $line');
      }
      if (line.contains('LOADED DATA')) {
        onFirstLoad.complete();
      }
      if (line.contains('SECOND DATA')) {
        onSecondLoad.complete();
      }
    });
75
    flutter.stdout.listen(printOnFailure);
76 77 78 79 80 81 82 83
    await flutter.run();
    await onFirstLoad.future;

    project.uncommentHotReloadPrint();
    await flutter.hotRestart();
    await onSecondLoad.future;
  });
}