Add a real-er web restart, doctor, workflow (#33786)
This commit is contained in:
@@ -66,7 +66,7 @@ void main() {
|
||||
|
||||
when(mockDeviceManager.getDevices()).thenAnswer((Invocation invocation) {
|
||||
return Stream<Device>.fromIterable(<Device>[
|
||||
MockDevice(TargetPlatform.web),
|
||||
MockDevice(TargetPlatform.web_javascript),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/web/chrome.dart';
|
||||
import 'package:flutter_tools/src/web/compile.dart';
|
||||
import 'package:flutter_tools/src/web/web_device.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
52
packages/flutter_tools/test/web/web_validator_test.dart
Normal file
52
packages/flutter_tools/test/web/web_validator_test.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/doctor.dart';
|
||||
import 'package:flutter_tools/src/web/chrome.dart';
|
||||
import 'package:flutter_tools/src/web/web_validator.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('WebValidator', () {
|
||||
Testbed testbed;
|
||||
WebValidator webValidator;
|
||||
MockPlatform mockPlatform;
|
||||
|
||||
setUp(() {
|
||||
testbed = Testbed(setup: () {
|
||||
fs.file(kMacOSExecutable).createSync(recursive: true);
|
||||
fs.file('chrome_foo').createSync();
|
||||
return null;
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => mockPlatform,
|
||||
});
|
||||
webValidator = const WebValidator();
|
||||
mockPlatform = MockPlatform();
|
||||
when(mockPlatform.isMacOS).thenReturn(true);
|
||||
when(mockPlatform.isWindows).thenReturn(false);
|
||||
when(mockPlatform.isLinux).thenReturn(false);
|
||||
});
|
||||
|
||||
test('Can find macOS executable ', () => testbed.run(() async {
|
||||
final ValidationResult result = await webValidator.validate();
|
||||
expect(result.type, ValidationType.installed);
|
||||
}));
|
||||
|
||||
test('Can notice missing macOS executable ', () => testbed.run(() async {
|
||||
fs.file(kMacOSExecutable).deleteSync();
|
||||
final ValidationResult result = await webValidator.validate();
|
||||
expect(result.type, ValidationType.missing);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockPlatform extends Mock implements Platform {
|
||||
@override
|
||||
Map<String, String> get environment => const <String, String>{};
|
||||
}
|
||||
140
packages/flutter_tools/test/web/workflow_test.dart
Normal file
140
packages/flutter_tools/test/web/workflow_test.dart
Normal file
@@ -0,0 +1,140 @@
|
||||
// Copyright 2019 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.
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/version.dart';
|
||||
import 'package:flutter_tools/src/web/chrome.dart';
|
||||
import 'package:flutter_tools/src/web/workflow.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
import '../src/testbed.dart';
|
||||
|
||||
void main() {
|
||||
group('WebWorkflow', () {
|
||||
Testbed testbed;
|
||||
MockPlatform noEnvironment;
|
||||
MockPlatform notSupported;
|
||||
MockPlatform windows;
|
||||
MockPlatform linux;
|
||||
MockPlatform macos;
|
||||
MockProcessManager mockProcessManager;
|
||||
MockFlutterVersion unstable;
|
||||
MockFlutterVersion stable;
|
||||
WebWorkflow workflow;
|
||||
|
||||
setUpAll(() {
|
||||
unstable = MockFlutterVersion(false);
|
||||
stable = MockFlutterVersion(true);
|
||||
noEnvironment = MockPlatform(environment: const <String, String>{});
|
||||
notSupported = MockPlatform(linux: false, windows: false, macos: false);
|
||||
windows = MockPlatform(windows: true);
|
||||
linux = MockPlatform(linux: true);
|
||||
macos = MockPlatform(macos: true);
|
||||
workflow = const WebWorkflow();
|
||||
mockProcessManager = MockProcessManager();
|
||||
testbed = Testbed(setup: () async {
|
||||
fs.file('chrome').createSync();
|
||||
when(mockProcessManager.canRun('chrome')).thenReturn(true);
|
||||
}, overrides: <Type, Generator>{
|
||||
FlutterVersion: () => unstable,
|
||||
ProcessManager: () => mockProcessManager,
|
||||
});
|
||||
});
|
||||
|
||||
test('does not apply if FLUTTER_WEB is not true', ()=> testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, false);
|
||||
expect(workflow.canLaunchDevices, false);
|
||||
expect(workflow.canListDevices, false);
|
||||
expect(workflow.canListEmulators, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => noEnvironment,
|
||||
}));
|
||||
|
||||
test('Applies on Linux', () => testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, true);
|
||||
expect(workflow.canLaunchDevices, true);
|
||||
expect(workflow.canListDevices, true);
|
||||
expect(workflow.canListEmulators, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => linux,
|
||||
}));
|
||||
|
||||
test('Applies on macOS', () => testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, true);
|
||||
expect(workflow.canLaunchDevices, true);
|
||||
expect(workflow.canListDevices, true);
|
||||
expect(workflow.canListEmulators, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => macos,
|
||||
}));
|
||||
|
||||
test('Applies on Windows', () => testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, true);
|
||||
expect(workflow.canLaunchDevices, true);
|
||||
expect(workflow.canListDevices, true);
|
||||
expect(workflow.canListEmulators, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => windows,
|
||||
}));
|
||||
|
||||
test('does not apply on other platforms', () => testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, false);
|
||||
expect(workflow.canLaunchDevices, false);
|
||||
expect(workflow.canListDevices, false);
|
||||
expect(workflow.canListEmulators, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => notSupported,
|
||||
}));
|
||||
|
||||
test('does not apply on stable brnach', () => testbed.run(() {
|
||||
expect(workflow.appliesToHostPlatform, false);
|
||||
expect(workflow.canLaunchDevices, false);
|
||||
expect(workflow.canListDevices, false);
|
||||
expect(workflow.canListEmulators, false);
|
||||
}, overrides: <Type, Generator>{
|
||||
Platform: () => macos,
|
||||
FlutterVersion: () => stable,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
class MockFlutterVersion extends Mock implements FlutterVersion {
|
||||
MockFlutterVersion(this.isStable);
|
||||
|
||||
@override
|
||||
final bool isStable;
|
||||
}
|
||||
|
||||
class MockProcessManager extends Mock implements ProcessManager {}
|
||||
|
||||
class MockPlatform extends Mock implements Platform {
|
||||
MockPlatform(
|
||||
{this.windows = false,
|
||||
this.macos = false,
|
||||
this.linux = false,
|
||||
this.environment = const <String, String>{
|
||||
'FLUTTER_WEB': 'true',
|
||||
kChromeEnvironment: 'chrome',
|
||||
}});
|
||||
|
||||
final bool windows;
|
||||
final bool macos;
|
||||
final bool linux;
|
||||
|
||||
@override
|
||||
final Map<String, String> environment;
|
||||
|
||||
@override
|
||||
bool get isLinux => linux;
|
||||
|
||||
@override
|
||||
bool get isMacOS => macos;
|
||||
|
||||
@override
|
||||
bool get isWindows => windows;
|
||||
}
|
||||
Reference in New Issue
Block a user