Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
test(scap-targets): run X11 target regression in Linux CI
Aditya Garud09a22a2dbfe8
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 57810c005..84d9ad4e3 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -282,6 +282,7 @@ jobs:cargo test --locked -p cap --bin cap record::testscargo test --locked -p cap-recording --lib -- --test-threads=1cargo test --locked -p cap-recording --test x11_shm_capture -- --test-threads=1+ cargo test --locked -p scap-targets --lib --test linux_targetscargo test --locked -p cap-enc-ffmpegbuild-gpui:diff --git a/crates/scap-targets/tests/linux_targets.rs b/crates/scap-targets/tests/linux_targets.rsindex 0d099bb28..73327eebf 100644--- a/crates/scap-targets/tests/linux_targets.rs+++ b/crates/scap-targets/tests/linux_targets.rs@@ -1,5 +1,10 @@#![cfg(target_os = "linux")]+use std::{+ io::{BufRead, BufReader},+ process::{Child, Command, Stdio},+};+use scap_targets::{Display, Window, WindowId};use x11rb::{COPY_DEPTH_FROM_PARENT,@@ -10,10 +15,60 @@ use x11rb::{wrapper::ConnectionExt as _,};+struct Xvfb(Child);++impl Xvfb {+ fn start() -> Option<(Self, String)> {+ let (reader, writer) = std::io::pipe().ok()?;+ let child = Command::new("Xvfb")+ .args([+ "-displayfd",+ "1",+ "-screen",+ "0",+ "1280x720x24",+ "-nolisten",+ "tcp",+ ])+ .stdin(Stdio::null())+ .stdout(writer)+ .stderr(Stdio::null())+ .spawn();+ let child = match child {+ Ok(child) => child,+ Err(error) => {+ eprintln!("skipping X11 targets test: cannot start Xvfb: {error}");+ return None;+ }+ };+ let server = Self(child);+ let mut line = String::new();+ BufReader::new(reader)+ .read_line(&mut line)+ .expect("Xvfb display number");+ let number: u32 = line.trim().parse().expect("Xvfb display number");+ Some((server, format!(":{number}")))+ }+}++impl Drop for Xvfb {+ fn drop(&mut self) {+ let _ = self.0.kill();+ let _ = self.0.wait();+ }+}+#[test]-#[ignore = "requires an isolated X11 server, run with xvfb-run"]fn partially_offscreen_window_remains_a_recording_target() {- let (conn, screen_num) = x11rb::connect(None).unwrap();+ let Some((_server, display)) = Xvfb::start() else {+ return;+ };+ // SAFETY: this binary has one test, which sets the variables before calling scap_targets.+ unsafe {+ std::env::set_var("DISPLAY", &display);+ std::env::set_var("XDG_SESSION_TYPE", "x11");+ }+ let (conn, screen_num) = x11rb::connect(Some(&display)).unwrap();let screen = &conn.setup().roots[screen_num];let id = conn.generate_id().unwrap();conn.create_window(