diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/upgrade_tests.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/cli/tests/integration/upgrade_tests.rs b/cli/tests/integration/upgrade_tests.rs index 6eed9e7a1..9b0ad30bd 100644 --- a/cli/tests/integration/upgrade_tests.rs +++ b/cli/tests/integration/upgrade_tests.rs @@ -2,8 +2,10 @@ use std::process::Command; use std::process::Stdio; +use std::time::Instant; use test_util as util; use test_util::TempDir; +use util::TestContextBuilder; // Warning: this test requires internet access. // TODO(#7412): reenable. test is flaky @@ -192,3 +194,62 @@ fn upgrade_invalid_canary_version() { util::strip_ansi_codes(&String::from_utf8(output.stderr).unwrap()) ); } + +#[test] +fn upgrade_prompt() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .env( + "DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL", + "http://localhost:4545", + ) + .build(); + let temp_dir = context.temp_dir(); + // start a task that goes indefinitely in order to allow + // the upgrade check to occur + temp_dir.write("main.js", "setInterval(() => {}, 1_000)"); + let cmd = context + .new_command() + .args("run --log-level=debug main.js") + .env_remove("DENO_NO_UPDATE_CHECK"); + // run once and wait for the version to be stored + cmd.with_pty(|mut pty| { + pty.expect("Finished upgrade checker."); + }); + // now check that the upgrade prompt is shown the next time this is run + temp_dir.write("main.js", ""); + cmd.with_pty(|mut pty| { + // - We need to use a pty here because the upgrade prompt + // doesn't occur except when there's a pty. + // - Version comes from the test server. + pty.expect(" 99999.99.99 Run `deno upgrade` to install it."); + }); +} + +#[test] +fn upgrade_lsp_repl_sleeps() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .env( + "DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL", + "http://localhost:4545/upgrade/sleep", + ) + .build(); + let start_instant = Instant::now(); + // ensure this works even though the upgrade check is taking + // a long time to complete + context + .new_command() + .args("repl") + .env_remove("DENO_NO_UPDATE_CHECK") + .with_pty(|mut pty| { + pty.write_line("123 + 456\n"); + pty.expect("579"); + }); + + // the test server will sleep for 45 seconds, so ensure this is less + let elapsed_secs = start_instant.elapsed().as_secs(); + assert!(elapsed_secs < 30, "elapsed_secs: {}", elapsed_secs); +} |