mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix flutter tools packages_test when run off bots (#14692)
* Fix packages tests when run off bots * Tweak dependencies to make bots happy * Review comment
This commit is contained in:
parent
24efb55b03
commit
ca677011f8
@ -73,6 +73,7 @@ Future<int> run(
|
||||
context.putIfAbsent(Config, () => new Config());
|
||||
|
||||
// Order-independent context entries
|
||||
context.putIfAbsent(BotDetector, () => const BotDetector());
|
||||
context.putIfAbsent(DeviceManager, () => new DeviceManager());
|
||||
context.putIfAbsent(DevFSConfig, () => new DevFSConfig());
|
||||
context.putIfAbsent(Doctor, () => new Doctor());
|
||||
|
||||
@ -15,27 +15,40 @@ import 'context.dart';
|
||||
import 'file_system.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
final BotDetector _kBotDetector = const BotDetector();
|
||||
|
||||
class BotDetector {
|
||||
const BotDetector();
|
||||
|
||||
bool get isRunningOnBot {
|
||||
return
|
||||
platform.environment['BOT'] == 'true' ||
|
||||
|
||||
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
|
||||
platform.environment['TRAVIS'] == 'true' ||
|
||||
platform.environment['CONTINUOUS_INTEGRATION'] == 'true' ||
|
||||
platform.environment.containsKey('CI') || // Travis and AppVeyor
|
||||
|
||||
// https://www.appveyor.com/docs/environment-variables/
|
||||
platform.environment.containsKey('APPVEYOR') ||
|
||||
|
||||
// https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
|
||||
(platform.environment.containsKey('AWS_REGION') && platform.environment.containsKey('CODEBUILD_INITIATOR')) ||
|
||||
|
||||
// https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables
|
||||
platform.environment.containsKey('JENKINS_URL') ||
|
||||
|
||||
// Properties on Flutter's Chrome Infra bots.
|
||||
platform.environment['CHROME_HEADLESS'] == '1' ||
|
||||
platform.environment.containsKey('BUILDBOT_BUILDERNAME');
|
||||
}
|
||||
}
|
||||
|
||||
bool get isRunningOnBot {
|
||||
return
|
||||
platform.environment['BOT'] == 'true' ||
|
||||
|
||||
// https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
|
||||
platform.environment['TRAVIS'] == 'true' ||
|
||||
platform.environment['CONTINUOUS_INTEGRATION'] == 'true' ||
|
||||
platform.environment.containsKey('CI') || // Travis and AppVeyor
|
||||
|
||||
// https://www.appveyor.com/docs/environment-variables/
|
||||
platform.environment.containsKey('APPVEYOR') ||
|
||||
|
||||
// https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
|
||||
(platform.environment.containsKey('AWS_REGION') && platform.environment.containsKey('CODEBUILD_INITIATOR')) ||
|
||||
|
||||
// https://wiki.jenkins.io/display/JENKINS/Building+a+software+project#Buildingasoftwareproject-belowJenkinsSetEnvironmentVariables
|
||||
platform.environment.containsKey('JENKINS_URL') ||
|
||||
|
||||
// Properties on Flutter's Chrome Infra bots.
|
||||
platform.environment['CHROME_HEADLESS'] == '1' ||
|
||||
platform.environment.containsKey('BUILDBOT_BUILDERNAME');
|
||||
if (context == null) {
|
||||
return _kBotDetector.isRunningOnBot;
|
||||
}
|
||||
return context[BotDetector].isRunningOnBot;
|
||||
}
|
||||
|
||||
String hex(List<int> bytes) {
|
||||
|
||||
@ -13,6 +13,7 @@ import 'base/io.dart';
|
||||
import 'base/logger.dart';
|
||||
import 'base/os.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/utils.dart';
|
||||
import 'cache.dart';
|
||||
import 'disabled_usage.dart';
|
||||
import 'usage.dart';
|
||||
@ -25,6 +26,7 @@ Future<Null> runInContext(List<String> args, Runner runner) {
|
||||
return executableContext.runInZone(() {
|
||||
// Initialize the context with some defaults.
|
||||
// This list must be kept in sync with lib/executable.dart.
|
||||
context.putIfAbsent(BotDetector, () => const BotDetector());
|
||||
context.putIfAbsent(Stdio, () => const Stdio());
|
||||
context.putIfAbsent(Platform, () => const LocalPlatform());
|
||||
context.putIfAbsent(FileSystem, () => const LocalFileSystem());
|
||||
|
||||
@ -7,6 +7,7 @@ import 'dart:async';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart' hide IOSink;
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/packages.dart';
|
||||
import 'package:process/process.dart';
|
||||
@ -16,6 +17,22 @@ import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/mocks.dart' show MockProcessManager, MockStdio, PromptingProcess;
|
||||
|
||||
class AlwaysTrueBotDetector implements BotDetector {
|
||||
const AlwaysTrueBotDetector();
|
||||
|
||||
@override
|
||||
bool get isRunningOnBot => true;
|
||||
}
|
||||
|
||||
|
||||
class AlwaysFalseBotDetector implements BotDetector {
|
||||
const AlwaysFalseBotDetector();
|
||||
|
||||
@override
|
||||
bool get isRunningOnBot => false;
|
||||
}
|
||||
|
||||
|
||||
void main() {
|
||||
Cache.disableLocking();
|
||||
group('packages get/upgrade', () {
|
||||
@ -221,7 +238,20 @@ void main() {
|
||||
mockStdio = new MockStdio();
|
||||
});
|
||||
|
||||
testUsingContext('test', () async {
|
||||
testUsingContext('test without bot', () async {
|
||||
await createTestCommandRunner(new PackagesCommand()).run(<String>['packages', 'test']);
|
||||
final List<String> commands = mockProcessManager.commands;
|
||||
expect(commands, hasLength(3));
|
||||
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
|
||||
expect(commands[1], 'run');
|
||||
expect(commands[2], 'test');
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Stdio: () => mockStdio,
|
||||
BotDetector: () => const AlwaysFalseBotDetector(),
|
||||
});
|
||||
|
||||
testUsingContext('test with bot', () async {
|
||||
await createTestCommandRunner(new PackagesCommand()).run(<String>['packages', 'test']);
|
||||
final List<String> commands = mockProcessManager.commands;
|
||||
expect(commands, hasLength(4));
|
||||
@ -232,6 +262,7 @@ void main() {
|
||||
}, overrides: <Type, Generator>{
|
||||
ProcessManager: () => mockProcessManager,
|
||||
Stdio: () => mockStdio,
|
||||
BotDetector: () => const AlwaysTrueBotDetector(),
|
||||
});
|
||||
|
||||
testUsingContext('run', () async {
|
||||
|
||||
@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/port_scanner.dart';
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/devfs.dart';
|
||||
import 'package:flutter_tools/src/device.dart';
|
||||
@ -91,6 +92,7 @@ void testUsingContext(String description, dynamic testMethod(), {
|
||||
|
||||
// The context always starts with these value since others depend on them.
|
||||
testContext
|
||||
..putIfAbsent(BotDetector, () => const BotDetector())
|
||||
..putIfAbsent(Stdio, () => const Stdio())
|
||||
..putIfAbsent(Platform, () => const LocalPlatform())
|
||||
..putIfAbsent(FileSystem, () => const LocalFileSystem())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user