stateless_stateful_hot_reload_test.dart 1.44 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 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import 'dart:async';

import 'package:file/file.dart';

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

// This test verifies that we can hot reload a stateless widget into a
// stateful one and back.
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();
    tryToDelete(tempDir);
  });

34
  testWithoutContext('Can switch between stateless and stateful', () async {
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    await _flutter.run();
    await _flutter.hotReload();
    final StringBuffer stdout = StringBuffer();
    final StreamSubscription<String> subscription = _flutter.stdout.listen(stdout.writeln);

    // switch to stateful.
    _project.toggleState();
    await _flutter.hotReload();

    // switch to stateless.
    _project.toggleState();
    await _flutter.hotReload();

    final String logs = stdout.toString();

    expect(logs, contains('STATELESS'));
    expect(logs, contains('STATEFUL'));
    await subscription.cancel();
  });
}