test_device.dart 1.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2014 The Flutter 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 'dart:async';

import 'package:stream_channel/stream_channel.dart';

/// A remote device where tests can be executed on.
///
/// Reusability of an instance across multiple runs is not guaranteed for all
/// implementations.
13 14
///
/// Methods may throw [TestDeviceException] if a problem is encountered.
15 16 17 18
abstract class TestDevice {
  /// Starts the test device with the provided entrypoint.
  ///
  /// Returns a channel that can be used to communicate with the test process.
19 20 21 22
  ///
  /// It is up to the device to determine if [entrypointPath] is a precompiled
  /// or raw source file.
  Future<StreamChannel<String>> start(String entrypointPath);
23

24 25
  /// Should complete with null if the VM Service is not enabled.
  Future<Uri?> get vmServiceUri;
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

  /// Terminates the test device.
  Future<void> kill();

  /// Waits for the test device to stop.
  Future<void> get finished;
}

/// Thrown when the device encounters a problem.
class TestDeviceException implements Exception {
  TestDeviceException(this.message, this.stackTrace);

  final String message;
  final StackTrace stackTrace;

  @override
  String toString() => 'TestDeviceException($message)';
}