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
d1178ae7
Unverified
Commit
d1178ae7
authored
Oct 01, 2020
by
Kate Lovett
Committed by
GitHub
Oct 01, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix local gold output for flutter/flutter (#66139)
parent
978f912d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
18 deletions
+49
-18
flutter_goldens.dart
packages/flutter_goldens/lib/flutter_goldens.dart
+3
-2
_goldens_io.dart
packages/flutter_test/lib/src/_goldens_io.dart
+10
-11
goldens_test.dart
packages/flutter_test/test/goldens_test.dart
+36
-5
No files found.
packages/flutter_goldens/lib/flutter_goldens.dart
View file @
d1178ae7
...
...
@@ -9,6 +9,7 @@ import 'dart:typed_data' show Uint8List;
import
'package:file/file.dart'
;
import
'package:file/local.dart'
;
import
'package:flutter/foundation.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:meta/meta.dart'
;
import
'package:platform/platform.dart'
;
...
...
@@ -670,7 +671,7 @@ class FlutterLocalFileComparator extends FlutterGoldenFileComparator with LocalC
if
(
result
.
passed
)
return
true
;
generateFailureOutput
(
result
,
golden
,
basedir
);
return
false
;
final
String
error
=
await
generateFailureOutput
(
result
,
golden
,
basedir
);
throw
FlutterError
(
error
)
;
}
}
packages/flutter_test/lib/src/_goldens_io.dart
View file @
d1178ae7
...
...
@@ -8,11 +8,13 @@ import 'dart:math' as math;
import
'dart:typed_data'
;
import
'dart:ui'
;
import
'package:flutter/foundation.dart'
;
import
'package:path/path.dart'
as
path
;
// ignore: deprecated_member_use
import
'package:test_api/test_api.dart'
as
test_package
show
TestFailure
;
import
'goldens.dart'
;
import
'test_async_utils.dart'
;
/// The default [GoldenFileComparator] implementation for `flutter test`.
///
...
...
@@ -102,7 +104,8 @@ class LocalFileComparator extends GoldenFileComparator with LocalComparisonOutpu
);
if
(!
result
.
passed
)
{
await
generateFailureOutput
(
result
,
golden
,
basedir
);
final
String
error
=
await
generateFailureOutput
(
result
,
golden
,
basedir
);
throw
FlutterError
(
error
);
}
return
result
.
passed
;
}
...
...
@@ -125,16 +128,15 @@ class LocalComparisonOutput {
/// Writes out diffs from the [ComparisonResult] of a golden file test.
///
/// Will throw an error if a null result is provided.
Future
<
void
>
generateFailureOutput
(
Future
<
String
>
generateFailureOutput
(
ComparisonResult
result
,
Uri
golden
,
Uri
basedir
,
{
String
key
=
''
,
})
async
{
})
async
=>
TestAsyncUtils
.
guard
<
String
>(()
async
{
String
additionalFeedback
=
''
;
if
(
result
.
diffs
!=
null
)
{
additionalFeedback
=
'
\n
Failure feedback can be found at '
'
${path.join(basedir.path, 'failures')}
'
;
additionalFeedback
=
'
\n
Failure feedback can be found at
${path.join(basedir.path, 'failures')}
'
;
final
Map
<
String
,
Image
>
diffs
=
result
.
diffs
!.
cast
<
String
,
Image
>();
for
(
final
MapEntry
<
String
,
Image
>
entry
in
diffs
.
entries
)
{
final
File
output
=
getFailureFile
(
...
...
@@ -143,15 +145,12 @@ class LocalComparisonOutput {
basedir
,
);
output
.
parent
.
createSync
(
recursive:
true
);
final
ByteData
?
pngBytes
=
await
entry
.
value
.
toByteData
(
format:
ImageByteFormat
.
png
);
final
ByteData
?
pngBytes
=
await
entry
.
value
.
toByteData
(
format:
ImageByteFormat
.
png
);
output
.
writeAsBytesSync
(
pngBytes
!.
buffer
.
asUint8List
());
}
}
throw
test_package
.
TestFailure
(
'Golden "
$golden
":
${result.error}$additionalFeedback
'
);
}
return
'Golden "
$golden
":
${result.error}$additionalFeedback
'
;
});
/// Returns the appropriate file for a given diff from a [ComparisonResult].
File
getFailureFile
(
String
failure
,
Uri
golden
,
Uri
basedir
)
{
...
...
packages/flutter_test/test/goldens_test.dart
View file @
d1178ae7
...
...
@@ -9,6 +9,7 @@ import 'dart:io' as io;
import
'dart:typed_data'
;
import
'package:file/memory.dart'
;
import
'package:flutter/foundation.dart'
show
DiagnosticLevel
,
DiagnosticsNode
,
DiagnosticPropertiesBuilder
,
FlutterError
;
import
'package:flutter_test/flutter_test.dart'
hide
test
;
import
'package:flutter_test/flutter_test.dart'
as
test_package
;
...
...
@@ -102,6 +103,36 @@ void main() {
expect
(
comparator
.
basedir
,
Uri
.
parse
(
'./'
));
});
test
(
'throws if local output is not awaited'
,
()
{
try
{
comparator
.
generateFailureOutput
(
ComparisonResult
(
passed:
false
),
Uri
.
parse
(
'foo_test.dart'
),
Uri
.
parse
(
'/foo/bar/'
),
);
TestAsyncUtils
.
verifyAllScopesClosed
();
throw
'unexpectedly did not throw'
;
}
on
FlutterError
catch
(
e
)
{
final
List
<
String
>
lines
=
e
.
message
.
split
(
'
\n
'
);
expectSync
(
lines
[
0
],
'Asynchronous call to guarded function leaked.'
);
expectSync
(
lines
[
1
],
'You must use "await" with all Future-returning test APIs.'
);
expectSync
(
lines
[
2
],
matches
(
r'^The guarded method "generateFailureOutput" from class '
r'LocalComparisonOutput was called from .*goldens_test.dart on line '
r'[0-9]+, but never completed before its parent scope closed\.$'
),
);
expectSync
(
lines
.
length
,
3
);
final
DiagnosticPropertiesBuilder
propertiesBuilder
=
DiagnosticPropertiesBuilder
();
e
.
debugFillProperties
(
propertiesBuilder
);
final
List
<
DiagnosticsNode
>
information
=
propertiesBuilder
.
properties
;
expectSync
(
information
.
length
,
3
);
expectSync
(
information
[
0
].
level
,
DiagnosticLevel
.
summary
);
expectSync
(
information
[
1
].
level
,
DiagnosticLevel
.
hint
);
expectSync
(
information
[
2
].
level
,
DiagnosticLevel
.
info
);
}
});
group
(
'compare'
,
()
{
Future
<
bool
>
doComparison
([
String
golden
=
'golden.png'
])
{
final
Uri
uri
=
fs
.
file
(
fix
(
golden
)).
uri
;
...
...
@@ -157,7 +188,7 @@ void main() {
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
TestFailure
catch
(
error
)
{
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'% diff detected'
));
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
...
...
@@ -186,7 +217,7 @@ void main() {
try
{
await
doComparison
(
'subdir/golden.png'
);
fail
(
'TestFailure expected but not thrown.'
);
}
on
TestFailure
catch
(
error
)
{
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'% diff detected'
));
final
io
.
File
master
=
fs
.
file
(
fix
(
'/failures/golden_masterImage.png'
)
...
...
@@ -221,7 +252,7 @@ void main() {
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
TestFailure
catch
(
error
)
{
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'image sizes do not match'
));
}
});
...
...
@@ -231,7 +262,7 @@ void main() {
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
TestFailure
catch
(
error
)
{
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'% diff detected'
));
}
});
...
...
@@ -241,7 +272,7 @@ void main() {
try
{
await
doComparison
();
fail
(
'TestFailure expected but not thrown.'
);
}
on
TestFailure
catch
(
error
)
{
}
on
FlutterError
catch
(
error
)
{
expect
(
error
.
message
,
contains
(
'null image provided'
));
}
});
...
...
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