flutter_run_test.dart 2.77 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// 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/io.dart';
7
import 'package:process/process.dart';
8 9 10

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

void main() {
15
  late Directory tempDir;
16
  final BasicProject project = BasicProject();
17
  late FlutterRunTestDriver flutter;
18 19 20

  setUp(() async {
    tempDir = createResolvedTempDirectorySync('run_test.');
21 22
    await project.setUpIn(tempDir);
    flutter = FlutterRunTestDriver(tempDir);
23 24 25
  });

  tearDown(() async {
26
    await flutter.stop();
27 28 29
    tryToDelete(tempDir);
  });

30
  testWithoutContext('flutter run reports an error if an invalid device is supplied', () async {
31 32 33 34
    // This test forces flutter to check for all possible devices to catch issues
    // like https://github.com/flutter/flutter/issues/21418 which were skipped
    // over because other integration tests run using flutter-tester which short-cuts
    // some of the checks for devices.
35
    final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
36

37 38
    const ProcessManager processManager = LocalProcessManager();
    final ProcessResult proc = await processManager.run(
39 40 41 42
      <String>[flutterBin, 'run', '-d', 'invalid-device-id'],
      workingDirectory: tempDir.path,
    );

43 44 45
    expect(proc.stdout, isNot(contains('flutter has exited unexpectedly')));
    expect(proc.stderr, isNot(contains('flutter has exited unexpectedly')));
    if (!proc.stderr.toString().contains('Unable to locate a development')
46
        && !proc.stdout.toString().contains('No supported devices found with name or id matching')) {
47 48 49 50
      fail("'flutter run -d invalid-device-id' did not produce the expected error");
    }
  });

51
  testWithoutContext('sets activeDevToolsServerAddress extension', () async {
52
    await flutter.run(
53 54 55 56
      startPaused: true,
      withDebugger: true,
      additionalCommandArgs: <String>['--devtools-server-address', 'http://127.0.0.1:9110'],
    );
57
    await flutter.resume();
58
    await pollForServiceExtensionValue<String>(
59
      testDriver: flutter,
60 61
      extension: 'ext.flutter.activeDevToolsServerAddress',
      continuePollingValue: '',
62
      matches: equals('http://127.0.0.1:9110'),
63
    );
64
    await pollForServiceExtensionValue<String>(
65
      testDriver: flutter,
66 67 68 69
      extension: 'ext.flutter.connectedVmServiceUri',
      continuePollingValue: '',
      matches: isNotEmpty,
    );
70
  });
71 72 73 74 75 76

  testWithoutContext('reports deviceId and mode in app.start event', () async {
    await flutter.run();
    expect(flutter.currentRunningDeviceId, 'flutter-tester');
    expect(flutter.currentRunningMode, 'debug');
  });
77
}