flutter_attach_test.dart 2.04 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
import 'dart:io';

7 8 9
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';

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

void main() {
16
  FlutterRunTestDriver _flutterRun, _flutterAttach;
17
  final BasicProject _project = BasicProject();
18
  Directory tempDir;
19 20

  setUp(() async {
21
    tempDir = createResolvedTempDirectorySync('attach_test.');
22
    await _project.setUpIn(tempDir);
23 24
    _flutterRun = FlutterRunTestDriver(tempDir,    logPrefix: '   RUN  ');
    _flutterAttach = FlutterRunTestDriver(tempDir, logPrefix: 'ATTACH  ');
25 26 27
  });

  tearDown(() async {
28
    await _flutterAttach.detach();
29 30
    await _flutterRun.stop();
    tryToDelete(tempDir);
31 32
  });

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  test('writes pid-file', () async {
    final File pidFile = tempDir.childFile('test.pid');
    await _flutterRun.run(withDebugger: true);
    await _flutterAttach.attach(
      _flutterRun.vmServicePort,
      pidFile: pidFile,
    );
    expect(pidFile.existsSync(), isTrue);
  });

  test('can hot reload', () async {
    await _flutterRun.run(withDebugger: true);
    await _flutterAttach.attach(_flutterRun.vmServicePort);
    await _flutterAttach.hotReload();
  });

  test('can detach, reattach, hot reload', () async {
    await _flutterRun.run(withDebugger: true);
    await _flutterAttach.attach(_flutterRun.vmServicePort);
    await _flutterAttach.detach();
    await _flutterAttach.attach(_flutterRun.vmServicePort);
    await _flutterAttach.hotReload();
  });

  test('killing process behaves the same as detach ', () async {
    await _flutterRun.run(withDebugger: true);
    await _flutterAttach.attach(_flutterRun.vmServicePort);
    await _flutterAttach.quit();
    _flutterAttach = FlutterRunTestDriver(tempDir, logPrefix: 'ATTACH-2');
    await _flutterAttach.attach(_flutterRun.vmServicePort);
    await _flutterAttach.hotReload();
  });
65
}