From fa9f8df396f49ccd74b25abd25c38348871bc01e Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 1 Nov 2023 08:15:06 -0500 Subject: [PATCH] Fix test snapshot filter when runtime is greater than 1s (#267) Tests would sometimes flake with this locally e.g. "1.50s" was not filtered correctly. Verified with ```diff diff --git a/crates/puffin-cli/src/commands/pip_compile.rs b/crates/puffin-cli/src/commands/pip_compile.rs index 0193216..2d6f8af 100644 --- a/crates/puffin-cli/src/commands/pip_compile.rs +++ b/crates/puffin-cli/src/commands/pip_compile.rs @@ -150,6 +150,8 @@ pub(crate) async fn pip_compile( result => result, }?; + std::thread::sleep(std::time::Duration::from_secs(1)); + let s = if resolution.len() == 1 { "" } else { "s" }; writeln!( printer, ``` --- crates/puffin-cli/tests/pip_compile.rs | 16 ++++++++-------- crates/puffin-cli/tests/pip_sync.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/puffin-cli/tests/pip_compile.rs b/crates/puffin-cli/tests/pip_compile.rs index 7407f4675..8db46c249 100644 --- a/crates/puffin-cli/tests/pip_compile.rs +++ b/crates/puffin-cli/tests/pip_compile.rs @@ -70,7 +70,7 @@ fn compile_requirements_in() -> Result<()> { insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] @@ -120,7 +120,7 @@ dependencies = [ insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] @@ -164,7 +164,7 @@ fn compile_constraints_txt() -> Result<()> { insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] @@ -211,7 +211,7 @@ fn compile_constraints_inline() -> Result<()> { insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] @@ -262,7 +262,7 @@ optional-dependencies.foo = [ insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] @@ -315,7 +315,7 @@ optional-dependencies."FrIeNdLy-._.-bArD" = [ insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] @@ -368,7 +368,7 @@ optional-dependencies.foo = [ insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] @@ -421,7 +421,7 @@ optional-dependencies.foo = [ insta::with_settings!({ filters => vec![ - (r"\d+(ms|s)", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), (r"# .* pip-compile", "# [BIN_PATH] pip-compile"), (r"--cache-dir .*", "--cache-dir [CACHE_DIR]"), ] diff --git a/crates/puffin-cli/tests/pip_sync.rs b/crates/puffin-cli/tests/pip_sync.rs index d91ae7e32..4475e6b51 100644 --- a/crates/puffin-cli/tests/pip_sync.rs +++ b/crates/puffin-cli/tests/pip_sync.rs @@ -71,7 +71,7 @@ fn install() -> Result<()> { insta::with_settings!({ filters => vec![ - (r"\d+ms", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), ] }, { assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) @@ -116,7 +116,7 @@ fn install_copy() -> Result<()> { insta::with_settings!({ filters => vec![ - (r"\d+ms", "[TIME]"), + (r"(\d|\.)+(ms|s)", "[TIME]"), ] }, { assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))