From e84704968e92638fae02c6ec2d629158dab3f25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 26 Nov 2020 20:12:26 +0100 Subject: [PATCH] fix(watch): fix flaky tests for watcher (#8508) --- cli/tests/integration_tests.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 8a6d1201f7..afe030a034 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -474,6 +474,19 @@ fn fmt_test() { assert_eq!(expected, actual); } +// Helper function to skip watcher output that contains "Restarting" +// phrase. +fn skip_restarting_line( + mut stderr_lines: impl Iterator, +) -> String { + loop { + let msg = stderr_lines.next().unwrap(); + if !msg.contains("Restarting") { + return msg; + } + } +} + #[test] fn fmt_watch_test() { let t = TempDir::new().expect("tempdir fail"); @@ -495,13 +508,13 @@ fn fmt_watch_test() { .spawn() .expect("Failed to spawn script"); let stderr = child.stderr.as_mut().unwrap(); - let mut stderr_lines = + let stderr_lines = std::io::BufReader::new(stderr).lines().map(|r| r.unwrap()); // TODO(lucacasonato): remove this timeout. It seems to be needed on Linux. std::thread::sleep(std::time::Duration::from_secs(1)); - assert!(stderr_lines.next().unwrap().contains("badly_formatted.js")); + assert!(skip_restarting_line(stderr_lines).contains("badly_formatted.js")); let expected = std::fs::read_to_string(fixed.clone()).unwrap(); let actual = std::fs::read_to_string(badly_formatted.clone()).unwrap();