diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 083cb4aa83..03eb73d56c 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -4,10 +4,8 @@ name = "deno" version = "1.40.4" authors.workspace = true -autotests = false default-run = "deno" edition.workspace = true -exclude = ["tests/testdata/npm/registry/*"] license.workspace = true repository.workspace = true description = "Provides the deno executable" @@ -19,7 +17,7 @@ doc = false [[test]] name = "integration" -path = "../tests/integration_tests_runner.rs" +path = "integration_tests_runner.rs" harness = false [[bench]] diff --git a/tests/integration_tests_runner.rs b/cli/integration_tests_runner.rs similarity index 100% rename from tests/integration_tests_runner.rs rename to cli/integration_tests_runner.rs diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 5eef6cf9a0..b750cb99a6 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -29,6 +29,7 @@ pub mod factory; mod fs; mod https; pub mod lsp; +mod macros; mod npm; pub mod pty; pub mod servers; diff --git a/test_util/src/macros.rs b/test_util/src/macros.rs new file mode 100644 index 0000000000..7cfedcc7ea --- /dev/null +++ b/test_util/src/macros.rs @@ -0,0 +1,86 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +#[macro_export] +macro_rules! itest( +($name:ident {$( $key:ident: $value:expr,)*}) => { + #[test] + fn $name() { + let test = $crate::CheckOutputIntegrationTest { + $( + $key: $value, + )* + .. Default::default() + }; + let output = test.output(); + output.assert_exit_code(test.exit_code); + if !test.output.is_empty() { + assert!(test.output_str.is_none()); + output.assert_matches_file(test.output); + } else { + output.assert_matches_text(test.output_str.unwrap_or("")); + } + } +} +); + +#[macro_export] +macro_rules! itest_flaky( +($name:ident {$( $key:ident: $value:expr,)*}) => { + #[flaky_test::flaky_test] + fn $name() { + let test = $crate::CheckOutputIntegrationTest { + $( + $key: $value, + )* + .. Default::default() + }; + let output = test.output(); + output.assert_exit_code(test.exit_code); + if !test.output.is_empty() { + assert!(test.output_str.is_none()); + output.assert_matches_file(test.output); + } else { + output.assert_matches_text(test.output_str.unwrap_or("")); + } + } +} +); + +#[macro_export] +macro_rules! context( +({$( $key:ident: $value:expr,)*}) => { + $crate::TestContext::create($crate::TestContextOptions { + $( + $key: $value, + )* + .. Default::default() + }) +} +); + +#[macro_export] +macro_rules! itest_steps( +($name:ident {$( $key:ident: $value:expr,)*}) => { + #[test] + fn $name() { + ($crate::CheckOutputIntegrationTestSteps { + $( + $key: $value, + )* + .. Default::default() + }).run() + } +} +); + +#[macro_export] +macro_rules! command_step( +({$( $key:ident: $value:expr,)*}) => { + $crate::CheckOutputIntegrationTestCommandStep { + $( + $key: $value, + )* + .. Default::default() + } +} +); diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 578aaf47b1..ffef6eb2d8 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -17,7 +17,12 @@ run = [] [[test]] name = "integration_tests" -path = "integration_tests.rs" +path = "integration/mod.rs" +required-features = ["run"] + +[[test]] +name = "node_compat_tests" +path = "node_compat/test_runner.rs" required-features = ["run"] [dev-dependencies] diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000000..58aceaa87e --- /dev/null +++ b/tests/README.md @@ -0,0 +1 @@ +# Deno Integration Tests diff --git a/tests/integration/bench_tests.rs b/tests/integration/bench_tests.rs index f92006eb93..8621679dc2 100644 --- a/tests/integration/bench_tests.rs +++ b/tests/integration/bench_tests.rs @@ -2,6 +2,8 @@ use deno_core::url::Url; use test_util as util; +use test_util::itest; +use test_util::itest_flaky; use util::assert_contains; use util::assert_not_contains; use util::env_vars_for_npm_tests; diff --git a/tests/integration/bundle_tests.rs b/tests/integration/bundle_tests.rs index 08e3fb06a2..836a692b68 100644 --- a/tests/integration/bundle_tests.rs +++ b/tests/integration/bundle_tests.rs @@ -3,6 +3,7 @@ use test_util as util; use test_util::assert_contains; use test_util::assert_ends_with; +use test_util::itest; use test_util::TempDir; #[test] diff --git a/tests/integration/cache_tests.rs b/tests/integration/cache_tests.rs index 2aa0f9d8b4..d5b4e88441 100644 --- a/tests/integration/cache_tests.rs +++ b/tests/integration/cache_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util::env_vars_for_npm_tests; +use test_util::itest; use test_util::TestContext; use test_util::TestContextBuilder; diff --git a/tests/integration/cert_tests.rs b/tests/integration/cert_tests.rs index 9e89a9f3ed..abdf9fe46a 100644 --- a/tests/integration/cert_tests.rs +++ b/tests/integration/cert_tests.rs @@ -8,6 +8,8 @@ use std::io::Cursor; use std::io::Read; use std::sync::Arc; use test_util as util; +use test_util::itest; +use test_util::itest_flaky; use url::Url; use util::testdata_path; use util::TestContext; diff --git a/tests/integration/check_tests.rs b/tests/integration/check_tests.rs index f836957ce9..d4d996b005 100644 --- a/tests/integration/check_tests.rs +++ b/tests/integration/check_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util as util; +use test_util::itest; use util::env_vars_for_npm_tests; use util::TestContext; use util::TestContextBuilder; diff --git a/tests/integration/coverage_tests.rs b/tests/integration/coverage_tests.rs index 804f9b578c..5353996a0d 100644 --- a/tests/integration/coverage_tests.rs +++ b/tests/integration/coverage_tests.rs @@ -3,6 +3,7 @@ use deno_core::serde_json; use std::fs; use test_util as util; +use test_util::itest; use test_util::TempDir; use util::assert_starts_with; use util::env_vars_for_npm_tests; diff --git a/tests/integration/doc_tests.rs b/tests/integration/doc_tests.rs index 62fd2a5b44..ca523f07f2 100644 --- a/tests/integration/doc_tests.rs +++ b/tests/integration/doc_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util as util; +use test_util::itest; use util::assert_contains; use util::TestContext; diff --git a/tests/integration/eval_tests.rs b/tests/integration/eval_tests.rs index 1ae65e49eb..3f4c6a3a6d 100644 --- a/tests/integration/eval_tests.rs +++ b/tests/integration/eval_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util as util; +use test_util::itest; #[test] fn eval_p() { diff --git a/tests/integration/flags_tests.rs b/tests/integration/flags_tests.rs index a22cb05481..c898c199cc 100644 --- a/tests/integration/flags_tests.rs +++ b/tests/integration/flags_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util as util; +use test_util::itest; use util::assert_contains; #[test] diff --git a/tests/integration/fmt_tests.rs b/tests/integration/fmt_tests.rs index 94eca295ee..6588ae10ab 100644 --- a/tests/integration/fmt_tests.rs +++ b/tests/integration/fmt_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util as util; +use test_util::itest; use util::assert_contains; use util::PathRef; use util::TestContext; diff --git a/tests/integration/info_tests.rs b/tests/integration/info_tests.rs index 922fcee064..c3de0e4709 100644 --- a/tests/integration/info_tests.rs +++ b/tests/integration/info_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util as util; +use test_util::itest; use util::env_vars_for_npm_tests; use util::TestContextBuilder; diff --git a/tests/integration/js_unit_tests.rs b/tests/integration/js_unit_tests.rs index de7108d255..d96af78d8c 100644 --- a/tests/integration/js_unit_tests.rs +++ b/tests/integration/js_unit_tests.rs @@ -1,4 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + use std::io::BufRead; use std::io::BufReader; use std::time::Duration; diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index 2de4f0056c..51cfcfaaca 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -3,6 +3,7 @@ use deno_core::serde_json::Value; use deno_lockfile::Lockfile; use test_util as util; +use test_util::itest; use url::Url; use util::env_vars_for_jsr_tests; use util::TestContextBuilder; diff --git a/tests/integration/jupyter_tests.rs b/tests/integration/jupyter_tests.rs index 59c247e5dc..5478612585 100644 --- a/tests/integration/jupyter_tests.rs +++ b/tests/integration/jupyter_tests.rs @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use test_util::itest; + itest!(jupyter_install_command_not_exists { args: "jupyter --install", output: "jupyter/install_command_not_exists.out", diff --git a/tests/integration/lint_tests.rs b/tests/integration/lint_tests.rs index b266fb5b74..f7c9ead36e 100644 --- a/tests/integration/lint_tests.rs +++ b/tests/integration/lint_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util::assert_contains; +use test_util::itest; use test_util::TestContextBuilder; itest!(ignore_unexplicit_files { diff --git a/tests/integration/mod.rs b/tests/integration/mod.rs index 19796f245f..89a66385e8 100644 --- a/tests/integration/mod.rs +++ b/tests/integration/mod.rs @@ -1,90 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -#[macro_export] -macro_rules! itest( -($name:ident {$( $key:ident: $value:expr,)*}) => { - #[test] - fn $name() { - let test = test_util::CheckOutputIntegrationTest { - $( - $key: $value, - )* - .. Default::default() - }; - let output = test.output(); - output.assert_exit_code(test.exit_code); - if !test.output.is_empty() { - assert!(test.output_str.is_none()); - output.assert_matches_file(test.output); - } else { - output.assert_matches_text(test.output_str.unwrap_or("")); - } - } -} -); - -#[macro_export] -macro_rules! itest_flaky( -($name:ident {$( $key:ident: $value:expr,)*}) => { - #[flaky_test::flaky_test] - fn $name() { - let test = test_util::CheckOutputIntegrationTest { - $( - $key: $value, - )* - .. Default::default() - }; - let output = test.output(); - output.assert_exit_code(test.exit_code); - if !test.output.is_empty() { - assert!(test.output_str.is_none()); - output.assert_matches_file(test.output); - } else { - output.assert_matches_text(test.output_str.unwrap_or("")); - } - } -} -); - -#[macro_export] -macro_rules! context( -({$( $key:ident: $value:expr,)*}) => { - test_util::TestContext::create(test_util::TestContextOptions { - $( - $key: $value, - )* - .. Default::default() - }) -} -); - -#[macro_export] -macro_rules! itest_steps( -($name:ident {$( $key:ident: $value:expr,)*}) => { - #[test] - fn $name() { - (test_util::CheckOutputIntegrationTestSteps { - $( - $key: $value, - )* - .. Default::default() - }).run() - } -} -); - -#[macro_export] -macro_rules! command_step( -({$( $key:ident: $value:expr,)*}) => { - test_util::CheckOutputIntegrationTestCommandStep { - $( - $key: $value, - )* - .. Default::default() - } -} -); - // These files have `_tests.rs` suffix to make it easier to tell which file is // the test (ex. `lint_tests.rs`) and which is the implementation (ex. `lint.rs`) // when both are open, especially for two tabs in VS Code diff --git a/tests/integration/node_compat_tests.rs b/tests/integration/node_compat_tests.rs index e2b3c219cf..767f23460b 100644 --- a/tests/integration/node_compat_tests.rs +++ b/tests/integration/node_compat_tests.rs @@ -1,28 +1,9 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use test_util as util; -use util::deno_config_path; +use test_util::itest; use util::env_vars_for_npm_tests; -#[test] -fn node_compat_tests() { - let mut deno = util::deno_cmd() - .current_dir(util::root_path()) - .arg("test") - .arg("--config") - .arg(deno_config_path()) - .arg("--no-lock") - .arg("--unstable") - .arg("-A") - .arg(util::tests_path().join("node_compat")) - .spawn() - .expect("failed to spawn script"); - - let status = deno.wait().expect("failed to wait for the child process"); - assert_eq!(Some(0), status.code()); - assert!(status.success()); -} - itest!(node_test_module { args: "test node/test.js", output: "node/test.out", diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index 7c5976bf60..3c824b6b23 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -1,9 +1,11 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + use std::io::BufRead; use std::io::BufReader; use std::time::Duration; use std::time::Instant; use test_util as util; +use test_util::itest; use util::deno_config_path; use util::env_vars_for_npm_tests; diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index a63253260a..3777bfe8a4 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -5,6 +5,7 @@ use deno_core::serde_json::json; use deno_core::serde_json::Value; use pretty_assertions::assert_eq; use test_util as util; +use test_util::itest; use util::assert_contains; use util::env_vars_for_npm_tests; use util::http_server; diff --git a/tests/integration/publish_tests.rs b/tests/integration/publish_tests.rs index 330a7692bf..2dbd854a72 100644 --- a/tests/integration/publish_tests.rs +++ b/tests/integration/publish_tests.rs @@ -5,6 +5,7 @@ use test_util::assert_contains; use test_util::assert_not_contains; use test_util::env_vars_for_jsr_tests; use test_util::env_vars_for_npm_tests; +use test_util::itest; use test_util::TestContextBuilder; itest!(no_token { diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index eab7b10bac..c9508594c9 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -11,6 +11,7 @@ use std::process::Command; use std::process::Stdio; use std::time::Duration; use test_util as util; +use test_util::itest; use test_util::TempDir; use trust_dns_client::serialize::txt::Lexer; use trust_dns_client::serialize::txt::Parser; @@ -2652,6 +2653,7 @@ fn dont_cache_on_check_fail() { mod permissions { use test_util as util; + use test_util::itest; use util::TestContext; // TODO(bartlomieju): remove --unstable once Deno.Command is stabilized diff --git a/tests/integration/task_tests.rs b/tests/integration/task_tests.rs index c8531c13f1..b64e329a58 100644 --- a/tests/integration/task_tests.rs +++ b/tests/integration/task_tests.rs @@ -5,6 +5,7 @@ use deno_core::serde_json::json; use test_util::env_vars_for_npm_tests; +use test_util::itest; use test_util::TestContext; use test_util::TestContextBuilder; diff --git a/tests/integration/test_tests.rs b/tests/integration/test_tests.rs index 27bef80075..2984941cd3 100644 --- a/tests/integration/test_tests.rs +++ b/tests/integration/test_tests.rs @@ -2,6 +2,7 @@ use deno_core::url::Url; use test_util as util; +use test_util::itest; use util::assert_contains; use util::assert_not_contains; use util::env_vars_for_npm_tests; diff --git a/tests/integration/vendor_tests.rs b/tests/integration/vendor_tests.rs index c38fb653ac..ab1119fe8e 100644 --- a/tests/integration/vendor_tests.rs +++ b/tests/integration/vendor_tests.rs @@ -6,6 +6,7 @@ use pretty_assertions::assert_eq; use std::fmt::Write as _; use std::path::PathBuf; use test_util as util; +use test_util::itest; use test_util::TempDir; use util::http_server; use util::new_deno_dir; diff --git a/tests/integration/worker_tests.rs b/tests/integration/worker_tests.rs index e2d1ef8688..7b1bddead4 100644 --- a/tests/integration/worker_tests.rs +++ b/tests/integration/worker_tests.rs @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use test_util::itest; + itest!(worker_error { args: "run -A workers/worker_error.ts", output: "workers/worker_error.ts.out", diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs deleted file mode 100644 index 8469b5416a..0000000000 --- a/tests/integration_tests.rs +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. - -// The tests exist in a sub folder instead of as separate files in -// this directory so that cargo doesn't compile each file as a new crate. - -#[cfg(test)] -mod integration; diff --git a/tests/node_compat/test_runner.rs b/tests/node_compat/test_runner.rs new file mode 100644 index 0000000000..e17c2b3736 --- /dev/null +++ b/tests/node_compat/test_runner.rs @@ -0,0 +1,23 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use test_util as util; +use util::deno_config_path; + +#[test] +fn node_compat_tests() { + let mut deno = util::deno_cmd() + .current_dir(util::root_path()) + .arg("test") + .arg("--config") + .arg(deno_config_path()) + .arg("--no-lock") + .arg("--unstable") + .arg("-A") + .arg(util::tests_path().join("node_compat")) + .spawn() + .expect("failed to spawn script"); + + let status = deno.wait().expect("failed to wait for the child process"); + assert_eq!(Some(0), status.code()); + assert!(status.success()); +}