From a2c9dd8180757f347eedfa08cbb2aa8e292d1209 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Tue, 30 Oct 2018 16:59:49 +0000 Subject: [PATCH] Add a hot reload test that modifies code and verifies it executes (#23725) --- .../test/integration/hot_reload_test.dart | 19 ++++++- .../test_data/hot_reload_project.dart | 54 +++++++++++++++++++ .../test/integration/test_driver.dart | 1 + 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 packages/flutter_tools/test/integration/test_data/hot_reload_project.dart diff --git a/packages/flutter_tools/test/integration/hot_reload_test.dart b/packages/flutter_tools/test/integration/hot_reload_test.dart index 109f4bb12ed..93b2ccf61c5 100644 --- a/packages/flutter_tools/test/integration/hot_reload_test.dart +++ b/packages/flutter_tools/test/integration/hot_reload_test.dart @@ -2,19 +2,21 @@ // 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 'package:flutter_tools/src/base/file_system.dart'; import 'package:vm_service_client/vm_service_client.dart'; import '../src/common.dart'; -import 'test_data/basic_project.dart'; +import 'test_data/hot_reload_project.dart'; import 'test_driver.dart'; import 'test_utils.dart'; void main() { group('hot', () { Directory tempDir; - final BasicProject _project = BasicProject(); + final HotReloadProject _project = HotReloadProject(); FlutterTestDriver _flutter; setUp(() async { @@ -33,6 +35,19 @@ void main() { await _flutter.hotReload(); }); + test('newly added code executes during reload', () async { + await _flutter.run(); + _project.uncommentHotReloadPrint(); + final StringBuffer stdout = StringBuffer(); + final StreamSubscription sub = _flutter.stdout.listen(stdout.writeln); + try { + await _flutter.hotReload(); + expect(stdout.toString(), contains('(((((RELOAD WORKED)))))')); + } finally { + await sub.cancel(); + } + }); + test('restart works without error', () async { await _flutter.run(); await _flutter.hotRestart(); diff --git a/packages/flutter_tools/test/integration/test_data/hot_reload_project.dart b/packages/flutter_tools/test/integration/test_data/hot_reload_project.dart new file mode 100644 index 00000000000..0e99ba3dc06 --- /dev/null +++ b/packages/flutter_tools/test/integration/test_data/hot_reload_project.dart @@ -0,0 +1,54 @@ +// Copyright 2018 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 'package:flutter_tools/src/base/file_system.dart'; + +import '../test_utils.dart'; +import 'test_project.dart'; + +class HotReloadProject extends TestProject { + @override + final String pubspec = ''' + name: test + environment: + sdk: ">=2.0.0-dev.68.0 <3.0.0" + + dependencies: + flutter: + sdk: flutter + '''; + + @override + final String main = r''' + import 'package:flutter/material.dart'; + + void main() => runApp(new MyApp()); + + class MyApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + // Do not remove this line, it's uncommented by a test to verify that hot + // reloading worked. + // printHotReloadWorked(); + + return new MaterialApp( // BREAKPOINT + title: 'Flutter Demo', + home: new Container(), + ); + } + } + + printHotReloadWorked() { + // The call to this function is uncommented by a test to verify that hot + // reloading worked. + print('(((((RELOAD WORKED)))))'); + } + '''; + + void uncommentHotReloadPrint() { + final String newMainContents = main.replaceAll( + '// printHotReloadWorked();', 'printHotReloadWorked();'); + writeFile(fs.path.join(dir.path, 'lib', 'main.dart'), newMainContents); + } +} diff --git a/packages/flutter_tools/test/integration/test_driver.dart b/packages/flutter_tools/test/integration/test_driver.dart index 685dff0b6d7..5322de64bd5 100644 --- a/packages/flutter_tools/test/integration/test_driver.dart +++ b/packages/flutter_tools/test/integration/test_driver.dart @@ -42,6 +42,7 @@ class FlutterTestDriver { VMServiceClient vmService; String get lastErrorInfo => _errorBuffer.toString(); + Stream get stdout => _stdout.stream; int get vmServicePort => _vmServicePort; bool get hasExited => _hasExited;