flutter_attach_test.dart 2.22 KB
Newer Older
1 2 3 4 5 6 7
// 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:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';

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

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

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

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

  group('attached process', () {
32 33 34 35 36 37 38 39 40
    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);
    });
41
    test('can hot reload', () async {
42 43 44 45
      await _flutterRun.run(withDebugger: true);
      await _flutterAttach.attach(_flutterRun.vmServicePort);
      await _flutterAttach.hotReload();
    });
46 47 48 49 50 51 52 53 54 55 56
    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();
57
      _flutterAttach = FlutterRunTestDriver(tempDir, logPrefix: 'ATTACH-2');
58 59 60
      await _flutterAttach.attach(_flutterRun.vmServicePort);
      await _flutterAttach.hotReload();
    });
61
  }, timeout: const Timeout.factor(10)); // The DevFS sync takes a really long time, so these tests can be slow.
62
}