This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
add option for bulk-updating screenshots; update screenshots #12797
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef08427
add option for bulk-updating screenshots; update screenshots
yjbanov e2da9ae
use bundled Roboto font
yjbanov 39ac372
switch to Roboto-Regular
yjbanov dc5c289
make golden smoke test use the engine
yjbanov 6a99791
use the real SHA
yjbanov 427a000
doUpdateScreenshotGoldens
yjbanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
repository: https://github.com/flutter/goldens.git | ||
revision: dd993a32c23c5c542f083134467e7cda09cac975 | ||
revision: 17a42169bbf6739421fce8a0a1695eb3405375b6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ import 'test_platform.dart'; | |
import 'environment.dart'; | ||
import 'utils.dart'; | ||
|
||
class TestsCommand extends Command<bool> { | ||
TestsCommand() { | ||
class TestCommand extends Command<bool> { | ||
TestCommand() { | ||
argParser | ||
..addMultiOption( | ||
'target', | ||
|
@@ -32,6 +32,13 @@ class TestsCommand extends Command<bool> { | |
help: 'Pauses the browser before running a test, giving you an ' | ||
'opportunity to add breakpoints or inspect loaded code before ' | ||
'running the code.', | ||
) | ||
..addFlag( | ||
'update-screenshot-goldens', | ||
defaultsTo: false, | ||
help: 'When running screenshot tests writes them to the file system into ' | ||
'.dart_tool/goldens. Use this option to bulk-update all screenshots, ' | ||
'for example, when a new browser version affects pixels.', | ||
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
|
||
addChromeVersionOption(argParser); | ||
|
@@ -47,7 +54,7 @@ class TestsCommand extends Command<bool> { | |
Future<bool> run() async { | ||
Chrome.version = chromeVersion; | ||
|
||
_copyAhemFontIntoWebUi(); | ||
_copyTestFontsIntoWebUi(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
await _buildHostPage(); | ||
|
||
final List<FilePath> targets = | ||
|
@@ -73,6 +80,10 @@ class TestsCommand extends Command<bool> { | |
/// See [ChromeInstallerCommand.chromeVersion]. | ||
String get chromeVersion => argResults['chrome-version']; | ||
|
||
/// When running screenshot tests writes them to the file system into | ||
/// ".dart_tool/goldens". | ||
bool get doUpdateScreenshotGoldens => argResults['update-screenshot-goldens']; | ||
|
||
Future<void> _runTargetTests(List<FilePath> targets) async { | ||
await _runTestBatch(targets, concurrency: 1, expectFailure: false); | ||
_checkExitCode(); | ||
|
@@ -234,7 +245,11 @@ class TestsCommand extends Command<bool> { | |
...testFiles.map((f) => f.relativeToWebUi).toList(), | ||
]; | ||
hack.registerPlatformPlugin(<Runtime>[Runtime.chrome], () { | ||
return BrowserPlatform.start(root: io.Directory.current.path); | ||
return BrowserPlatform.start( | ||
root: io.Directory.current.path, | ||
// It doesn't make sense to update a screenshot for a test that is expected to fail. | ||
doUpdateScreenshotGoldens: !expectFailure && doUpdateScreenshotGoldens, | ||
); | ||
}); | ||
|
||
// We want to run tests with `web_ui` as a working directory. | ||
|
@@ -257,15 +272,20 @@ class TestsCommand extends Command<bool> { | |
} | ||
} | ||
|
||
void _copyAhemFontIntoWebUi() { | ||
final io.File sourceAhemTtf = io.File(path.join( | ||
environment.flutterDirectory.path, | ||
'third_party', | ||
'txt', | ||
'third_party', | ||
'fonts', | ||
'ahem.ttf')); | ||
final String destinationAhemTtfPath = | ||
path.join(environment.webUiRootDir.path, 'lib', 'assets', 'ahem.ttf'); | ||
sourceAhemTtf.copySync(destinationAhemTtfPath); | ||
const List<String> _kTestFonts = <String>['ahem.ttf', 'Roboto-Regular.ttf']; | ||
|
||
void _copyTestFontsIntoWebUi() { | ||
final String fontsPath = path.join( | ||
environment.flutterDirectory.path, | ||
'third_party', | ||
'txt', | ||
'third_party', | ||
'fonts', | ||
); | ||
|
||
for (String fontFile in _kTestFonts) { | ||
final io.File sourceTtf = io.File(path.join(fontsPath, fontFile)); | ||
final String destinationTtfPath = path.join(environment.webUiRootDir.path, 'lib', 'assets', fontFile); | ||
sourceTtf.copySync(destinationTtfPath); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
ahem.ttf | ||
*.ttf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,15 @@ import 'dart:html' as html; | |
|
||
import 'package:test/test.dart'; | ||
import 'package:ui/ui.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
import 'package:web_engine_tester/golden_tester.dart'; | ||
|
||
void main() { | ||
void main() async { | ||
debugEmulateFlutterTesterEnvironment = true; | ||
await webOnlyInitializePlatform(assetManager: WebOnlyMockAssetManager()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I guess there's some styles in the platform init that causes the color of the font to become red) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other than the above, LGTM! |
||
|
||
test('screenshot test reports success', () async { | ||
html.document.body.style.fontFamily = 'Roboto'; | ||
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
html.document.body.innerHtml = 'Hello world!'; | ||
await matchGoldenFile('__local__/smoke_test.png', region: Rect.fromLTWH(0, 0, 320, 200)); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.