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

9 10 11
import '../integration.shard/test_data/hot_reload_project.dart';
import '../integration.shard/test_driver.dart';
import '../integration.shard/test_utils.dart';
12 13
import '../src/common.dart';

14 15 16 17 18 19 20 21 22 23 24
import 'test_data/hot_reload_index_html_samples.dart';

void main() async {
  await _testProject(HotReloadProject()); // default
  await _testProject(HotReloadProject(indexHtml: indexHtmlFlutterJsCallback), name: 'flutter.js (callback)');
  await _testProject(HotReloadProject(indexHtml: indexHtmlFlutterJsPromisesFull), name: 'flutter.js (promises)');
  await _testProject(HotReloadProject(indexHtml: indexHtmlFlutterJsPromisesShort), name: 'flutter.js (promises, short)');
  await _testProject(HotReloadProject(indexHtml: indexHtmlNoFlutterJs), name: 'No flutter.js');
}

Future<void> _testProject(HotReloadProject project, {String name = 'Default'}) async {
25 26
  late Directory tempDir;
  late FlutterRunTestDriver flutter;
27

28 29
  final String testName = 'Hot reload (index.html: $name)';

30 31 32 33 34 35 36
  setUp(() async {
    tempDir = createResolvedTempDirectorySync('hot_reload_test.');
    await project.setUpIn(tempDir);
    flutter = FlutterRunTestDriver(tempDir);
  });

  tearDown(() async {
37 38
    await flutter.stop();
    await flutter.done;
39 40 41
    tryToDelete(tempDir);
  });

42
  testWithoutContext('$testName: hot restart works without error', () async {
43
    flutter.stdout.listen(printOnFailure);
44
    await flutter.run(chrome: true, additionalCommandArgs: <String>['--verbose', '--web-renderer=html']);
45
    await flutter.hotRestart();
46
  });
47

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

66
  testWithoutContext('$testName: newly added code executes during hot restart - canvaskit', () async {
67 68
    final Completer<void> completer = Completer<void>();
    final StreamSubscription<String> subscription = flutter.stdout.listen((String line) {
69
      printOnFailure(line);
70 71 72 73
      if (line.contains('(((((RELOAD WORKED)))))')) {
        completer.complete();
      }
    });
74 75
    await flutter.run(chrome: true,
      additionalCommandArgs: <String>['--dart-define=FLUTTER_WEB_USE_SKIA=true', '--verbose']);
76 77 78
    project.uncommentHotReloadPrint();
    try {
      await flutter.hotRestart();
79
      await completer.future.timeout(const Duration(seconds: 15));
80 81 82
    } finally {
      await subscription.cancel();
    }
83
  }, skip: true); // Skipped for https://github.com/flutter/flutter/issues/110879.
84
}