diff options
Diffstat (limited to 'cli/tests/integration/cert_tests.rs')
-rw-r--r-- | cli/tests/integration/cert_tests.rs | 119 |
1 files changed, 54 insertions, 65 deletions
diff --git a/cli/tests/integration/cert_tests.rs b/cli/tests/integration/cert_tests.rs index f53ce9cee..4ccc38809 100644 --- a/cli/tests/integration/cert_tests.rs +++ b/cli/tests/integration/cert_tests.rs @@ -7,10 +7,8 @@ use lsp_types::Url; use std::io::BufReader; use std::io::Cursor; use std::io::Read; -use std::process::Command; use std::sync::Arc; use test_util as util; -use test_util::TempDir; use util::TestContext; itest_flaky!(cafile_url_imports { @@ -125,29 +123,29 @@ fn cafile_compile() { #[flaky_test::flaky_test] fn cafile_install_remote_module() { - let _g = util::http_server(); - let temp_dir = TempDir::new(); + let context = TestContext::with_http_server(); + let temp_dir = context.temp_dir(); let bin_dir = temp_dir.path().join("bin"); - std::fs::create_dir(&bin_dir).unwrap(); - let deno_dir = TempDir::new(); + bin_dir.create_dir_all(); let cafile = util::testdata_path().join("tls/RootCA.pem"); - let install_output = Command::new(util::deno_exe_path()) - .env("DENO_DIR", deno_dir.path()) - .current_dir(util::testdata_path()) - .arg("install") - .arg("--cert") - .arg(cafile) - .arg("--root") - .arg(temp_dir.path()) - .arg("-n") - .arg("echo_test") - .arg("https://localhost:5545/echo.ts") - .output() - .expect("Failed to spawn script"); - println!("{}", std::str::from_utf8(&install_output.stdout).unwrap()); - eprintln!("{}", std::str::from_utf8(&install_output.stderr).unwrap()); - assert!(install_output.status.success()); + let install_output = context + .new_command() + .args_vec([ + "install", + "--cert", + &cafile.to_string_lossy(), + "--root", + &temp_dir.path().to_string_lossy(), + "-n", + "echo_test", + "https://localhost:5545/echo.ts", + ]) + .split_output() + .run(); + println!("{}", install_output.stdout()); + eprintln!("{}", install_output.stderr()); + install_output.assert_exit_code(0); let mut echo_test_path = bin_dir.join("echo_test"); if cfg!(windows) { @@ -155,61 +153,52 @@ fn cafile_install_remote_module() { } assert!(echo_test_path.exists()); - let output = Command::new(echo_test_path) - .current_dir(temp_dir.path()) - .arg("foo") + let output = context + .new_command() + .name(echo_test_path) + .args("foo") .env("PATH", util::target_dir()) - .output() - .expect("failed to spawn script"); - let stdout = std::str::from_utf8(&output.stdout).unwrap().trim(); - assert!(stdout.ends_with("foo")); + .run(); + output.assert_matches_text("[WILDCARD]foo"); } #[flaky_test::flaky_test] fn cafile_bundle_remote_exports() { - let _g = util::http_server(); + let context = TestContext::with_http_server(); // First we have to generate a bundle of some remote module that has exports. let mod1 = "https://localhost:5545/subdir/mod1.ts"; let cafile = util::testdata_path().join("tls/RootCA.pem"); - let t = TempDir::new(); + let t = context.temp_dir(); let bundle = t.path().join("mod1.bundle.js"); - let mut deno = util::deno_cmd() - .current_dir(util::testdata_path()) - .arg("bundle") - .arg("--cert") - .arg(cafile) - .arg(mod1) - .arg(&bundle) - .spawn() - .expect("failed to spawn script"); - let status = deno.wait().expect("failed to wait for the child process"); - assert!(status.success()); + context + .new_command() + .args_vec([ + "bundle", + "--cert", + &cafile.to_string_lossy(), + mod1, + &bundle.to_string_lossy(), + ]) + .run() + .skip_output_check() + .assert_exit_code(0); + assert!(bundle.is_file()); // Now we try to use that bundle from another module. let test = t.path().join("test.js"); - std::fs::write( - &test, - " - import { printHello3 } from \"./mod1.bundle.js\"; - printHello3(); ", - ) - .expect("error writing file"); - - let output = util::deno_cmd() - .current_dir(util::testdata_path()) - .arg("run") - .arg("--check") - .arg(&test) - .output() - .expect("failed to spawn script"); - // check the output of the test.ts program. - assert!(std::str::from_utf8(&output.stdout) - .unwrap() - .trim() - .ends_with("Hello")); - assert_eq!(output.stderr, b""); + test.write( + "import { printHello3 } from \"./mod1.bundle.js\"; +printHello3();", + ); + + context + .new_command() + .args_vec(["run", "--quiet", "--check", &test.to_string_lossy()]) + .run() + .assert_matches_text("[WILDCARD]Hello\n") + .assert_exit_code(0); } #[tokio::test] @@ -223,7 +212,7 @@ async fn listen_tls_alpn() { .arg("--allow-read") .arg("./cert/listen_tls_alpn.ts") .arg("4504") - .stdout(std::process::Stdio::piped()) + .stdout_piped() .spawn() .unwrap(); let stdout = child.stdout.as_mut().unwrap(); @@ -272,7 +261,7 @@ async fn listen_tls_alpn_fail() { .arg("--allow-read") .arg("./cert/listen_tls_alpn_fail.ts") .arg("4505") - .stdout(std::process::Stdio::piped()) + .stdout_piped() .spawn() .unwrap(); let stdout = child.stdout.as_mut().unwrap(); |