build_test_task_test.dart 2.98 KB
Newer Older
1 2 3 4
// 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.

5 6
// @dart = 2.8

7 8
import 'dart:async';

9 10 11 12 13 14 15 16 17
import 'package:flutter_devicelab/framework/runner.dart';
import 'package:flutter_devicelab/framework/task_result.dart';

import '../common.dart';

void main() {
  final Map<String, String> isolateParams = <String, String>{
    'runFlutterConfig': 'false',
    'runProcessCleanup': 'false',
18
    'timeoutInMinutes': '1',
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  };

  test('runs build and test when no args are passed', () async {
    final TaskResult result = await runTask(
      'smoke_test_build_test',
      deviceId: 'FAKE_SUCCESS',
      isolateParams: isolateParams,
    );
    expect(result.data['benchmark'], 'data');
  });

  test('runs build only when build arg is given', () async {
    final TaskResult result = await runTask(
      'smoke_test_build_test',
      taskArgs: <String>['--build'],
      deviceId: 'FAKE_SUCCESS',
      isolateParams: isolateParams,
    );
    expect(result.message, 'No tests run');
  });

  test('runs test only when test arg is given', () async {
    final TaskResult result = await runTask(
      'smoke_test_build_test',
      taskArgs: <String>['--test'],
      deviceId: 'FAKE_SUCCESS',
      isolateParams: isolateParams,
    );
    expect(result.data['benchmark'], 'data');
  });

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  test('sets environment', () async {
    final StringBuffer capturedPrintLines = StringBuffer();
    await runZoned<Future<void>>(
      () async {
        await runTask(
          'smoke_test_build_test',
          taskArgs: <String>['--test'],
          deviceId: 'FAKE_SUCCESS',
          isolateParams: isolateParams,
        );
      },
      zoneSpecification: ZoneSpecification(
        // Intercept printing from the task.
        print: (Zone self, ZoneDelegate parent, Zone zone, String line) async {
          capturedPrintLines.writeln(line);
        },
      ),
    );
    final String capturedPrint = capturedPrintLines.toString();
    expect(capturedPrint,
        contains('with environment {FLUTTER_DEVICELAB_DEVICEID: FAKE_SUCCESS, BOT: true, LANG: en_US.UTF-8}'));
    expect(capturedPrint, contains('exit code: 0'));
  });

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  test('throws exception when build and test arg are given', () async {
    final TaskResult result = await runTask(
      'smoke_test_build_test',
      taskArgs: <String>['--build', '--test'],
      deviceId: 'FAKE_SUCCESS',
      isolateParams: isolateParams,
    );
    expect(result.message, 'Task failed: Exception: Both build and test should not be passed. Pass only one.');
  });

  test('throws exception when build and application binary arg are given', () async {
    final TaskResult result = await runTask(
      'smoke_test_build_test',
      taskArgs: <String>['--build', '--application-binary-path=test.apk'],
      deviceId: 'FAKE_SUCCESS',
      isolateParams: isolateParams,
    );
    expect(result.message, 'Task failed: Exception: Application binary path is only used for tests');
  });
}