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
e2dfd73c
Unverified
Commit
e2dfd73c
authored
Apr 30, 2019
by
chunhtai
Committed by
GitHub
Apr 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only build asset when there is asset declared in pubspec (#31804)
parent
514fb2c7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
24 deletions
+36
-24
binding.dart
packages/flutter_test/lib/src/binding.dart
+32
-21
test.dart
packages/flutter_tools/lib/src/commands/test.dart
+4
-3
No files found.
packages/flutter_test/lib/src/binding.dart
View file @
e2dfd73c
...
...
@@ -740,7 +740,8 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override
int
get
microtaskCount
=>
_currentFakeAsync
.
microtaskCount
;
static
Set
<
String
>
_allowedKeys
;
/// A whitelist [Set] that is used in mocking the asset message channel.
static
Set
<
String
>
_allowedAssetKeys
;
void
_mockFlutterAssets
()
{
if
(!
Platform
.
environment
.
containsKey
(
'UNIT_TEST_ASSETS'
))
{
...
...
@@ -748,29 +749,39 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
}
final
String
assetFolderPath
=
Platform
.
environment
[
'UNIT_TEST_ASSETS'
];
_ensureInitialized
(
assetFolderPath
);
BinaryMessages
.
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
message
)
{
final
String
key
=
utf8
.
decode
(
message
.
buffer
.
asUint8List
());
if
(
_allowedKeys
.
contains
(
key
))
{
final
File
asset
=
File
(
path
.
join
(
assetFolderPath
,
key
));
final
Uint8List
encoded
=
Uint8List
.
fromList
(
asset
.
readAsBytesSync
());
return
Future
<
ByteData
>.
value
(
encoded
.
buffer
.
asByteData
());
}
});
if
(
_allowedAssetKeys
.
isNotEmpty
)
{
BinaryMessages
.
setMockMessageHandler
(
'flutter/assets'
,
(
ByteData
message
)
{
final
String
key
=
utf8
.
decode
(
message
.
buffer
.
asUint8List
());
if
(
_allowedAssetKeys
.
contains
(
key
))
{
final
File
asset
=
File
(
path
.
join
(
assetFolderPath
,
key
));
final
Uint8List
encoded
=
Uint8List
.
fromList
(
asset
.
readAsBytesSync
());
return
Future
<
ByteData
>.
value
(
encoded
.
buffer
.
asByteData
());
}
});
}
}
void
_ensureInitialized
(
String
assetFolderPath
)
{
if
(
_allowedKeys
==
null
)
{
final
File
manifestFile
=
File
(
path
.
join
(
assetFolderPath
,
'AssetManifest.json'
));
final
Map
<
String
,
dynamic
>
manifest
=
json
.
decode
(
manifestFile
.
readAsStringSync
());
_allowedKeys
=
<
String
>{
'AssetManifest.json'
,
};
for
(
List
<
dynamic
>
value
in
manifest
.
values
)
{
final
List
<
String
>
strList
=
List
<
String
>.
from
(
value
);
_allowedKeys
.
addAll
(
strList
);
}
if
(
_allowedAssetKeys
!=
null
)
{
return
;
}
final
File
manifestFile
=
File
(
path
.
join
(
assetFolderPath
,
'AssetManifest.json'
));
// If the file does not exist, it means there is no asset declared in
// the project.
if
(!
manifestFile
.
existsSync
())
{
_allowedAssetKeys
=
<
String
>{};
return
;
}
final
Map
<
String
,
dynamic
>
manifest
=
json
.
decode
(
manifestFile
.
readAsStringSync
());
_allowedAssetKeys
=
<
String
>{
'AssetManifest.json'
,
};
for
(
List
<
dynamic
>
value
in
manifest
.
values
)
{
final
List
<
String
>
strList
=
List
<
String
>.
from
(
value
);
_allowedAssetKeys
.
addAll
(
strList
);
}
}
...
...
packages/flutter_tools/lib/src/commands/test.dart
View file @
e2dfd73c
...
...
@@ -127,13 +127,14 @@ class TestCommand extends FastFlutterCommand {
await
pubGet
(
context:
PubContext
.
getVerifyContext
(
name
),
skipPubspecYamlCheck:
true
);
}
final
bool
buildTestAssets
=
argResults
[
'test-assets'
];
if
(
buildTestAssets
)
{
await
_buildTestAsset
();
}
final
List
<
String
>
names
=
argResults
[
'name'
];
final
List
<
String
>
plainNames
=
argResults
[
'plain-name'
];
final
FlutterProject
flutterProject
=
FlutterProject
.
current
();
if
(
buildTestAssets
&&
flutterProject
.
manifest
.
assets
.
isNotEmpty
)
{
await
_buildTestAsset
();
}
Iterable
<
String
>
files
=
argResults
.
rest
.
map
<
String
>((
String
testPath
)
=>
fs
.
path
.
absolute
(
testPath
)).
toList
();
final
bool
startPaused
=
argResults
[
'start-paused'
];
...
...
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