summaryrefslogtreecommitdiff
path: root/tests/integration/init_tests.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-02-10 13:22:13 -0700
committerGitHub <noreply@github.com>2024-02-10 20:22:13 +0000
commitf5e46c9bf2f50d66a953fa133161fc829cecff06 (patch)
tree8faf2f5831c1c7b11d842cd9908d141082c869a5 /tests/integration/init_tests.rs
parentd2477f780630a812bfd65e3987b70c0d309385bb (diff)
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests -> tests, and updates of relative paths for files. This is the first step towards aggregate all of the integration test files under tests/, which will lead to a set of integration tests that can run without the CLI binary being built. While we could leave these tests under `cli`, it would require us to keep a more complex directory structure for the various test runners. In addition, we have a lot of complexity to ignore various test files in the `cli` project itself (cargo publish exclusion rules, autotests = false, etc). And finally, the `tests/` folder will eventually house the `test_ffi`, `test_napi` and other testing code, reducing the size of the root repo directory. For easier review, the extremely large and noisy "move" is in the first commit (with no changes -- just a move), while the remainder of the changes to actual files is in the second commit.
Diffstat (limited to 'tests/integration/init_tests.rs')
-rw-r--r--tests/integration/init_tests.rs171
1 files changed, 171 insertions, 0 deletions
diff --git a/tests/integration/init_tests.rs b/tests/integration/init_tests.rs
new file mode 100644
index 000000000..d3908eae4
--- /dev/null
+++ b/tests/integration/init_tests.rs
@@ -0,0 +1,171 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+use test_util as util;
+use util::assert_contains;
+use util::TestContextBuilder;
+
+#[test]
+fn init_subcommand_without_dir() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let cwd = context.temp_dir().path();
+
+ let output = context.new_command().args("init").split_output().run();
+
+ output.assert_exit_code(0);
+
+ let stderr = output.stderr();
+ assert_contains!(stderr, "Project initialized");
+ assert!(!stderr.contains("cd"));
+ assert_contains!(stderr, "deno run main.ts");
+ assert_contains!(stderr, "deno task dev");
+ assert_contains!(stderr, "deno test");
+
+ assert!(cwd.join("deno.json").exists());
+
+ let output = context
+ .new_command()
+ .env("NO_COLOR", "1")
+ .args("run main.ts")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+ assert_eq!(output.stdout().as_bytes(), b"Add 2 + 3 = 5\n");
+
+ let output = context
+ .new_command()
+ .env("NO_COLOR", "1")
+ .args("test")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+ assert_contains!(output.stdout(), "1 passed");
+ output.skip_output_check();
+}
+
+#[test]
+fn init_subcommand_with_dir_arg() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let cwd = context.temp_dir().path();
+
+ let output = context
+ .new_command()
+ .args("init my_dir")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+
+ let stderr = output.stderr();
+ assert_contains!(stderr, "Project initialized");
+ assert_contains!(stderr, "cd my_dir");
+ assert_contains!(stderr, "deno run main.ts");
+ assert_contains!(stderr, "deno task dev");
+ assert_contains!(stderr, "deno test");
+
+ assert!(cwd.join("my_dir/deno.json").exists());
+
+ let output = context
+ .new_command()
+ .env("NO_COLOR", "1")
+ .args("run my_dir/main.ts")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+
+ assert_eq!(output.stdout().as_bytes(), b"Add 2 + 3 = 5\n");
+ output.skip_output_check();
+
+ let output = context
+ .new_command()
+ .env("NO_COLOR", "1")
+ .args("test my_dir/main_test.ts")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+ assert_contains!(output.stdout(), "1 passed");
+ output.skip_output_check();
+}
+
+#[test]
+fn init_subcommand_with_quiet_arg() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let cwd = context.temp_dir().path();
+
+ let output = context
+ .new_command()
+ .args("init --quiet")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+
+ assert_eq!(output.stdout(), "");
+ assert!(cwd.join("deno.json").exists());
+
+ let output = context
+ .new_command()
+ .env("NO_COLOR", "1")
+ .args("run main.ts")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+ assert_eq!(output.stdout().as_bytes(), b"Add 2 + 3 = 5\n");
+ output.skip_output_check();
+
+ let output = context
+ .new_command()
+ .env("NO_COLOR", "1")
+ .args("test")
+ .split_output()
+ .run();
+
+ output.assert_exit_code(0);
+ assert_contains!(output.stdout(), "1 passed");
+ output.skip_output_check();
+}
+
+#[test]
+fn init_subcommand_with_existing_file() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let cwd = context.temp_dir().path();
+
+ cwd
+ .join("main.ts")
+ .write("console.log('Log from main.ts that already exists');");
+
+ let output = context.new_command().args("init").split_output().run();
+
+ output.assert_exit_code(0);
+ output.assert_stderr_matches_text(
+ "ℹ️ Skipped creating main.ts as it already exists
+✅ Project initialized
+
+Run these commands to get started
+
+ # Run the program
+ deno run main.ts
+
+ # Run the program and watch for file changes
+ deno task dev
+
+ # Run the tests
+ deno test
+",
+ );
+
+ assert!(cwd.join("deno.json").exists());
+
+ let output = context
+ .new_command()
+ .env("NO_COLOR", "1")
+ .args("run main.ts")
+ .run();
+
+ output.assert_exit_code(0);
+ output.assert_matches_text("Log from main.ts that already exists\n");
+}