2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-01-14 23:18:58 -05:00
|
|
|
use std::process::Command;
|
|
|
|
use std::process::Stdio;
|
2023-11-23 11:20:40 -05:00
|
|
|
use std::time::Instant;
|
2023-01-12 20:59:13 -05:00
|
|
|
use test_util as util;
|
2024-08-30 20:22:20 -04:00
|
|
|
use test_util::assert_starts_with;
|
2024-07-23 19:00:48 -04:00
|
|
|
use test_util::TestContext;
|
2023-11-23 11:20:40 -05:00
|
|
|
use util::TestContextBuilder;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2024-07-29 16:18:25 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2024-07-23 19:00:48 -04:00
|
|
|
fn upgrade_invalid_lockfile() {
|
|
|
|
let context = upgrade_context();
|
|
|
|
let temp_dir = context.temp_dir();
|
|
|
|
temp_dir.write("deno.deno", r#"{ \"lock\": true }"#);
|
|
|
|
temp_dir.write(
|
|
|
|
"deno.lock",
|
|
|
|
r#"{
|
|
|
|
"version": "invalid",
|
|
|
|
}"#,
|
|
|
|
);
|
|
|
|
let exe_path = temp_dir.path().join("deno");
|
|
|
|
util::deno_exe_path().copy(&exe_path);
|
|
|
|
assert!(exe_path.exists());
|
|
|
|
exe_path.mark_executable();
|
|
|
|
let output = Command::new(&exe_path)
|
|
|
|
.arg("upgrade")
|
|
|
|
.arg("--version")
|
|
|
|
.arg("foobar")
|
2024-07-29 16:18:25 -04:00
|
|
|
.arg("--dry-run")
|
2024-07-23 19:00:48 -04:00
|
|
|
.stderr(Stdio::piped())
|
|
|
|
.spawn()
|
|
|
|
.unwrap()
|
|
|
|
.wait_with_output()
|
|
|
|
.unwrap();
|
|
|
|
assert!(!output.status.success());
|
|
|
|
// should make it here instead of erroring on an invalid lockfile
|
2024-08-30 20:22:20 -04:00
|
|
|
assert_starts_with!(
|
|
|
|
&util::strip_ansi_codes(&String::from_utf8(output.stderr.clone()).unwrap())
|
|
|
|
.to_string(),
|
|
|
|
"error: Invalid version passed (foobar)"
|
2024-07-23 19:00:48 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-12 17:04:00 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2023-11-23 11:20:40 -05:00
|
|
|
fn upgrade_prompt() {
|
2024-07-23 19:00:48 -04:00
|
|
|
let context = upgrade_context();
|
2023-11-23 11:20:40 -05:00
|
|
|
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.
|
2023-11-23 12:54:27 -05:00
|
|
|
pty.expect_any(&[
|
|
|
|
" 99999.99.99 Run `deno upgrade` to install it.",
|
|
|
|
// it builds canary releases on main, so check for this in that case
|
2024-08-30 20:22:20 -04:00
|
|
|
"Run `deno upgrade canary` to install it.",
|
2023-11-23 12:54:27 -05:00
|
|
|
]);
|
2023-11-23 11:20:40 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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");
|
|
|
|
});
|
|
|
|
|
2023-11-27 18:12:17 -05:00
|
|
|
// the test server will sleep for 95 seconds, so ensure this is less
|
2023-11-23 11:20:40 -05:00
|
|
|
let elapsed_secs = start_instant.elapsed().as_secs();
|
2023-11-27 18:12:17 -05:00
|
|
|
assert!(elapsed_secs < 94, "elapsed_secs: {}", elapsed_secs);
|
2023-11-23 11:20:40 -05:00
|
|
|
}
|
2024-07-23 19:00:48 -04:00
|
|
|
|
|
|
|
fn upgrade_context() -> TestContext {
|
|
|
|
TestContextBuilder::new()
|
|
|
|
.use_http_server()
|
|
|
|
.use_temp_cwd()
|
|
|
|
.env(
|
|
|
|
"DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL",
|
|
|
|
"http://localhost:4545",
|
|
|
|
)
|
|
|
|
.build()
|
|
|
|
}
|