stateless_stateful_hot_reload_test.dart 1.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 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/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() {
17
  late Directory tempDir;
18
  final HotReloadProject project = HotReloadProject();
19
  late FlutterRunTestDriver flutter;
20 21 22

  setUp(() async {
    tempDir = createResolvedTempDirectorySync('hot_reload_test.');
23 24
    await project.setUpIn(tempDir);
    flutter = FlutterRunTestDriver(tempDir);
25 26 27
  });

  tearDown(() async {
28
    await flutter.stop();
29 30 31
    tryToDelete(tempDir);
  });

32
  testWithoutContext('Can switch between stateless and stateful', () async {
33 34
    await flutter.run();
    await flutter.hotReload();
35
    final StringBuffer stdout = StringBuffer();
36
    final StreamSubscription<String> subscription = flutter.stdout.listen(stdout.writeln);
37 38

    // switch to stateful.
39 40
    project.toggleState();
    await flutter.hotReload();
41 42

    // switch to stateless.
43 44
    project.toggleState();
    await flutter.hotReload();
45 46 47 48 49 50 51 52

    final String logs = stdout.toString();

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