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
63fc778f
Unverified
Commit
63fc778f
authored
May 13, 2021
by
Jonah Williams
Committed by
GitHub
May 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mocks from dart plugins test (#82413)
parent
6cb91b1c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
64 deletions
+104
-64
analytics_test.dart
...ages/flutter_tools/test/general.shard/analytics_test.dart
+22
-14
dart_plugin_test.dart
...es/flutter_tools/test/general.shard/dart_plugin_test.dart
+82
-50
No files found.
packages/flutter_tools/test/general.shard/analytics_test.dart
View file @
63fc778f
...
...
@@ -6,6 +6,7 @@
import
'package:args/command_runner.dart'
;
import
'package:file/memory.dart'
;
import
'package:flutter_tools/src/android/android_workflow.dart'
;
import
'package:flutter_tools/src/base/config.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/io.dart'
;
...
...
@@ -21,7 +22,7 @@ import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:flutter_tools/src/runner/flutter_command.dart'
;
import
'package:flutter_tools/src/version.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'package:usage/usage_io.dart'
;
import
'../src/common.dart'
;
...
...
@@ -147,28 +148,24 @@ void main() {
});
});
group
(
'analytics with
mock
s'
,
()
{
group
(
'analytics with
fake
s'
,
()
{
MemoryFileSystem
memoryFileSystem
;
FakeStdio
fakeStdio
;
TestUsage
testUsage
;
FakeClock
fakeClock
;
Doctor
mockD
octor
;
FakeDoctor
d
octor
;
setUp
(()
{
memoryFileSystem
=
MemoryFileSystem
.
test
();
fakeStdio
=
FakeStdio
();
testUsage
=
TestUsage
();
fakeClock
=
FakeClock
();
mockDoctor
=
Mock
Doctor
();
doctor
=
Fake
Doctor
();
});
testUsingContext
(
'flutter commands send timing events'
,
()
async
{
fakeClock
.
times
=
<
int
>[
1000
,
2000
];
when
(
mockDoctor
.
diagnose
(
androidLicenses:
false
,
verbose:
false
,
androidLicenseValidator:
anyNamed
(
'androidLicenseValidator'
)
)).
thenAnswer
((
_
)
async
=>
true
);
doctor
.
diagnoseSucceeds
=
true
;
final
DoctorCommand
command
=
DoctorCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'doctor'
]);
...
...
@@ -180,14 +177,13 @@ void main() {
));
},
overrides:
<
Type
,
Generator
>{
SystemClock:
()
=>
fakeClock
,
Doctor:
()
=>
mockD
octor
,
Doctor:
()
=>
d
octor
,
Usage:
()
=>
testUsage
,
});
testUsingContext
(
'doctor fail sends warning'
,
()
async
{
fakeClock
.
times
=
<
int
>[
1000
,
2000
];
when
(
mockDoctor
.
diagnose
(
androidLicenses:
false
,
verbose:
false
,
androidLicenseValidator:
anyNamed
(
'androidLicenseValidator'
)))
.
thenAnswer
((
_
)
async
=>
false
);
doctor
.
diagnoseSucceeds
=
false
;
final
DoctorCommand
command
=
DoctorCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'doctor'
]);
...
...
@@ -200,7 +196,7 @@ void main() {
));
},
overrides:
<
Type
,
Generator
>{
SystemClock:
()
=>
fakeClock
,
Doctor:
()
=>
mockD
octor
,
Doctor:
()
=>
d
octor
,
Usage:
()
=>
testUsage
,
});
...
...
@@ -363,7 +359,19 @@ class FakeFlutterCommand extends FlutterCommand {
}
}
class
MockDoctor
extends
Mock
implements
Doctor
{}
class
FakeDoctor
extends
Fake
implements
Doctor
{
bool
diagnoseSucceeds
=
false
;
@override
Future
<
bool
>
diagnose
({
bool
androidLicenses
=
false
,
bool
verbose
=
true
,
bool
showColor
=
true
,
AndroidLicenseValidator
androidLicenseValidator
,
})
async
{
return
diagnoseSucceeds
;
}
}
class
FakeClock
extends
Fake
implements
SystemClock
{
List
<
int
>
times
=
<
int
>[];
...
...
packages/flutter_tools/test/general.shard/dart_plugin_test.dart
View file @
63fc778f
...
...
@@ -12,8 +12,8 @@ import 'package:flutter_tools/src/flutter_plugins.dart';
import
'package:flutter_tools/src/globals_null_migrated.dart'
as
globals
;
import
'package:flutter_tools/src/plugins.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:package_config/package_config.dart'
;
import
'package:test/fake.dart'
;
import
'package:yaml/yaml.dart'
;
import
'../src/common.dart'
;
...
...
@@ -22,23 +22,18 @@ import '../src/context.dart';
void
main
(
)
{
group
(
'Dart plugin registrant'
,
()
{
FileSystem
fs
;
Mock
FlutterProject
flutterProject
;
Mock
FlutterManifest
flutterManifest
;
Fake
FlutterProject
flutterProject
;
Fake
FlutterManifest
flutterManifest
;
setUp
(()
async
{
fs
=
MemoryFileSystem
.
test
();
flutterProject
=
MockFlutterProject
();
flutterManifest
=
MockFlutterManifest
();
when
(
flutterManifest
.
dependencies
).
thenReturn
(<
String
>{});
when
(
flutterProject
.
manifest
).
thenReturn
(
flutterManifest
);
when
(
flutterProject
.
directory
).
thenReturn
(
fs
.
systemTempDirectory
.
childDirectory
(
'app'
));
when
(
flutterProject
.
flutterPluginsFile
).
thenReturn
(
flutterProject
.
directory
.
childFile
(
'.flutter-plugins'
));
when
(
flutterProject
.
flutterPluginsDependenciesFile
).
thenReturn
(
flutterProject
.
directory
.
childFile
(
'.flutter-plugins-dependencies'
));
final
Directory
directory
=
fs
.
currentDirectory
.
childDirectory
(
'app'
);
flutterManifest
=
FakeFlutterManifest
();
flutterProject
=
FakeFlutterProject
()
..
manifest
=
flutterManifest
..
directory
=
directory
..
flutterPluginsFile
=
directory
.
childFile
(
'.flutter-plugins'
)
..
flutterPluginsDependenciesFile
=
directory
.
childFile
(
'.flutter-plugins-dependencies'
);
flutterProject
.
directory
.
childFile
(
'.packages'
).
createSync
(
recursive:
true
);
});
...
...
@@ -564,33 +559,8 @@ void main() {
});
group
(
'generateMainDartWithPluginRegistrant'
,
()
{
void
createFakeDartPlugins
(
FlutterProject
flutterProject
,
FlutterManifest
flutterManifest
,
FileSystem
fs
,
Map
<
String
,
String
>
plugins
,
)
{
final
Directory
fakePubCache
=
fs
.
systemTempDirectory
.
childDirectory
(
'cache'
);
final
File
packagesFile
=
flutterProject
.
directory
.
childFile
(
'.packages'
)
..
createSync
(
recursive:
true
);
for
(
final
MapEntry
<
String
,
String
>
entry
in
plugins
.
entries
)
{
final
String
name
=
fs
.
path
.
basename
(
entry
.
key
);
final
Directory
pluginDirectory
=
fakePubCache
.
childDirectory
(
name
);
packagesFile
.
writeAsStringSync
(
'
$name
:file://
${pluginDirectory.childFile('lib').uri}
\n
'
,
mode:
FileMode
.
writeOnlyAppend
);
pluginDirectory
.
childFile
(
'pubspec.yaml'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
entry
.
value
);
}
when
(
flutterManifest
.
dependencies
).
thenReturn
(<
String
>{...
plugins
.
keys
});
}
testUsingContext
(
'Generates new entrypoint'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
)
;
flutterProject
.
isModule
=
true
;
createFakeDartPlugins
(
flutterProject
,
...
...
@@ -739,7 +709,7 @@ void main() {
});
testUsingContext
(
'Plugin without platform support throws tool exit'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
)
;
flutterProject
.
isModule
=
false
;
createFakeDartPlugins
(
flutterProject
,
...
...
@@ -785,7 +755,7 @@ void main() {
});
testUsingContext
(
'Plugin with platform support without dart plugin class throws tool exit'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
)
;
flutterProject
.
isModule
=
false
;
createFakeDartPlugins
(
flutterProject
,
...
...
@@ -858,8 +828,7 @@ void main() {
});
testUsingContext
(
'Does not create new entrypoint if there are no platform resolutions'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
);
when
(
flutterManifest
.
dependencies
).
thenReturn
(<
String
>{});
flutterProject
.
isModule
=
false
;
final
Directory
libDir
=
flutterProject
.
directory
.
childDirectory
(
'lib'
);
libDir
.
createSync
(
recursive:
true
);
...
...
@@ -886,7 +855,7 @@ void main() {
});
testUsingContext
(
'Deletes new entrypoint if there are no platform resolutions'
,
()
async
{
when
(
flutterProject
.
isModule
).
thenReturn
(
false
)
;
flutterProject
.
isModule
=
false
;
createFakeDartPlugins
(
flutterProject
,
...
...
@@ -943,11 +912,74 @@ void main() {
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
});
});
});
}
class
MockFlutterManifest
extends
Mock
implements
FlutterManifest
{}
class
MockFlutterProject
extends
Mock
implements
FlutterProject
{}
void
createFakeDartPlugins
(
FakeFlutterProject
flutterProject
,
FakeFlutterManifest
flutterManifest
,
FileSystem
fs
,
Map
<
String
,
String
>
plugins
,
)
{
final
Directory
fakePubCache
=
fs
.
systemTempDirectory
.
childDirectory
(
'cache'
);
final
File
packagesFile
=
flutterProject
.
directory
.
childFile
(
'.packages'
)
..
createSync
(
recursive:
true
);
for
(
final
MapEntry
<
String
,
String
>
entry
in
plugins
.
entries
)
{
final
String
name
=
fs
.
path
.
basename
(
entry
.
key
);
final
Directory
pluginDirectory
=
fakePubCache
.
childDirectory
(
name
);
packagesFile
.
writeAsStringSync
(
'
$name
:file://
${pluginDirectory.childFile('lib').uri}
\n
'
,
mode:
FileMode
.
writeOnlyAppend
,
);
pluginDirectory
.
childFile
(
'pubspec.yaml'
)
..
createSync
(
recursive:
true
)
..
writeAsStringSync
(
entry
.
value
);
}
flutterManifest
.
dependencies
=
plugins
.
keys
.
toSet
();
}
class
FakeFlutterManifest
extends
Fake
implements
FlutterManifest
{
@override
Set
<
String
>
dependencies
=
<
String
>{};
}
class
FakeFlutterProject
extends
Fake
implements
FlutterProject
{
@override
bool
isModule
=
false
;
@override
FlutterManifest
manifest
;
@override
Directory
directory
;
@override
File
flutterPluginsFile
;
@override
File
flutterPluginsDependenciesFile
;
@override
IosProject
ios
;
@override
AndroidProject
android
;
@override
WebProject
web
;
@override
MacOSProject
macos
;
@override
LinuxProject
linux
;
@override
WindowsProject
windows
;
@override
WindowsUwpProject
windowsUwp
;
}
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