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
a1c185f3
Unverified
Commit
a1c185f3
authored
Aug 26, 2019
by
Collin Jackson
Committed by
GitHub
Aug 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix plugin template app's tests (#39080)
* Fix plugin template * Add test of plugin template working
parent
19cdb21c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
30 deletions
+61
-30
plugin_tests.dart
dev/devicelab/lib/tasks/plugin_tests.dart
+59
-30
projectName_test.dart.tmpl
...er_tools/templates/plugin/test/projectName_test.dart.tmpl
+2
-0
No files found.
dev/devicelab/lib/tasks/plugin_tests.dart
View file @
a1c185f3
...
...
@@ -23,8 +23,8 @@ TaskFunction combine(List<TaskFunction> tasks) {
};
}
/// Defines task that creates new Flutter project, adds a
plugin, and then
/// builds the specified [buildTarget].
/// Defines task that creates new Flutter project, adds a
local and remote
///
plugin, and then
builds the specified [buildTarget].
class
PluginTest
{
PluginTest
(
this
.
buildTarget
,
this
.
options
);
...
...
@@ -32,19 +32,32 @@ class PluginTest {
final
List
<
String
>
options
;
Future
<
TaskResult
>
call
()
async
{
section
(
'Create Flutter project'
);
final
Directory
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_devicelab_plugin_test.'
);
final
Directory
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_devicelab_plugin_test.'
);
try
{
final
FlutterProject
project
=
await
FlutterProject
.
create
(
tempDir
,
options
);
section
(
'Create plugin'
);
final
_FlutterProject
plugin
=
await
_FlutterProject
.
create
(
tempDir
,
options
,
name:
'plugintest'
,
template:
'plugin'
);
section
(
'Test plugin'
);
await
plugin
.
test
();
section
(
'Create Flutter app'
);
final
_FlutterProject
app
=
await
_FlutterProject
.
create
(
tempDir
,
options
,
name:
'plugintestapp'
,
template:
'app'
);
try
{
if
(
buildTarget
==
'ios'
)
await
prepareProvisioningCertificates
(
project
.
rootPath
);
section
(
'Add plugin'
);
await
project
.
addPlugin
(
'path_provider'
);
section
(
'Build'
);
await
project
.
build
(
buildTarget
);
await
prepareProvisioningCertificates
(
app
.
rootPath
);
section
(
'Add plugins'
);
await
app
.
addPlugin
(
'plugintest'
,
pluginPath:
path
.
join
(
'..'
,
'plugintest'
));
await
app
.
addPlugin
(
'path_provider'
);
section
(
'Build app'
);
await
app
.
build
(
buildTarget
);
section
(
'Test app'
);
await
app
.
test
();
}
finally
{
await
project
.
delete
();
await
plugin
.
delete
();
await
app
.
delete
();
}
return
TaskResult
.
success
(
null
);
}
catch
(
e
)
{
...
...
@@ -55,34 +68,50 @@ class PluginTest {
}
}
class
FlutterProject
{
FlutterProject
(
this
.
parent
,
this
.
name
);
class
_
FlutterProject
{
_
FlutterProject
(
this
.
parent
,
this
.
name
);
final
Directory
parent
;
final
String
name
;
static
Future
<
FlutterProject
>
create
(
Directory
directory
,
List
<
String
>
options
)
async
{
await
inDirectory
(
directory
,
()
async
{
await
flutter
(
'create'
,
options:
<
String
>[
'--template=app'
,
'--org'
,
'io.flutter.devicelab'
,
...
options
,
'plugintest'
],
);
});
return
FlutterProject
(
directory
,
'plugintest'
);
}
String
get
rootPath
=>
path
.
join
(
parent
.
path
,
name
);
Future
<
void
>
addPlugin
(
String
plugin
)
async
{
Future
<
void
>
addPlugin
(
String
plugin
,
{
String
pluginPath
}
)
async
{
final
File
pubspec
=
File
(
path
.
join
(
rootPath
,
'pubspec.yaml'
));
String
content
=
await
pubspec
.
readAsString
();
final
String
dependency
=
pluginPath
!=
null
?
'
$plugin
:
\n
path:
$pluginPath
'
:
'
$plugin
:'
;
content
=
content
.
replaceFirst
(
'
\n
dependencies:
\n
'
,
'
\n
dependencies:
\n
$
plugin
:
\n
'
,
'
\n
dependencies:
\n
$
dependency
\n
'
,
);
await
pubspec
.
writeAsString
(
content
,
flush:
true
);
}
Future
<
void
>
test
()
async
{
await
inDirectory
(
Directory
(
rootPath
),
()
async
{
await
flutter
(
'test'
);
});
}
static
Future
<
_FlutterProject
>
create
(
Directory
directory
,
List
<
String
>
options
,
{
String
name
,
String
template
})
async
{
await
inDirectory
(
directory
,
()
async
{
await
flutter
(
'create'
,
options:
<
String
>[
'--template=
$template
'
,
'--org'
,
'io.flutter.devicelab'
,
...
options
,
name
],
);
});
return
_FlutterProject
(
directory
,
name
);
}
Future
<
void
>
build
(
String
target
)
async
{
await
inDirectory
(
Directory
(
rootPath
),
()
async
{
await
flutter
(
'build'
,
options:
<
String
>[
target
]);
...
...
@@ -93,11 +122,11 @@ class FlutterProject {
if
(
Platform
.
isWindows
)
{
// A running Gradle daemon might prevent us from deleting the project
// folder on Windows.
await
exec
(
path
.
absolute
(
path
.
join
(
rootPath
,
'android'
,
'gradlew.bat'
)),
<
String
>[
'--stop'
],
canFail:
true
,
);
final
String
wrapperPath
=
path
.
absolute
(
path
.
join
(
rootPath
,
'android'
,
'gradlew.bat'
));
if
(
File
(
wrapperPath
).
existsSync
())
{
await
exec
(
wrapperPath
,
<
String
>[
'--stop'
],
canFail:
true
);
}
// TODO(ianh): Investigating if flakiness is timing dependent.
await
Future
<
void
>.
delayed
(
const
Duration
(
seconds:
10
));
}
...
...
packages/flutter_tools/templates/plugin/test/projectName_test.dart.tmpl
View file @
a1c185f3
...
...
@@ -5,6 +5,8 @@ import 'package:{{projectName}}/{{projectName}}.dart';
void main() {
const MethodChannel channel = MethodChannel('{{projectName}}');
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
return '42';
...
...
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