hot_reload_web_test.dart 2.4 KB
Newer Older
1 2 3 4
// 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.

5 6
// @dart = 2.8

7 8 9 10
import 'dart:async';

import 'package:file/file.dart';

11 12 13
import '../integration.shard/test_data/hot_reload_project.dart';
import '../integration.shard/test_driver.dart';
import '../integration.shard/test_utils.dart';
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import '../src/common.dart';

void main() {
  Directory tempDir;
  final HotReloadProject project = HotReloadProject();
  FlutterRunTestDriver flutter;

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

  tearDown(() async {
    await flutter?.stop();
29
    await flutter?.done;
30 31 32 33
    tryToDelete(tempDir);
  });

  testWithoutContext('hot restart works without error', () async {
34
    await flutter.run(chrome: true, additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
35
    await flutter.hotRestart();
36
  });
37 38 39 40 41 42 43 44

  testWithoutContext('newly added code executes during hot restart', () async {
    final Completer<void> completer = Completer<void>();
    final StreamSubscription<String> subscription = flutter.stdout.listen((String line) {
      if (line.contains('(((((RELOAD WORKED)))))')) {
        completer.complete();
      }
    });
45
    await flutter.run(chrome: true, additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
46 47 48
    project.uncommentHotReloadPrint();
    try {
      await flutter.hotRestart();
49
      await completer.future.timeout(const Duration(seconds: 15));
50 51 52
    } finally {
      await subscription.cancel();
    }
53
  });
54 55 56 57 58 59 60 61

  testWithoutContext('newly added code executes during hot restart - canvaskit', () async {
    final Completer<void> completer = Completer<void>();
    final StreamSubscription<String> subscription = flutter.stdout.listen((String line) {
      if (line.contains('(((((RELOAD WORKED)))))')) {
        completer.complete();
      }
    });
62 63
    await flutter.run(chrome: true,
      additionalCommandArgs: <String>['--dart-define=FLUTTER_WEB_USE_SKIA=true', '--verbose']);
64 65 66
    project.uncommentHotReloadPrint();
    try {
      await flutter.hotRestart();
67
      await completer.future.timeout(const Duration(seconds: 15));
68 69 70
    } finally {
      await subscription.cancel();
    }
71
  }, skip: true); // Skipping for https://github.com/flutter/flutter/issues/85043.
72
}