lifetime_test.dart 1.45 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// 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
import 'package:file/file.dart';

9
import '../src/common.dart';
10 11
import 'test_data/basic_project.dart';
import 'test_driver.dart';
12
import 'test_utils.dart';
13 14

/// This duration is arbitrary but is ideally:
15 16
/// a) Long enough to ensure that if the app is crashing at startup, we notice.
/// b) As short as possible, to avoid inflating build times.
17
const Duration requiredLifespan = Duration(seconds: 5);
18 19

void main() {
20 21
  final BasicProject project = BasicProject();
  FlutterRunTestDriver flutter;
22 23 24 25
  Directory tempDir;

  setUp(() async {
    tempDir = createResolvedTempDirectorySync('lifetime_test.');
26 27
    await project.setUpIn(tempDir);
    flutter = FlutterRunTestDriver(tempDir);
28 29 30
  });

  tearDown(() async {
31
    await flutter.stop();
32 33 34
    tryToDelete(tempDir);
  });

35
  testWithoutContext('flutter run does not terminate when a debugger is attached', () async {
36
    await flutter.run(withDebugger: true);
37
    await Future<void>.delayed(requiredLifespan);
38
    expect(flutter.hasExited, equals(false));
39 40
  });

41
  testWithoutContext('flutter run does not terminate when a debugger is attached and pause-on-exceptions', () async {
42
    await flutter.run(withDebugger: true, pauseOnExceptions: true);
43
    await Future<void>.delayed(requiredLifespan);
44
    expect(flutter.hasExited, equals(false));
45
  });
46
}