• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Integration tests which invoke flutter instead of unit testing the code
6// will not produce meaningful coverage information - we can measure coverage
7// from the isolate running the test, but not from the isolate started via
8// the command line process.
9@Tags(<String>['no_coverage'])
10import 'package:file/file.dart';
11import 'package:flutter_tools/src/base/file_system.dart';
12import 'package:flutter_tools/src/base/io.dart';
13import 'package:process/process.dart';
14
15import '../src/common.dart';
16import 'test_data/basic_project.dart';
17import 'test_driver.dart';
18import 'test_utils.dart';
19
20void main() {
21  group('flutter_run', () {
22    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      tryToDelete(tempDir);
35    });
36
37    test('reports an error if an invalid device is supplied', () async {
38      // This test forces flutter to check for all possible devices to catch issues
39      // 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      // some of the checks for devices.
42      final String flutterBin = fs.path.join(getFlutterRoot(), 'bin', 'flutter');
43
44      const ProcessManager _processManager = LocalProcessManager();
45      final ProcessResult _proc = await _processManager.run(
46        <String>[flutterBin, 'run', '-d', 'invalid-device-id'],
47        workingDirectory: tempDir.path,
48      );
49
50      expect(_proc.stdout, isNot(contains('flutter has exited unexpectedly')));
51      expect(_proc.stderr, isNot(contains('flutter has exited unexpectedly')));
52      if (!_proc.stderr.toString().contains('Unable to locate a development')
53          && !_proc.stdout.toString().contains('No devices found with name or id matching')) {
54        fail("'flutter run -d invalid-device-id' did not produce the expected error");
55      }
56    });
57
58    test('writes pid-file', () async {
59      final File pidFile = tempDir.childFile('test.pid');
60      await _flutter.run(pidFile: pidFile);
61      expect(pidFile.existsSync(), isTrue);
62    });
63  }, timeout: const Timeout.factor(10), tags: <String>['integration']); // The DevFS sync takes a really long time, so these tests can be slow.
64}
65