diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-08-08 17:54:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-08 16:54:39 +0000 |
commit | ffe1bfd54c2065fe718872f67e19e8a863c0bf22 (patch) | |
tree | cf315d0c24fd72afd7957622008e7c1893d68ab8 /tests/integration/init_tests.rs | |
parent | 3f692bed0a62de79895ea3373b9004fd6a542035 (diff) |
feat: `deno init --serve` (#24897)
This commit adds "--serve" flag to "deno init" subcommand,
that provides a template for quick starting a project using
"deno serve".
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Diffstat (limited to 'tests/integration/init_tests.rs')
-rw-r--r-- | tests/integration/init_tests.rs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/integration/init_tests.rs b/tests/integration/init_tests.rs index 65a57eeea..757dcb021 100644 --- a/tests/integration/init_tests.rs +++ b/tests/integration/init_tests.rs @@ -170,3 +170,50 @@ Run these commands to get started output.assert_exit_code(0); output.assert_matches_text("Log from main.ts that already exists\n"); } + +#[tokio::test] +async fn init_subcommand_serve() { + let context = TestContextBuilder::for_jsr().use_temp_cwd().build(); + let cwd = context.temp_dir().path(); + + let output = context + .new_command() + .args("init --serve") + .split_output() + .run(); + + output.assert_exit_code(0); + + let stderr = output.stderr(); + assert_contains!(stderr, "Project initialized"); + assert_contains!(stderr, "deno serve -R main.ts"); + assert_contains!(stderr, "deno task dev"); + assert_contains!(stderr, "deno -R test"); + + assert!(cwd.join("deno.json").exists()); + + let mut child = context + .new_command() + .env("NO_COLOR", "1") + .args("serve -R --port 9500 main.ts") + .spawn_with_piped_output(); + + tokio::time::sleep(std::time::Duration::from_millis(1000)).await; + let resp = reqwest::get("http://127.0.0.1:9500").await.unwrap(); + + let body = resp.text().await.unwrap(); + assert_eq!(body, "Home page"); + + let _ = child.kill(); + + let output = context + .new_command() + .env("NO_COLOR", "1") + .args("-R test") + .split_output() + .run(); + + output.assert_exit_code(0); + assert_contains!(output.stdout(), "4 passed"); + output.skip_output_check(); +} |