2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2018-07-19 12:38:29 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-10-18 23:35:39 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2018-07-19 12:38:29 +00:00
|
|
|
import 'package:file/file.dart';
|
|
|
|
|
2018-08-15 03:33:58 +00:00
|
|
|
import '../src/common.dart';
|
2018-07-19 12:38:29 +00:00
|
|
|
import 'test_data/basic_project.dart';
|
|
|
|
import 'test_driver.dart';
|
2018-10-19 11:51:31 +00:00
|
|
|
import 'test_utils.dart';
|
2018-07-19 12:38:29 +00:00
|
|
|
|
|
|
|
void main() {
|
2018-11-19 08:25:42 +00:00
|
|
|
FlutterRunTestDriver _flutterRun, _flutterAttach;
|
2018-09-12 06:29:29 +00:00
|
|
|
final BasicProject _project = BasicProject();
|
2018-08-17 20:17:23 +00:00
|
|
|
Directory tempDir;
|
2018-07-19 12:38:29 +00:00
|
|
|
|
|
|
|
setUp(() async {
|
2019-01-17 11:29:18 +00:00
|
|
|
tempDir = createResolvedTempDirectorySync('attach_test.');
|
2018-07-19 12:38:29 +00:00
|
|
|
await _project.setUpIn(tempDir);
|
2019-01-19 08:31:05 +00:00
|
|
|
_flutterRun = FlutterRunTestDriver(tempDir, logPrefix: ' RUN ');
|
2020-07-29 17:05:40 +00:00
|
|
|
_flutterAttach = FlutterRunTestDriver(
|
|
|
|
tempDir,
|
|
|
|
logPrefix: 'ATTACH ',
|
|
|
|
// Only one DDS instance can be connected to the VM service at a time.
|
|
|
|
// DDS can also only initialize if the VM service doesn't have any existing
|
|
|
|
// clients, so we'll just let _flutterRun be responsible for spawning DDS.
|
|
|
|
spawnDdsInstance: false,
|
|
|
|
);
|
2018-07-19 12:38:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
2018-09-06 14:26:55 +00:00
|
|
|
await _flutterAttach.detach();
|
2018-08-17 20:17:23 +00:00
|
|
|
await _flutterRun.stop();
|
|
|
|
tryToDelete(tempDir);
|
2018-07-19 12:38:29 +00:00
|
|
|
});
|
|
|
|
|
2020-09-08 22:56:00 +00:00
|
|
|
testWithoutContext('writes pid-file', () async {
|
2019-10-18 23:35:39 +00:00
|
|
|
final File pidFile = tempDir.childFile('test.pid');
|
|
|
|
await _flutterRun.run(withDebugger: true);
|
|
|
|
await _flutterAttach.attach(
|
|
|
|
_flutterRun.vmServicePort,
|
|
|
|
pidFile: pidFile,
|
|
|
|
);
|
|
|
|
expect(pidFile.existsSync(), isTrue);
|
|
|
|
});
|
|
|
|
|
2020-09-08 22:56:00 +00:00
|
|
|
testWithoutContext('can hot reload', () async {
|
2019-10-18 23:35:39 +00:00
|
|
|
await _flutterRun.run(withDebugger: true);
|
|
|
|
await _flutterAttach.attach(_flutterRun.vmServicePort);
|
|
|
|
await _flutterAttach.hotReload();
|
|
|
|
});
|
|
|
|
|
2020-09-08 22:56:00 +00:00
|
|
|
testWithoutContext('can detach, reattach, hot reload', () async {
|
2019-10-18 23:35:39 +00:00
|
|
|
await _flutterRun.run(withDebugger: true);
|
|
|
|
await _flutterAttach.attach(_flutterRun.vmServicePort);
|
|
|
|
await _flutterAttach.detach();
|
|
|
|
await _flutterAttach.attach(_flutterRun.vmServicePort);
|
|
|
|
await _flutterAttach.hotReload();
|
|
|
|
});
|
|
|
|
|
2020-09-08 22:56:00 +00:00
|
|
|
testWithoutContext('killing process behaves the same as detach ', () async {
|
2019-10-18 23:35:39 +00:00
|
|
|
await _flutterRun.run(withDebugger: true);
|
|
|
|
await _flutterAttach.attach(_flutterRun.vmServicePort);
|
|
|
|
await _flutterAttach.quit();
|
2020-07-29 17:05:40 +00:00
|
|
|
_flutterAttach = FlutterRunTestDriver(
|
|
|
|
tempDir,
|
|
|
|
logPrefix: 'ATTACH-2',
|
|
|
|
spawnDdsInstance: false,
|
|
|
|
);
|
2019-10-18 23:35:39 +00:00
|
|
|
await _flutterAttach.attach(_flutterRun.vmServicePort);
|
|
|
|
await _flutterAttach.hotReload();
|
|
|
|
});
|
2018-07-19 12:38:29 +00:00
|
|
|
}
|