Stabilize controlled scroll screenshot comparisons
This commit is contained in:
1 parent
9bacacc60d
commit
1a0c7096fc
4 files changed
+296
-12
No files matched your search
@@ -71,3 +71,58 @@ fn screenshot_is_captured_after_eval_scrolls_the_live_page() {
|
||||
|
||||
std::fs::remove_dir_all(directory).expect("remove temporary output directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paired_capture_reasserts_scroll_after_the_post_eval_settle() {
|
||||
let directory = output_directory();
|
||||
std::fs::create_dir_all(&directory).expect("temporary output directory");
|
||||
let screenshot = directory.join("reasserted.png");
|
||||
let url = concat!(
|
||||
"data:text/html,<html style=\"margin:0;scroll-behavior:smooth\">",
|
||||
"<body style=\"margin:0\"><div style=\"height:400px\"></div>",
|
||||
"</body></html>"
|
||||
);
|
||||
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_obscura"))
|
||||
.args(["fetch", url, "--screenshot"])
|
||||
.arg(&screenshot)
|
||||
.args([
|
||||
"--eval",
|
||||
"(()=>{scrollTo(0,40);setTimeout(()=>scrollTo(0,10),10);return 'started'})()",
|
||||
"--wait",
|
||||
"1",
|
||||
"--timeout",
|
||||
"5",
|
||||
"--quiet",
|
||||
])
|
||||
.env("OBSCURA_SHOT_W", "100")
|
||||
.env("OBSCURA_SHOT_H", "80")
|
||||
.env("OBSCURA_SHOT_SCROLL_X", "0")
|
||||
.env("OBSCURA_SHOT_SCROLL_Y", "80")
|
||||
.output()
|
||||
.expect("run obscura fetch");
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"capture failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
|
||||
let report: serde_json::Value =
|
||||
serde_json::from_slice(&output.stdout).expect("capture report JSON");
|
||||
assert_eq!(
|
||||
report["controlledScroll"]["preReassertActual"]["y"].as_f64(),
|
||||
Some(10.0),
|
||||
"the diagnostic offset must be sampled after the post-eval settle"
|
||||
);
|
||||
assert_eq!(
|
||||
report["controlledScroll"]["finalReassertActual"]["y"].as_f64(),
|
||||
Some(80.0)
|
||||
);
|
||||
assert_eq!(report["captureState"]["scrollY"].as_f64(), Some(80.0));
|
||||
assert_eq!(
|
||||
report["controlledScroll"]["phase"].as_str(),
|
||||
Some("immediately-before-capture-state-and-screenshot")
|
||||
);
|
||||
|
||||
std::fs::remove_dir_all(directory).expect("remove temporary output directory");
|
||||
}
|
||||
Reference in new issue
Block a user