1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00
denoland-deno/tests/integration/init_tests.rs
Bartek Iwańczuk 0e4d1cb5f9
feat(init): use jsr specifier for @std/assert (#23073)
This commit changes "deno init" subcommand to use "jsr:" specifier for
standard library "assert" module. It is unversioned, but we will change
it to `@^1` once `@std/assert` release version 1.0.

This allows us to start decoupling `deno` and `deno_std` release. The
release scripts have been updated to take that into account.
2024-03-27 18:51:52 +01:00

171 lines
3.9 KiB
Rust
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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::for_jsr().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::for_jsr().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::for_jsr().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");
}