Skip to content

Commit

Permalink
chore: combine TestCommandBuilder with DenoCmd (denoland#21248)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Nov 18, 2023
1 parent 4a2d8c4 commit c213ad3
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 364 deletions.
5 changes: 3 additions & 2 deletions cli/tests/integration/cert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::io::Cursor;
use std::io::Read;
use std::sync::Arc;
use test_util as util;
use util::testdata_path;
use util::TestContext;

itest_flaky!(cafile_url_imports {
Expand Down Expand Up @@ -75,7 +76,7 @@ fn cafile_env_fetch() {
let module_url =
Url::parse("https://localhost:5545/cert/cafile_url_imports.ts").unwrap();
let context = TestContext::with_http_server();
let cafile = context.testdata_path().join("tls/RootCA.pem");
let cafile = testdata_path().join("tls/RootCA.pem");

context
.new_command()
Expand All @@ -91,7 +92,7 @@ fn cafile_fetch() {
let module_url =
Url::parse("http:https://localhost:4545/cert/cafile_url_imports.ts").unwrap();
let context = TestContext::with_http_server();
let cafile = context.testdata_path().join("tls/RootCA.pem");
let cafile = testdata_path().join("tls/RootCA.pem");
context
.new_command()
.args(format!("cache --quiet --cert {} {}", cafile, module_url,))
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/integration/compile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use test_util as util;
use util::assert_contains;
use util::assert_not_contains;
use util::testdata_path;
use util::TestContext;
use util::TestContextBuilder;

Expand Down Expand Up @@ -705,7 +706,7 @@ fn dynamic_import_unanalyzable() {

context
.new_command()
.cwd(util::root_path().join("cli"))
.current_dir(util::root_path().join("cli"))
.name(&exe)
.env("NO_COLOR", "")
.run()
Expand Down Expand Up @@ -935,11 +936,10 @@ fn run_npm_bin_compile_test(opts: RunNpmBinCompileOptions) {
let context = TestContextBuilder::for_npm().use_temp_cwd().build();

let temp_dir = context.temp_dir();
let testdata_path = context.testdata_path();
let main_specifier = if opts.input_specifier.starts_with("npm:") {
opts.input_specifier.to_string()
} else {
testdata_path.join(opts.input_specifier).to_string()
testdata_path().join(opts.input_specifier).to_string()
};

let mut args = vec!["compile".to_string()];
Expand Down
10 changes: 5 additions & 5 deletions cli/tests/integration/fmt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn fmt_test() {

let output = context
.new_command()
.cwd(&testdata_fmt_dir)
.current_dir(&testdata_fmt_dir)
.args_vec(vec![
"fmt".to_string(),
format!(
Expand All @@ -50,7 +50,7 @@ fn fmt_test() {
// Check without ignore.
let output = context
.new_command()
.cwd(&testdata_fmt_dir)
.current_dir(&testdata_fmt_dir)
.args_vec(vec![
"fmt".to_string(),
"--check".to_string(),
Expand All @@ -66,7 +66,7 @@ fn fmt_test() {
// Format the source file.
let output = context
.new_command()
.cwd(&testdata_fmt_dir)
.current_dir(&testdata_fmt_dir)
.args_vec(vec![
"fmt".to_string(),
badly_formatted_js.to_string(),
Expand Down Expand Up @@ -95,7 +95,7 @@ fn fmt_stdin_syntax_error() {
.current_dir(util::testdata_path())
.arg("fmt")
.arg("-")
.set_stdin_text("import { example }")
.stdin_text("import { example }")
.split_output()
.run();
assert!(output.stdout().is_empty());
Expand Down Expand Up @@ -141,7 +141,7 @@ fn fmt_auto_ignore_git_and_node_modules() {

let output = context
.new_command()
.cwd(t)
.current_dir(t)
.env("NO_COLOR", "1")
.args("fmt")
.run();
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/integration/info_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ fn info_with_compiled_source() {

let output = context
.new_command()
.cwd(util::testdata_path())
.current_dir(util::testdata_path())
.args_vec(["cache", module_path])
.run();
output.assert_exit_code(0);
output.skip_output_check();

let output = context
.new_command()
.cwd(util::testdata_path())
.current_dir(util::testdata_path())
.args_vec(["info", module_path])
.split_output()
.run();
Expand Down
8 changes: 4 additions & 4 deletions cli/tests/integration/install_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn install_custom_dir_env_var() {

context
.new_command()
.cwd(util::root_path()) // different cwd
.current_dir(util::root_path()) // different cwd
.args("install --check --name echo_test http:https://localhost:4545/echo.ts")
.envs([
("HOME", temp_dir_str.as_str()),
Expand Down Expand Up @@ -124,7 +124,7 @@ fn installer_test_local_module_run() {

context
.new_command()
.cwd(util::root_path())
.current_dir(util::root_path())
.args_vec([
"install",
"--name",
Expand Down Expand Up @@ -152,7 +152,7 @@ fn installer_test_local_module_run() {
let output = context
.new_command()
.name(&file_path)
.cwd(temp_dir.path())
.current_dir(temp_dir.path())
.args("foo")
.env("PATH", util::target_dir())
.run();
Expand Down Expand Up @@ -183,7 +183,7 @@ fn installer_test_remote_module_run() {
let output = context
.new_command()
.name(&bin_file_path)
.cwd(root_dir)
.current_dir(root_dir)
.args("foo")
.env("PATH", util::target_dir())
.run();
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/integration/npm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ fn top_level_install_package_json_explicit_opt_in() {
let output = test_context
.new_command()
.args("run -")
.stdin("console.log(5)")
.stdin_text("console.log(5)")
.run();
output.assert_matches_text(concat!(
"Initialize @denotest/[email protected]\n",
Expand Down
12 changes: 7 additions & 5 deletions cli/tests/integration/repl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ fn repl_with_quiet_flag() {
#[test]
fn repl_unit_tests() {
util::with_pty(&["repl"], |mut console| {
console.write_line(
console.write_line_raw(
"\
console.log('Hello from outside of test!'); \
Deno.test('test1', async (t) => { \
Expand All @@ -912,11 +912,11 @@ fn repl_unit_tests() {
console.expect(" step1 ... ok (");
console.expect("test1 ... ok (");
console.expect("test2 ... FAILED (");
console.expect(" ERRORS ");
console.expect("ERRORS");
console.expect("test2 => <anonymous>:6:6");
console.expect("error: Error: some message");
console.expect(" at <anonymous>:7:9");
console.expect(" FAILURES ");
console.expect("FAILURES");
console.expect("test2 => <anonymous>:6:6");
console.expect("FAILED | 1 passed (1 step) | 1 failed (");
console.expect("undefined");
Expand Down Expand Up @@ -1058,11 +1058,13 @@ fn package_json_uncached_no_error() {
// should support getting the package now though
console
.write_line("import { getValue, setValue } from '@denotest/esm-basic';");
console.expect_all(&["undefined", "Initialize"]);
console.expect_all(&["undefined", "Download"]);
console.write_line("setValue(12 + 30);");
console.expect("undefined");
console.write_line("getValue()");
console.expect("42")
console.expect("42");

assert!(temp_dir.path().join("node_modules").exists());
});
}

Expand Down
11 changes: 2 additions & 9 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,7 @@ fn lock_no_declaration_files() {
.run();
output.assert_matches_file("lockfile/no_dts/main.cache.out");
let lockfile = context.temp_dir().path().join("deno.lock");
lockfile.assert_matches_file(
context
.testdata_path()
.join("lockfile/no_dts/deno.lock.out"),
);
lockfile.assert_matches_file("lockfile/no_dts/deno.lock.out");
}

#[test]
Expand Down Expand Up @@ -2093,10 +2089,7 @@ console.log("executing javascript");
"#;

let mut p = util::deno_cmd()
.arg("run")
.args(["--ext", "js"])
.arg("--check")
.arg("-")
.args("run --ext js --check -")
.stdin(std::process::Stdio::piped())
.stdout_piped()
.spawn()
Expand Down
11 changes: 10 additions & 1 deletion cli/tools/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,16 @@ fn get_url(
UpgradeCheckKind::Execution => "",
UpgradeCheckKind::Lsp => "?lsp",
};
format!("https://dl.deno.land/{}{}", file_name, query_param)
format!("{}/{}{}", base_upgrade_url(), file_name, query_param)
}

fn base_upgrade_url() -> Cow<'static, str> {
// this is used to get the current version
if let Ok(url) = env::var("DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL") {
Cow::Owned(url)
} else {
Cow::Borrowed("https://dl.deno.land")
}
}

async fn download_package(
Expand Down
Loading

0 comments on commit c213ad3

Please sign in to comment.