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
52415cb0
Unverified
Commit
52415cb0
authored
Apr 25, 2019
by
Jonah Williams
Committed by
GitHub
Apr 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
baby-steps to testing/refactoring flutter_platform (#31616)
parent
eca93640
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
26 deletions
+61
-26
flutter_platform.dart
packages/flutter_tools/lib/src/test/flutter_platform.dart
+31
-26
flutter_platform_test.dart
packages/flutter_tools/test/flutter_platform_test.dart
+30
-0
No files found.
packages/flutter_tools/lib/src/test/flutter_platform.dart
View file @
52415cb0
...
...
@@ -74,7 +74,7 @@ final Map<InternetAddressType, InternetAddress> _kHosts = <InternetAddressType,
/// Configure the `test` package to work with Flutter.
///
/// On systems where each [
_
FlutterPlatform] is only used to run one test suite
/// On systems where each [FlutterPlatform] is only used to run one test suite
/// (that is, one Dart file with a `*_test.dart` file name and a single `void
/// main()`), you can set an observatory port explicitly.
void
installHook
(
{
...
...
@@ -99,25 +99,27 @@ void installHook({
assert
(
enableObservatory
||
(!
startPaused
&&
observatoryPort
==
null
));
hack
.
registerPlatformPlugin
(
<
Runtime
>[
Runtime
.
vm
],
()
=>
_FlutterPlatform
(
shellPath:
shellPath
,
watcher:
watcher
,
machine:
machine
,
enableObservatory:
enableObservatory
,
startPaused:
startPaused
,
disableServiceAuthCodes:
disableServiceAuthCodes
,
explicitObservatoryPort:
observatoryPort
,
host:
_kHosts
[
serverType
],
port:
port
,
precompiledDillPath:
precompiledDillPath
,
precompiledDillFiles:
precompiledDillFiles
,
trackWidgetCreation:
trackWidgetCreation
,
updateGoldens:
updateGoldens
,
buildTestAssets:
buildTestAssets
,
projectRootDirectory:
projectRootDirectory
,
flutterProject:
flutterProject
,
icudtlPath:
icudtlPath
,
),
()
{
return
FlutterPlatform
(
shellPath:
shellPath
,
watcher:
watcher
,
machine:
machine
,
enableObservatory:
enableObservatory
,
startPaused:
startPaused
,
disableServiceAuthCodes:
disableServiceAuthCodes
,
explicitObservatoryPort:
observatoryPort
,
host:
_kHosts
[
serverType
],
port:
port
,
precompiledDillPath:
precompiledDillPath
,
precompiledDillFiles:
precompiledDillFiles
,
trackWidgetCreation:
trackWidgetCreation
,
updateGoldens:
updateGoldens
,
buildTestAssets:
buildTestAssets
,
projectRootDirectory:
projectRootDirectory
,
flutterProject:
flutterProject
,
icudtlPath:
icudtlPath
,
);
}
);
}
...
...
@@ -380,8 +382,9 @@ class _Compiler {
}
}
class
_FlutterPlatform
extends
PlatformPlugin
{
_FlutterPlatform
({
/// The flutter test platform used to integrate with package:test.
class
FlutterPlatform
extends
PlatformPlugin
{
FlutterPlatform
({
@required
this
.
shellPath
,
this
.
watcher
,
this
.
enableObservatory
,
...
...
@@ -462,14 +465,16 @@ class _FlutterPlatform extends PlatformPlugin {
}
@override
StreamChannel
<
dynamic
>
loadChannel
(
String
testP
ath
,
SuitePlatform
platform
)
{
StreamChannel
<
dynamic
>
loadChannel
(
String
p
ath
,
SuitePlatform
platform
)
{
if
(
_testCount
>
0
)
{
// Fail if there will be a port conflict.
if
(
explicitObservatoryPort
!=
null
)
if
(
explicitObservatoryPort
!=
null
)
{
throwToolExit
(
'installHook() was called with an observatory port or debugger mode enabled, but then more than one test suite was run.'
);
}
// Fail if we're passing in a precompiled entry-point.
if
(
precompiledDillPath
!=
null
)
if
(
precompiledDillPath
!=
null
)
{
throwToolExit
(
'installHook() was called with a precompiled test entry-point, but then more than one test suite was run.'
);
}
}
final
int
ourTestCount
=
_testCount
;
_testCount
+=
1
;
...
...
@@ -488,7 +493,7 @@ class _FlutterPlatform extends PlatformPlugin {
localController
.
stream
,
remoteSink
,
);
testCompleteCompleter
.
complete
(
_startTest
(
testP
ath
,
localChannel
,
ourTestCount
));
testCompleteCompleter
.
complete
(
_startTest
(
p
ath
,
localChannel
,
ourTestCount
));
return
remoteChannel
;
}
...
...
packages/flutter_tools/test/flutter_platform_test.dart
0 → 100644
View file @
52415cb0
// 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/common.dart'
;
import
'package:flutter_tools/src/test/flutter_platform.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:test_core/backend.dart'
;
import
'src/common.dart'
;
import
'src/context.dart'
;
void
main
(
)
{
group
(
'FlutterPlatform'
,
()
{
testUsingContext
(
'ensureConfiguration throws an error if an explicitObservatoryPort is specified and more than one test file'
,
()
async
{
final
FlutterPlatform
flutterPlatfrom
=
FlutterPlatform
(
shellPath:
'/'
,
explicitObservatoryPort:
1234
);
flutterPlatfrom
.
loadChannel
(
'test1.dart'
,
MockPlatform
());
expect
(()
=>
flutterPlatfrom
.
loadChannel
(
'test2.dart'
,
MockPlatform
()),
throwsA
(
isA
<
ToolExit
>()));
});
testUsingContext
(
'ensureConfiguration throws an error if a precompiled entrypoint is specified and more that one test file'
,
()
{
final
FlutterPlatform
flutterPlatfrom
=
FlutterPlatform
(
shellPath:
'/'
,
precompiledDillPath:
'example.dill'
);
flutterPlatfrom
.
loadChannel
(
'test1.dart'
,
MockPlatform
());
expect
(()
=>
flutterPlatfrom
.
loadChannel
(
'test2.dart'
,
MockPlatform
()),
throwsA
(
isA
<
ToolExit
>()));
});
});
}
class
MockPlatform
extends
Mock
implements
SuitePlatform
{}
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