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
4832e64c
Unverified
Commit
4832e64c
authored
Nov 19, 2020
by
Jonah Williams
Committed by
GitHub
Nov 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove globals from flutter web platform (#70863)
parent
085ff127
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
306 additions
and
280 deletions
+306
-280
flutter_web_goldens.dart
packages/flutter_tools/lib/src/test/flutter_web_goldens.dart
+195
-0
flutter_web_platform.dart
...ages/flutter_tools/lib/src/test/flutter_web_platform.dart
+95
-278
runner.dart
packages/flutter_tools/lib/src/test/runner.dart
+14
-0
golden_comparator_process_test.dart
...est/general.shard/web/golden_comparator_process_test.dart
+1
-1
golden_comparator_test.dart
..._tools/test/general.shard/web/golden_comparator_test.dart
+1
-1
No files found.
packages/flutter_tools/lib/src/test/flutter_web_goldens.dart
0 → 100644
View file @
4832e64c
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// ignore_for_file: implementation_imports
import
'dart:async'
;
import
'dart:typed_data'
;
import
'../base/common.dart'
;
import
'../base/file_system.dart'
;
import
'../base/io.dart'
;
import
'../convert.dart'
;
import
'../globals.dart'
as
globals
;
import
'test_compiler.dart'
;
import
'test_config.dart'
;
/// Helper class to start golden file comparison in a separate process.
///
/// Golden file comparator is configured using flutter_test_config.dart and that
/// file can contain arbitrary Dart code that depends on dart:ui. Thus it has to
/// be executed in a `flutter_tester` environment. This helper class generates a
/// Dart file configured with flutter_test_config.dart to perform the comparison
/// of golden files.
class
TestGoldenComparator
{
/// Creates a [TestGoldenComparator] instance.
TestGoldenComparator
(
this
.
shellPath
,
this
.
compilerFactory
)
:
tempDir
=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_web_platform.'
);
final
String
shellPath
;
final
Directory
tempDir
;
final
TestCompiler
Function
()
compilerFactory
;
TestCompiler
_compiler
;
TestGoldenComparatorProcess
_previousComparator
;
Uri
_previousTestUri
;
Future
<
void
>
close
()
async
{
tempDir
.
deleteSync
(
recursive:
true
);
await
_compiler
?.
dispose
();
await
_previousComparator
?.
close
();
}
/// Start golden comparator in a separate process. Start one file per test file
/// to reduce the overhead of starting `flutter_tester`.
Future
<
TestGoldenComparatorProcess
>
_processForTestFile
(
Uri
testUri
)
async
{
if
(
testUri
==
_previousTestUri
)
{
return
_previousComparator
;
}
final
String
bootstrap
=
TestGoldenComparatorProcess
.
generateBootstrap
(
testUri
);
final
Process
process
=
await
_startProcess
(
bootstrap
);
unawaited
(
_previousComparator
?.
close
());
_previousComparator
=
TestGoldenComparatorProcess
(
process
);
_previousTestUri
=
testUri
;
return
_previousComparator
;
}
Future
<
Process
>
_startProcess
(
String
testBootstrap
)
async
{
// Prepare the Dart file that will talk to us and start the test.
final
File
listenerFile
=
(
await
tempDir
.
createTemp
(
'listener'
)).
childFile
(
'listener.dart'
);
await
listenerFile
.
writeAsString
(
testBootstrap
);
// Lazily create the compiler
_compiler
=
_compiler
??
compilerFactory
();
final
String
output
=
await
_compiler
.
compile
(
listenerFile
.
uri
);
final
List
<
String
>
command
=
<
String
>[
shellPath
,
'--disable-observatory'
,
'--non-interactive'
,
'--packages=
${globals.fs.path.join('.dart_tool', 'package_config.json')}
'
,
output
,
];
final
Map
<
String
,
String
>
environment
=
<
String
,
String
>{
// Chrome is the only supported browser currently.
'FLUTTER_TEST_BROWSER'
:
'chrome'
,
};
return
globals
.
processManager
.
start
(
command
,
environment:
environment
);
}
Future
<
String
>
compareGoldens
(
Uri
testUri
,
Uint8List
bytes
,
Uri
goldenKey
,
bool
updateGoldens
)
async
{
final
File
imageFile
=
await
(
await
tempDir
.
createTemp
(
'image'
)).
childFile
(
'image'
).
writeAsBytes
(
bytes
);
final
TestGoldenComparatorProcess
process
=
await
_processForTestFile
(
testUri
);
process
.
sendCommand
(
imageFile
,
goldenKey
,
updateGoldens
);
final
Map
<
String
,
dynamic
>
result
=
await
process
.
getResponse
();
if
(
result
==
null
)
{
return
'unknown error'
;
}
else
{
return
(
result
[
'success'
]
as
bool
)
?
null
:
((
result
[
'message'
]
as
String
)
??
'does not match'
);
}
}
}
/// Represents a `flutter_tester` process started for golden comparison. Also
/// handles communication with the child process.
class
TestGoldenComparatorProcess
{
/// Creates a [TestGoldenComparatorProcess] backed by [process].
TestGoldenComparatorProcess
(
this
.
process
)
{
// Pipe stdout and stderr to printTrace and printError.
// Also parse stdout as a stream of JSON objects.
streamIterator
=
StreamIterator
<
Map
<
String
,
dynamic
>>(
process
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
where
((
String
line
)
{
globals
.
printTrace
(
'<<<
$line
'
);
return
line
.
isNotEmpty
&&
line
[
0
]
==
'{'
;
})
.
map
<
dynamic
>(
jsonDecode
)
.
cast
<
Map
<
String
,
dynamic
>>());
process
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
forEach
((
String
line
)
{
globals
.
printError
(
'<<<
$line
'
);
});
}
final
Process
process
;
StreamIterator
<
Map
<
String
,
dynamic
>>
streamIterator
;
Future
<
void
>
close
()
async
{
await
process
.
stdin
.
close
();
process
.
kill
();
}
void
sendCommand
(
File
imageFile
,
Uri
goldenKey
,
bool
updateGoldens
)
{
final
Object
command
=
jsonEncode
(<
String
,
dynamic
>{
'imageFile'
:
imageFile
.
path
,
'key'
:
goldenKey
.
toString
(),
'update'
:
updateGoldens
,
});
globals
.
printTrace
(
'Preparing to send command:
$command
'
);
process
.
stdin
.
writeln
(
command
);
}
Future
<
Map
<
String
,
dynamic
>>
getResponse
()
async
{
final
bool
available
=
await
streamIterator
.
moveNext
();
assert
(
available
);
return
streamIterator
.
current
;
}
static
String
generateBootstrap
(
Uri
testUri
)
{
final
File
testConfigFile
=
findTestConfigFile
(
globals
.
fs
.
file
(
testUri
));
// Generate comparator process for the file.
return
'''
// @dart=2.9
import '
dart:
convert
'; // ignore: dart_convert_import
import '
dart:
io
'; // ignore: dart_io_import
import '
package:
flutter_test
/
flutter_test
.
dart
';
${testConfigFile != null ? "import '${Uri.file(testConfigFile.path)}
'
as
test_config
;
" : ""}
void main() async {
LocalFileComparator comparator = LocalFileComparator(Uri.parse('
$testUri
'));
goldenFileComparator = comparator;
${testConfigFile != null ? 'test_config.testExecutable(() async {' : ''}
final commands = stdin
.transform<String>(utf8.decoder)
.transform<String>(const LineSplitter())
.map<Object>(jsonDecode);
await for (final Object command in commands) {
if (command is Map<String, dynamic>) {
File imageFile = File(command['imageFile']);
Uri goldenKey = Uri.parse(command['key']);
bool update = command['update'];
final bytes = await File(imageFile.path).readAsBytes();
if (update) {
await goldenFileComparator.update(goldenKey, bytes);
print(jsonEncode({'success': true}));
} else {
try {
bool success = await goldenFileComparator.compare(bytes, goldenKey);
print(jsonEncode({'success': success}));
} on Exception catch (ex) {
print(jsonEncode({'success': false, 'message': '
\
$ex
'}));
}
}
} else {
print('object type is not right');
}
}
${testConfigFile != null ? '}
);' : ''}
}
''';
}
}
packages/flutter_tools/lib/src/test/flutter_web_platform.dart
View file @
4832e64c
This diff is collapsed.
Click to expand it.
packages/flutter_tools/lib/src/test/runner.dart
View file @
4832e64c
...
...
@@ -11,6 +11,7 @@ import '../base/io.dart';
import
'../build_info.dart'
;
import
'../globals.dart'
as
globals
;
import
'../project.dart'
;
import
'../web/chrome.dart'
;
import
'../web/compile.dart'
;
import
'../web/memory_fs.dart'
;
import
'flutter_platform.dart'
as
loader
;
...
...
@@ -139,6 +140,8 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
testWrapper
.
registerPlatformPlugin
(
<
Runtime
>[
Runtime
.
chrome
],
()
{
// TODO(jonahwilliams): refactor this into a factory that handles
// providing dependencies.
return
FlutterWebPlatform
.
start
(
flutterProject
.
directory
.
path
,
updateGoldens:
updateGoldens
,
...
...
@@ -147,6 +150,17 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
pauseAfterLoad:
startPaused
,
buildInfo:
buildInfo
,
webMemoryFS:
result
,
logger:
globals
.
logger
,
fileSystem:
globals
.
fs
,
artifacts:
globals
.
artifacts
,
chromiumLauncher:
ChromiumLauncher
(
fileSystem:
globals
.
fs
,
platform:
globals
.
platform
,
processManager:
globals
.
processManager
,
operatingSystemUtils:
globals
.
os
,
browserFinder:
findChromeExecutable
,
logger:
globals
.
logger
,
),
);
},
);
...
...
packages/flutter_tools/test/general.shard/web/golden_comparator_process_test.dart
View file @
4832e64c
...
...
@@ -5,8 +5,8 @@
import
'dart:convert'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/test/flutter_web_platform.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:flutter_tools/src/test/flutter_web_goldens.dart'
;
import
'../../src/common.dart'
;
import
'../../src/mocks.dart'
;
...
...
packages/flutter_tools/test/general.shard/web/golden_comparator_test.dart
View file @
4832e64c
...
...
@@ -5,7 +5,7 @@
import
'dart:convert'
;
import
'dart:typed_data'
;
import
'package:flutter_tools/src/test/flutter_web_
platform
.dart'
;
import
'package:flutter_tools/src/test/flutter_web_
goldens
.dart'
;
import
'package:flutter_tools/src/test/test_compiler.dart'
;
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:mockito/mockito.dart'
;
...
...
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