flutter_run_test.dart 2.58 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 13 14 15 16
import 'package:file/file.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:process/process.dart';

import '../src/common.dart';
import 'test_data/basic_project.dart';
17
import 'test_driver.dart';
18
import 'test_utils.dart';
19 20 21 22

void main() {
  group('flutter_run', () {
    Directory tempDir;
23
    final BasicProject _project = BasicProject();
24
    FlutterRunTestDriver _flutter;
25 26

    setUp(() async {
27
      tempDir = createResolvedTempDirectorySync('run_test.');
28
      await _project.setUpIn(tempDir);
29
      _flutter = FlutterRunTestDriver(tempDir);
30 31 32
    });

    tearDown(() async {
33
      await _flutter.stop();
34 35
      tryToDelete(tempDir);
    });
36

37 38 39
    test('reports an error if an invalid device is supplied', () async {
      // This test forces flutter to check for all possible devices to catch issues
      // like https://github.com/flutter/flutter/issues/21418 which were skipped
40
      // over because other integration tests run using flutter-tester which short-cuts
41 42 43 44 45 46
      // some of the checks for devices.
      final String flutterBin = fs.path.join(getFlutterRoot(), 'bin', 'flutter');

      const ProcessManager _processManager = LocalProcessManager();
      final ProcessResult _proc = await _processManager.run(
        <String>[flutterBin, 'run', '-d', 'invalid-device-id'],
47
        workingDirectory: tempDir.path,
48 49 50 51
      );

      expect(_proc.stdout, isNot(contains('flutter has exited unexpectedly')));
      expect(_proc.stderr, isNot(contains('flutter has exited unexpectedly')));
52
      if (!_proc.stderr.toString().contains('Unable to locate a development')
53 54 55
          && !_proc.stdout.toString().contains('No devices found with name or id matching')) {
        fail("'flutter run -d invalid-device-id' did not produce the expected error");
      }
56
    });
57 58 59 60

    test('writes pid-file', () async {
      final File pidFile = tempDir.childFile('test.pid');
      await _flutter.run(pidFile: pidFile);
61
      expect(pidFile.existsSync(), isTrue);
62
    });
Dan Field's avatar
Dan Field committed
63
  }, timeout: const Timeout.factor(10), tags: <String>['integration']); // The DevFS sync takes a really long time, so these tests can be slow.
64
}