flutter_attach_test.dart 2.53 KB
Newer Older
1 2 3 4
// 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.

5 6 7 8 9
// Integration tests which invoke flutter instead of unit testing the code
// will not produce meaningful coverage information - we can measure coverage
// from the isolate running the test, but not from the isolate started via
// the command line process.
@Tags(<String>['no_coverage'])
10 11 12
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';

13
import '../src/common.dart';
14 15
import 'test_data/basic_project.dart';
import 'test_driver.dart';
16
import 'test_utils.dart';
17 18

void main() {
19
  FlutterRunTestDriver _flutterRun, _flutterAttach;
20
  final BasicProject _project = BasicProject();
21
  Directory tempDir;
22 23

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

  tearDown(() async {
31
    await _flutterAttach.detach();
32 33
    await _flutterRun.stop();
    tryToDelete(tempDir);
34 35 36
  });

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