Skip to content

Commit ac22a83

Browse files
committed
Reduce flaky screenshots. (dart-lang#8603)
1 parent fa355bd commit ac22a83

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

pkg/pub_integration/lib/src/screenshot_utils.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ extension ScreenshotElementHandleExt on ElementHandle {
6868
final body = await page.$('body');
6969
final bodyClassAttr =
7070
(await body.evaluate('el => el.getAttribute("class")')) as String;
71-
final bodyClasses = bodyClassAttr.split(' ');
71+
final bodyClasses = [
72+
...bodyClassAttr.split(' '),
73+
'-pub-ongoing-screenshot',
74+
];
7275

7376
for (final vp in _viewports.entries) {
7477
await page.setViewport(vp.value);
@@ -84,10 +87,17 @@ extension ScreenshotElementHandleExt on ElementHandle {
8487
// The presence of the element is verified, continue only if screenshots are enabled.
8588
if (!_isScreenshotDirSet) continue;
8689

90+
// Arbitrary delay in the hope that potential ongoing updates complete.
91+
await Future.delayed(Duration(milliseconds: 500));
92+
8793
final path = p.join(_screenshotDir!, '$prefix-${vp.key}-$theme.png');
8894
await _writeScreenshotToFile(path);
8995
}
9096
}
97+
98+
// restore the original body class attributes
99+
await body.evaluate('(el, v) => el.setAttribute("class", v)',
100+
args: [bodyClassAttr]);
91101
}
92102

93103
Future<void> _writeScreenshotToFile(String path) async {

pkg/web_css/lib/src/_base.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,13 @@ a.-x-ago {
480480
margin-left: 36px;
481481
}
482482
}
483+
484+
.-pub-ongoing-screenshot {
485+
// Disables flashing caret (cursor) in input fields by making it invisible.
486+
caret-color: transparent;
487+
488+
// Instantaneous transitions - no ambiguous delay in the end state.
489+
* {
490+
transition-duration: 0s !important;
491+
}
492+
}

pkg/web_css/test/expression_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ void main() {
5757
'cookie-notice-container',
5858
'cookie-notice-button',
5959
]);
60+
// test-only style
61+
expressions.remove('-pub-ongoing-screenshot');
6062
// markdown alert classes
6163
expressions.removeAll([
6264
'markdown-alert-note',

0 commit comments

Comments
 (0)