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
9e30d51a
Unverified
Commit
9e30d51a
authored
Jun 24, 2020
by
Jonah Williams
Committed by
GitHub
Jun 24, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] start fixing command tests (#60172)
parent
77bc1ee5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
186 deletions
+73
-186
devices_test.dart
...tter_tools/test/commands.shard/hermetic/devices_test.dart
+10
-1
doctor_test.dart
...utter_tools/test/commands.shard/hermetic/doctor_test.dart
+24
-4
run_test.dart
.../flutter_tools/test/commands.shard/hermetic/run_test.dart
+39
-181
No files found.
packages/flutter_tools/test/commands.shard/hermetic/devices_test.dart
View file @
9e30d51a
...
...
@@ -34,7 +34,7 @@ void main() {
expect
(
testLogger
.
statusText
,
containsIgnoringWhitespace
(
'No devices detected'
));
},
overrides:
<
Type
,
Generator
>{
AndroidSdk:
()
=>
null
,
DeviceManager:
()
=>
Device
Manager
(),
DeviceManager:
()
=>
NoDevices
Manager
(),
ProcessManager:
()
=>
MockProcessManager
(),
});
...
...
@@ -160,3 +160,12 @@ class _FakeDeviceManager extends DeviceManager {
<
String
>[
'Cannot connect to device ABC'
]
);
}
class
NoDevicesManager
extends
DeviceManager
{
@override
Future
<
List
<
Device
>>
getAllConnectedDevices
()
async
=>
<
Device
>[];
@override
Future
<
List
<
Device
>>
refreshAllConnectedDevices
({
Duration
timeout
})
=>
getAllConnectedDevices
();
}
packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart
View file @
9e30d51a
...
...
@@ -43,6 +43,11 @@ final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
Platform:
_kNoColorOutputPlatform
,
};
final
Platform
macPlatform
=
FakePlatform
(
operatingSystem:
'macos'
,
environment:
<
String
,
String
>{
'HOME'
:
'/foo/bar'
}
);
void
main
(
)
{
MockProcessManager
mockProcessManager
;
MockFlutterVersion
mockFlutterVersion
;
...
...
@@ -93,11 +98,14 @@ void main() {
expect
(
validator
.
plistFile
,
'/path/to/app/Contents/Info.plist'
);
expect
(
validator
.
pluginsPath
,
pluginsDirectory
.
path
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
FakePlatform
()
..
environment
=
<
String
,
String
>{
'HOME'
:
'/foo/bar'
},
Platform:
()
=>
macPlatform
,
PlistParser:
()
=>
mockPlistParser
,
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
mockProcessManager
,
FileSystemUtils:
()
=>
FileSystemUtils
(
fileSystem:
fileSystem
,
platform:
macPlatform
,
)
});
testUsingContext
(
'legacy intellij plugins path checking on mac'
,
()
async
{
...
...
@@ -106,9 +114,14 @@ void main() {
final
IntelliJValidatorOnMac
validator
=
IntelliJValidatorOnMac
(
'Test'
,
'TestID'
,
'/foo'
);
expect
(
validator
.
pluginsPath
,
'/foo/bar/Library/Application Support/TestID2020.10'
);
},
overrides:
<
Type
,
Generator
>{
Platform:
()
=>
FakePlatform
()
..
environment
=
<
String
,
String
>{
'HOME'
:
'/foo/bar'
},
Platform:
()
=>
macPlatform
,
PlistParser:
()
=>
mockPlistParser
,
FileSystem:
()
=>
fileSystem
,
FileSystemUtils:
()
=>
FileSystemUtils
(
fileSystem:
fileSystem
,
platform:
macPlatform
,
),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
testUsingContext
(
'intellij plugins path checking on mac with override'
,
()
async
{
...
...
@@ -118,6 +131,13 @@ void main() {
expect
(
validator
.
pluginsPath
,
'/path/to/JetBrainsToolboxApp.plugins'
);
},
overrides:
<
Type
,
Generator
>{
PlistParser:
()
=>
mockPlistParser
,
Platform:
()
=>
macPlatform
,
FileSystem:
()
=>
fileSystem
,
FileSystemUtils:
()
=>
FileSystemUtils
(
fileSystem:
fileSystem
,
platform:
macPlatform
,
),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
testUsingContext
(
'vs code validator when both installed'
,
()
async
{
...
...
packages/flutter_tools/test/commands.shard/hermetic/run_test.dart
View file @
9e30d51a
...
...
@@ -3,10 +3,8 @@
// found in the LICENSE file.
import
'dart:async'
;
import
'package:file/file.dart'
;
import
'package:file/memory.dart'
;
import
'package:args/command_runner.dart'
;
import
'package:flutter_tools/src/application_package.dart'
;
import
'package:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
...
...
@@ -15,19 +13,13 @@ import 'package:flutter_tools/src/base/file_system.dart';
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/user_messages.dart'
;
import
'package:flutter_tools/src/base/net.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
import
'package:flutter_tools/src/commands/run.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/features.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:flutter_tools/src/resident_runner.dart'
;
import
'package:flutter_tools/src/runner/flutter_command.dart'
;
import
'package:flutter_tools/src/version.dart'
;
import
'package:flutter_tools/src/web/web_runner.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../../src/common.dart'
;
...
...
@@ -40,15 +32,16 @@ void main() {
group
(
'run'
,
()
{
MockApplicationPackageFactory
mockApplicationPackageFactory
;
MockDeviceManager
mockDeviceManager
;
MockFlutterVersion
mockStableFlutterVersion
;
MockFlutterVersion
mockUnstableFlutterVersion
;
FileSystem
fileSystem
;
setUpAll
(()
{
Cache
.
disableLocking
();
});
setUp
(()
{
mockApplicationPackageFactory
=
MockApplicationPackageFactory
();
mockDeviceManager
=
MockDeviceManager
();
mockStableFlutterVersion
=
MockFlutterVersion
(
isStable:
true
);
mockUnstableFlutterVersion
=
MockFlutterVersion
(
isStable:
false
);
fileSystem
=
MemoryFileSystem
.
test
();
});
testUsingContext
(
'fails when target not found'
,
()
async
{
...
...
@@ -60,12 +53,16 @@ void main() {
}
on
ToolExit
catch
(
e
)
{
expect
(
e
.
exitCode
??
1
,
1
);
}
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Logger:
()
=>
BufferLogger
.
test
(),
});
testUsingContext
(
'does not support "--use-application-binary" and "--fast-start"'
,
()
async
{
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
'lib'
,
'main.dart'
)
).
createSync
(
recursive:
true
);
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
).
createSync
();
fileSystem
.
file
(
'lib/main.dart'
).
createSync
(
recursive:
true
);
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'.packages'
).
createSync
();
final
RunCommand
command
=
RunCommand
();
applyMocksToCommand
(
command
);
...
...
@@ -82,17 +79,18 @@ void main() {
expect
(
e
.
toString
(),
isNot
(
contains
(
'--fast-start is not supported with --use-application-binary'
)));
}
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
()
,
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Logger:
()
=>
BufferLogger
.
test
(),
});
testUsingContext
(
'Walks upward looking for a pubspec.yaml and succeeds if found'
,
()
async
{
globals
.
fs
.
file
(
'pubspec.yaml'
).
createSync
();
globals
.
fs
.
file
(
'.packages'
)
.
.
createSync
()
..
writeAsStringSync
(
'Not a valid package'
);
globals
.
fs
.
currentDirectory
=
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
'a'
,
'b'
,
'c'
)
)
fileSystem
.
file
(
'pubspec.yaml'
).
createSync
();
fileSystem
.
file
(
'.packages'
)
.
writeAsStringSync
(
'
\n
'
);
fileSystem
.
file
(
'lib/main.dart'
)
.
createSync
(
recursive:
true
);
fileSystem
.
currentDirectory
=
fileSystem
.
directory
(
'a/b/c'
)
..
createSync
(
recursive:
true
);
final
RunCommand
command
=
RunCommand
();
...
...
@@ -100,7 +98,6 @@ void main() {
try
{
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'run'
,
'--fast-start'
,
'--no-pub'
,
]);
fail
(
'Expect exception'
);
...
...
@@ -113,20 +110,22 @@ void main() {
containsIgnoringWhitespace
(
'Changing current working directory to:'
),
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
()
,
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Logger:
()
=>
BufferLogger
.
test
(),
});
testUsingContext
(
'Walks upward looking for a pubspec.yaml and exits if missing'
,
()
async
{
globals
.
fs
.
currentDirectory
=
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
'a'
,
'b'
,
'c'
)
)
fileSystem
.
currentDirectory
=
fileSystem
.
directory
(
'a/b/c'
)
..
createSync
(
recursive:
true
);
fileSystem
.
file
(
'lib/main.dart'
)
.
createSync
(
recursive:
true
);
final
RunCommand
command
=
RunCommand
();
applyMocksToCommand
(
command
);
try
{
await
createTestCommandRunner
(
command
).
run
(<
String
>[
'run'
,
'--fast-start'
,
'--no-pub'
,
]);
fail
(
'Expect exception'
);
...
...
@@ -135,11 +134,11 @@ void main() {
expect
(
e
.
toString
(),
contains
(
'No pubspec.yaml file found'
));
}
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
()
,
FileSystem:
()
=>
fileSystem
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Logger:
()
=>
BufferLogger
.
test
(),
});
group
(
'run app'
,
()
{
MemoryFileSystem
fs
;
MockArtifacts
mockArtifacts
;
...
...
@@ -148,7 +147,7 @@ void main() {
MockUsage
mockUsage
;
Directory
tempDir
;
setUp
All
(()
{
setUp
(()
{
mockArtifacts
=
MockArtifacts
();
mockCache
=
MockCache
();
mockUsage
=
MockUsage
();
...
...
@@ -418,18 +417,10 @@ void main() {
});
group
(
'dart-flags option'
,
()
{
setUpAll
(()
{
final
FakeDevice
fakeDevice
=
FakeDevice
();
when
(
mockDeviceManager
.
getDevices
()).
thenAnswer
((
Invocation
invocation
)
{
return
Future
<
List
<
Device
>>.
value
(<
Device
>[
fakeDevice
]);
});
when
(
mockDeviceManager
.
findTargetDevices
(
any
)).
thenAnswer
(
(
Invocation
invocation
)
=>
Future
<
List
<
Device
>>.
value
(<
Device
>[
fakeDevice
])
);
});
RunCommand
command
;
List
<
String
>
args
;
MockDeviceManager
mockDeviceManager
;
setUp
(()
{
command
=
TestRunCommand
();
args
=
<
String
>
[
...
...
@@ -438,20 +429,14 @@ void main() {
'--no-hot'
,
'--no-pub'
,
];
mockDeviceManager
=
MockDeviceManager
();
final
FakeDevice
fakeDevice
=
FakeDevice
();
when
(
mockDeviceManager
.
getDevices
()).
thenAnswer
((
Invocation
invocation
)
{
return
Future
<
List
<
Device
>>.
value
(<
Device
>[
fakeDevice
]);
});
testUsingContext
(
'is not available on stable channel'
,
()
async
{
// Stable branch.
try
{
await
createTestCommandRunner
(
command
).
run
(
args
);
fail
(
'Expect exception'
);
// ignore: unused_catch_clause
}
on
UsageException
catch
(
e
)
{
// Not available while on stable branch.
}
},
overrides:
<
Type
,
Generator
>{
DeviceManager:
()
=>
mockDeviceManager
,
FlutterVersion:
()
=>
mockStableFlutterVersion
,
when
(
mockDeviceManager
.
findTargetDevices
(
any
)).
thenAnswer
(
(
Invocation
invocation
)
=>
Future
<
List
<
Device
>>.
value
(<
Device
>[
fakeDevice
])
);
});
testUsingContext
(
'is populated in debug mode'
,
()
async
{
...
...
@@ -466,7 +451,6 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
ApplicationPackageFactory:
()
=>
mockApplicationPackageFactory
,
DeviceManager:
()
=>
mockDeviceManager
,
FlutterVersion:
()
=>
mockUnstableFlutterVersion
,
});
testUsingContext
(
'is populated in profile mode'
,
()
async
{
...
...
@@ -483,7 +467,6 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
ApplicationPackageFactory:
()
=>
mockApplicationPackageFactory
,
DeviceManager:
()
=>
mockDeviceManager
,
FlutterVersion:
()
=>
mockUnstableFlutterVersion
,
});
testUsingContext
(
'is not populated in release mode'
,
()
async
{
...
...
@@ -501,7 +484,6 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
ApplicationPackageFactory:
()
=>
mockApplicationPackageFactory
,
DeviceManager:
()
=>
mockDeviceManager
,
FlutterVersion:
()
=>
mockUnstableFlutterVersion
,
});
});
...
...
@@ -554,95 +536,6 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
DeviceManager:
()
=>
mockDeviceManager
,
});
group
(
'--dart-define option'
,
()
{
MemoryFileSystem
fs
;
MockProcessManager
mockProcessManager
;
MockWebRunnerFactory
mockWebRunnerFactory
;
setUpAll
(()
{
final
FakeDevice
fakeDevice
=
FakeDevice
()..
_targetPlatform
=
TargetPlatform
.
web_javascript
;
when
(
mockDeviceManager
.
getDevices
()).
thenAnswer
(
(
Invocation
invocation
)
=>
Future
<
List
<
Device
>>.
value
(<
Device
>[
fakeDevice
])
);
when
(
mockDeviceManager
.
findTargetDevices
(
any
)).
thenAnswer
(
(
Invocation
invocation
)
=>
Future
<
List
<
Device
>>.
value
(<
Device
>[
fakeDevice
])
);
});
RunCommand
command
;
List
<
String
>
args
;
setUp
(()
{
command
=
TestRunCommand
();
args
=
<
String
>
[
'run'
,
'--dart-define=FOO=bar'
,
'--no-hot'
,
'--no-pub'
,
];
applyMocksToCommand
(
command
);
fs
=
MemoryFileSystem
();
mockProcessManager
=
MockProcessManager
();
mockWebRunnerFactory
=
MockWebRunnerFactory
();
});
testUsingContext
(
'populates the environment'
,
()
async
{
final
Directory
tempDir
=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_run_test.'
);
globals
.
fs
.
currentDirectory
=
tempDir
;
final
Directory
libDir
=
tempDir
.
childDirectory
(
'lib'
);
libDir
.
createSync
();
final
File
mainFile
=
libDir
.
childFile
(
'main.dart'
);
mainFile
.
writeAsStringSync
(
'void main() {}'
);
final
Directory
webDir
=
tempDir
.
childDirectory
(
'web'
);
webDir
.
createSync
();
final
File
indexFile
=
libDir
.
childFile
(
'index.html'
);
indexFile
.
writeAsStringSync
(
'<h1>Hello</h1>'
);
await
createTestCommandRunner
(
command
).
run
(
args
);
expect
(
mockWebRunnerFactory
.
_dartDefines
,
<
String
>[
'FOO=bar'
]);
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWebEnabled:
true
,
),
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
mockProcessManager
,
DeviceManager:
()
=>
mockDeviceManager
,
FlutterVersion:
()
=>
mockStableFlutterVersion
,
WebRunnerFactory:
()
=>
mockWebRunnerFactory
,
});
testUsingContext
(
'populates dartDefines in --machine mode'
,
()
async
{
final
Directory
tempDir
=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_run_test.'
);
globals
.
fs
.
currentDirectory
=
tempDir
;
final
Directory
libDir
=
tempDir
.
childDirectory
(
'lib'
);
libDir
.
createSync
();
final
File
mainFile
=
libDir
.
childFile
(
'main.dart'
);
mainFile
.
writeAsStringSync
(
'void main() {}'
);
final
Directory
webDir
=
tempDir
.
childDirectory
(
'web'
);
webDir
.
createSync
();
final
File
indexFile
=
libDir
.
childFile
(
'index.html'
);
indexFile
.
writeAsStringSync
(
'<h1>Hello</h1>'
);
when
(
mockDeviceManager
.
deviceDiscoverers
).
thenReturn
(<
DeviceDiscovery
>[]);
args
.
add
(
'--machine'
);
await
createTestCommandRunner
(
command
).
run
(
args
);
expect
(
mockWebRunnerFactory
.
_dartDefines
,
<
String
>[
'FOO=bar'
]);
},
overrides:
<
Type
,
Generator
>{
FeatureFlags:
()
=>
TestFeatureFlags
(
isWebEnabled:
true
,
),
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
mockProcessManager
,
DeviceManager:
()
=>
mockDeviceManager
,
FlutterVersion:
()
=>
mockStableFlutterVersion
,
WebRunnerFactory:
()
=>
mockWebRunnerFactory
,
});
});
});
}
...
...
@@ -674,7 +567,7 @@ class FakeDevice extends Fake implements Device {
static
const
int
kSuccess
=
1
;
static
const
int
kFailure
=
-
1
;
TargetPlatform
_targetPlatform
=
TargetPlatform
.
ios
;
final
TargetPlatform
_targetPlatform
=
TargetPlatform
.
ios
;
final
bool
_isLocalEmulator
;
@override
...
...
@@ -744,38 +637,3 @@ class FakeDevice extends Fake implements Device {
return
null
;
}
}
class
MockWebRunnerFactory
extends
Mock
implements
WebRunnerFactory
{
List
<
String
>
_dartDefines
;
@override
ResidentRunner
createWebRunner
(
FlutterDevice
device
,
{
String
target
,
bool
stayResident
,
FlutterProject
flutterProject
,
bool
ipv6
,
DebuggingOptions
debuggingOptions
,
UrlTunneller
urlTunneller
,
})
{
_dartDefines
=
debuggingOptions
.
buildInfo
.
dartDefines
;
return
MockWebRunner
();
}
}
class
MockWebRunner
extends
Mock
implements
ResidentRunner
{
@override
bool
get
debuggingEnabled
=>
false
;
@override
Future
<
int
>
run
({
Completer
<
DebugConnectionInfo
>
connectionInfoCompleter
,
Completer
<
void
>
appStartedCompleter
,
String
route
,
})
async
{
return
0
;
}
@override
Future
<
int
>
waitForAppToFinish
()
async
=>
0
;
}
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