Skip to content

Commit 84b3e76

Browse files
committed
Reduce flaky css screenshots.
1 parent 6bc0917 commit 84b3e76

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-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
@@ -493,3 +493,13 @@ a.-x-ago {
493493
margin-left: 36px;
494494
}
495495
}
496+
497+
.-pub-ongoing-screenshot {
498+
// Disables flashing caret (cursor) in input fields by making it invisible.
499+
caret-color: transparent;
500+
501+
// Instantaneous transitions - no ambiguous delay in the end state.
502+
* {
503+
transition-duration: 0s !important;
504+
}
505+
}

0 commit comments

Comments
 (0)