Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
6830edd0
Unverified
Commit
6830edd0
authored
Jul 19, 2019
by
Jonah Williams
Committed by
GitHub
Jul 19, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up flutter driver device detection. (#36434)
parent
ecd89fb7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
32 deletions
+41
-32
drive.dart
packages/flutter_tools/lib/src/commands/drive.dart
+3
-9
config_test.dart
...lutter_tools/test/general.shard/commands/config_test.dart
+6
-1
drive_test.dart
...flutter_tools/test/general.shard/commands/drive_test.dart
+28
-18
context.dart
packages/flutter_tools/test/src/context.dart
+4
-4
No files found.
packages/flutter_tools/lib/src/commands/drive.dart
View file @
6830edd0
...
...
@@ -13,6 +13,7 @@ import '../dart/package_map.dart';
import
'../dart/sdk.dart'
;
import
'../device.dart'
;
import
'../globals.dart'
;
import
'../project.dart'
;
import
'../resident_runner.dart'
;
import
'../runner/flutter_command.dart'
show
FlutterCommandResult
;
import
'run.dart'
;
...
...
@@ -94,7 +95,7 @@ class DriveCommand extends RunCommandBase {
if
(
testFile
==
null
)
throwToolExit
(
null
);
_device
=
await
targetDeviceFinder
();
_device
=
await
findTargetDevice
();
if
(
device
==
null
)
throwToolExit
(
null
);
...
...
@@ -187,15 +188,8 @@ class DriveCommand extends RunCommandBase {
}
}
/// Finds a device to test on. May launch a simulator, if necessary.
typedef
TargetDeviceFinder
=
Future
<
Device
>
Function
();
TargetDeviceFinder
targetDeviceFinder
=
findTargetDevice
;
void
restoreTargetDeviceFinder
(
)
{
targetDeviceFinder
=
findTargetDevice
;
}
Future
<
Device
>
findTargetDevice
()
async
{
final
List
<
Device
>
devices
=
await
deviceManager
.
getDevices
().
toList
(
);
final
List
<
Device
>
devices
=
await
deviceManager
.
findTargetDevices
(
FlutterProject
.
current
()
);
if
(
deviceManager
.
hasSpecifiedDeviceId
)
{
if
(
devices
.
isEmpty
)
{
...
...
packages/flutter_tools/test/general.shard/commands/config_test.dart
View file @
6830edd0
...
...
@@ -12,7 +12,9 @@ import 'package:flutter_tools/src/base/context.dart';
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/config.dart'
;
import
'package:flutter_tools/src/desktop.dart'
;
import
'package:flutter_tools/src/version.dart'
;
import
'package:flutter_tools/src/web/workflow.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../../src/common.dart'
;
...
...
@@ -24,6 +26,9 @@ void main() {
MockFlutterVersion
mockFlutterVersion
;
setUpAll
(()
{
// TODO(jonahwilliams): remove once features are landed.
debugDisableDesktop
=
true
;
debugDisableWeb
=
true
;
Cache
.
disableLocking
();
});
...
...
packages/flutter_tools/test/general.shard/commands/drive_test.dart
View file @
6830edd0
...
...
@@ -23,15 +23,10 @@ void main() {
group
(
'drive'
,
()
{
DriveCommand
command
;
Device
mockDevice
;
Device
mockUnsupportedDevice
;
MemoryFileSystem
fs
;
Directory
tempDir
;
void
withMockDevice
([
Device
mock
])
{
mockDevice
=
mock
??
MockDevice
();
targetDeviceFinder
=
()
async
=>
mockDevice
;
testDeviceManager
.
addDevice
(
mockDevice
);
}
setUpAll
(()
{
Cache
.
disableLocking
();
});
...
...
@@ -47,9 +42,6 @@ void main() {
fs
.
file
(
'pubspec.yaml'
)..
createSync
();
fs
.
file
(
'.packages'
).
createSync
();
setExitFunctionForTests
();
targetDeviceFinder
=
()
{
throw
'Unexpected call to targetDeviceFinder'
;
};
appStarter
=
(
DriveCommand
command
)
{
throw
'Unexpected call to appStarter'
;
};
...
...
@@ -67,12 +59,11 @@ void main() {
restoreAppStarter
();
restoreAppStopper
();
restoreTestRunner
();
restoreTargetDeviceFinder
();
tryToDelete
(
tempDir
);
});
testUsingContext
(
'returns 1 when test file is not found'
,
()
async
{
withMockDevice
(
);
testDeviceManager
.
addDevice
(
MockDevice
()
);
final
String
testApp
=
fs
.
path
.
join
(
tempDir
.
path
,
'test'
,
'e2e.dart'
);
final
String
testFile
=
fs
.
path
.
join
(
tempDir
.
path
,
'test_driver'
,
'e2e_test.dart'
);
...
...
@@ -94,7 +85,7 @@ void main() {
});
testUsingContext
(
'returns 1 when app fails to run'
,
()
async
{
withMockDevice
(
);
testDeviceManager
.
addDevice
(
MockDevice
()
);
appStarter
=
expectAsync1
((
DriveCommand
command
)
async
=>
null
);
final
String
testApp
=
fs
.
path
.
join
(
tempDir
.
path
,
'test_driver'
,
'e2e.dart'
);
...
...
@@ -163,7 +154,7 @@ void main() {
});
testUsingContext
(
'returns 0 when test ends successfully'
,
()
async
{
withMockDevice
(
);
testDeviceManager
.
addDevice
(
MockDevice
()
);
final
String
testApp
=
fs
.
path
.
join
(
tempDir
.
path
,
'test'
,
'e2e.dart'
);
final
String
testFile
=
fs
.
path
.
join
(
tempDir
.
path
,
'test_driver'
,
'e2e_test.dart'
);
...
...
@@ -194,7 +185,7 @@ void main() {
});
testUsingContext
(
'returns exitCode set by test runner'
,
()
async
{
withMockDevice
(
);
testDeviceManager
.
addDevice
(
MockDevice
()
);
final
String
testApp
=
fs
.
path
.
join
(
tempDir
.
path
,
'test'
,
'e2e.dart'
);
final
String
testFile
=
fs
.
path
.
join
(
tempDir
.
path
,
'test_driver'
,
'e2e_test.dart'
);
...
...
@@ -231,7 +222,8 @@ void main() {
group
(
'findTargetDevice'
,
()
{
testUsingContext
(
'uses specified device'
,
()
async
{
testDeviceManager
.
specifiedDeviceId
=
'123'
;
withMockDevice
();
mockDevice
=
MockDevice
();
testDeviceManager
.
addDevice
(
mockDevice
);
when
(
mockDevice
.
name
).
thenReturn
(
'specified-device'
);
when
(
mockDevice
.
id
).
thenReturn
(
'123'
);
...
...
@@ -255,7 +247,25 @@ void main() {
testUsingContext
(
'uses existing Android device'
,
()
async
{
mockDevice
=
MockAndroidDevice
();
when
(
mockDevice
.
name
).
thenReturn
(
'mock-android-device'
);
withMockDevice
(
mockDevice
);
testDeviceManager
.
addDevice
(
mockDevice
);
final
Device
device
=
await
findTargetDevice
();
expect
(
device
.
name
,
'mock-android-device'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fs
,
Platform:
platform
,
});
testUsingContext
(
'skips unsupported device'
,
()
async
{
mockDevice
=
MockAndroidDevice
();
mockUnsupportedDevice
=
MockDevice
();
when
(
mockUnsupportedDevice
.
isSupportedForProject
(
any
))
.
thenReturn
(
false
);
when
(
mockDevice
.
isSupportedForProject
(
any
))
.
thenReturn
(
true
);
when
(
mockDevice
.
name
).
thenReturn
(
'mock-android-device'
);
testDeviceManager
.
addDevice
(
mockDevice
);
testDeviceManager
.
addDevice
(
mockUnsupportedDevice
);
final
Device
device
=
await
findTargetDevice
();
expect
(
device
.
name
,
'mock-android-device'
);
...
...
@@ -279,7 +289,7 @@ void main() {
Platform
macOsPlatform
()
=>
FakePlatform
(
operatingSystem:
'macos'
);
testUsingContext
(
'uses existing simulator'
,
()
async
{
withMockDevice
(
);
testDeviceManager
.
addDevice
(
mockDevice
);
when
(
mockDevice
.
name
).
thenReturn
(
'mock-simulator'
);
when
(
mockDevice
.
isLocalEmulator
)
.
thenAnswer
((
Invocation
invocation
)
=>
Future
<
bool
>.
value
(
true
));
...
...
@@ -300,7 +310,7 @@ void main() {
});
Future
<
void
>
appStarterSetup
()
async
{
withMockDevice
(
);
testDeviceManager
.
addDevice
(
mockDevice
);
final
MockDeviceLogReader
mockDeviceLogReader
=
MockDeviceLogReader
();
when
(
mockDevice
.
getLogReader
()).
thenReturn
(
mockDeviceLogReader
);
...
...
packages/flutter_tools/test/src/context.dart
View file @
6830edd0
...
...
@@ -188,13 +188,13 @@ class FakeDeviceManager implements DeviceManager {
List
<
DeviceDiscovery
>
get
deviceDiscoverers
=>
<
DeviceDiscovery
>[];
@override
Future
<
List
<
Device
>>
findTargetDevices
(
FlutterProject
flutterProject
)
{
return
getDevices
().
toList
(
);
bool
isDeviceSupportedForProject
(
Device
device
,
FlutterProject
flutterProject
)
{
return
device
.
isSupportedForProject
(
flutterProject
);
}
@override
bool
isDeviceSupportedForProject
(
Device
device
,
FlutterProject
flutterProject
)
{
return
device
.
isSupportedForProject
(
flutterProject
)
;
Future
<
List
<
Device
>>
findTargetDevices
(
FlutterProject
flutterProject
)
async
{
return
device
s
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment