2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2024-03-07 19:32:11 -05:00
|
|
|
use deno_core::serde_json;
|
2023-01-12 20:59:13 -05:00
|
|
|
use test_util as util;
|
2023-04-19 17:50:56 -04:00
|
|
|
use util::assert_contains;
|
2023-11-14 11:58:06 -05:00
|
|
|
use util::assert_not_contains;
|
2023-11-17 22:46:15 -05:00
|
|
|
use util::testdata_path;
|
2023-11-14 11:58:06 -05:00
|
|
|
use util::TestContext;
|
2023-05-10 20:06:59 -04:00
|
|
|
use util::TestContextBuilder;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
#[test]
|
2023-05-25 14:27:45 -04:00
|
|
|
fn compile_basic() {
|
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("welcome.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("welcome")
|
|
|
|
};
|
|
|
|
// try this twice to ensure it works with the cache
|
|
|
|
for _ in 0..2 {
|
2023-05-25 14:27:45 -04:00
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
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.
2024-02-10 15:22:13 -05:00
|
|
|
"../../tests/testdata/welcome.ts",
|
2023-05-25 14:27:45 -04:00
|
|
|
])
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
2023-10-25 14:39:00 -04:00
|
|
|
let output = context.new_command().name(&exe).run();
|
2023-05-25 14:27:45 -04:00
|
|
|
output.assert_matches_text("Welcome to Deno!\n");
|
|
|
|
}
|
|
|
|
|
2024-08-01 05:11:24 -04:00
|
|
|
// On arm64 macOS, check if `codesign -v` passes
|
|
|
|
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
|
|
|
|
{
|
|
|
|
let output = std::process::Command::new("codesign")
|
|
|
|
.arg("-v")
|
|
|
|
.arg(&exe)
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
assert!(output.status.success());
|
|
|
|
}
|
|
|
|
|
2023-05-25 14:27:45 -04:00
|
|
|
// now ensure this works when the deno_dir is readonly
|
|
|
|
let readonly_dir = dir.path().join("readonly");
|
2023-06-10 11:09:45 -04:00
|
|
|
readonly_dir.make_dir_readonly();
|
2023-05-25 14:27:45 -04:00
|
|
|
let readonly_sub_dir = readonly_dir.join("sub");
|
|
|
|
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
// it should fail creating this, but still work
|
2023-06-10 11:09:45 -04:00
|
|
|
.env("DENO_DIR", readonly_sub_dir)
|
2023-10-25 14:39:00 -04:00
|
|
|
.name(exe)
|
2023-05-25 14:27:45 -04:00
|
|
|
.run();
|
|
|
|
output.assert_matches_text("Welcome to Deno!\n");
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn standalone_args() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("args.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("args")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/args.ts",
|
|
|
|
"a",
|
|
|
|
"b",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.args("foo --bar --unstable")
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("a\nb\nfoo\n--bar\n--unstable\n")
|
|
|
|
.assert_exit_code(0);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_error() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("error.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("error")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/standalone_error.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
|
|
|
|
let output = context.new_command().name(&exe).split_output().run();
|
|
|
|
output.assert_exit_code(1);
|
|
|
|
output.assert_stdout_matches_text("");
|
|
|
|
let stderr = output.stderr();
|
2023-01-12 20:59:13 -05:00
|
|
|
// On Windows, we cannot assert the file path (because '\').
|
|
|
|
// Instead we just check for relevant output.
|
2023-12-06 19:02:52 -05:00
|
|
|
assert_contains!(stderr, "error: Uncaught (in promise) Error: boom!");
|
2023-04-19 17:50:56 -04:00
|
|
|
assert_contains!(stderr, "\n at boom (file://");
|
2023-08-21 05:53:52 -04:00
|
|
|
assert_contains!(stderr, "standalone_error.ts:2:9");
|
2023-04-19 17:50:56 -04:00
|
|
|
assert_contains!(stderr, "at foo (file://");
|
2023-08-21 05:53:52 -04:00
|
|
|
assert_contains!(stderr, "standalone_error.ts:5:3");
|
2023-04-19 17:50:56 -04:00
|
|
|
assert_contains!(stderr, "standalone_error.ts:7:1");
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_error_module_with_imports() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("error.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("error")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/standalone_error_module_with_imports_1.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
2023-01-12 20:59:13 -05:00
|
|
|
.env("NO_COLOR", "1")
|
2023-11-14 11:58:06 -05:00
|
|
|
.split_output()
|
|
|
|
.run();
|
|
|
|
output.assert_stdout_matches_text("hello\n");
|
|
|
|
let stderr = output.stderr();
|
2023-01-12 20:59:13 -05:00
|
|
|
// On Windows, we cannot assert the file path (because '\').
|
|
|
|
// Instead we just check for relevant output.
|
2023-12-06 19:02:52 -05:00
|
|
|
assert_contains!(stderr, "error: Uncaught (in promise) Error: boom!");
|
2023-04-19 17:50:56 -04:00
|
|
|
assert_contains!(stderr, "\n at file://");
|
|
|
|
assert_contains!(stderr, "standalone_error_module_with_imports_2.ts:2:7");
|
2023-11-14 11:58:06 -05:00
|
|
|
output.assert_exit_code(1);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_load_datauri() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("load_datauri.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("load_datauri")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/standalone_import_datauri.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("Hello Deno!\n")
|
|
|
|
.assert_exit_code(0);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// https://github.com/denoland/deno/issues/13704
|
|
|
|
#[test]
|
|
|
|
fn standalone_follow_redirects() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("follow_redirects.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("follow_redirects")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
2024-07-24 20:26:54 -04:00
|
|
|
"--config",
|
|
|
|
"../config/deno.json",
|
2023-11-14 11:58:06 -05:00
|
|
|
"./compile/standalone_follow_redirects.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("Hello\n")
|
|
|
|
.assert_exit_code(0);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_with_file_exists_error() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let output_path = if cfg!(windows) {
|
|
|
|
dir.path().join(r"args\")
|
|
|
|
} else {
|
|
|
|
dir.path().join("args/")
|
|
|
|
};
|
|
|
|
let file_path = dir.path().join("args");
|
2023-11-17 10:05:42 -05:00
|
|
|
file_path.write("");
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&output_path.to_string_lossy(),
|
|
|
|
"./compile/args.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.assert_matches_text(&format!(
|
|
|
|
concat!(
|
|
|
|
"[WILDCARD]error: Could not compile to file '{}' because its parent directory ",
|
|
|
|
"is an existing file. You can use the `--output <file-path>` flag to ",
|
|
|
|
"provide an alternative name.\n",
|
|
|
|
),
|
|
|
|
file_path,
|
|
|
|
))
|
|
|
|
.assert_exit_code(1);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_with_directory_exists_error() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("args.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("args")
|
|
|
|
};
|
|
|
|
std::fs::create_dir(&exe).unwrap();
|
2023-11-14 11:58:06 -05:00
|
|
|
context.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/args.ts"
|
|
|
|
]).run()
|
|
|
|
.assert_matches_text(&format!(
|
|
|
|
concat!(
|
|
|
|
"[WILDCARD]error: Could not compile to file '{}' because a directory exists with ",
|
|
|
|
"the same name. You can use the `--output <file-path>` flag to ",
|
|
|
|
"provide an alternative name.\n"
|
|
|
|
),
|
|
|
|
exe
|
|
|
|
))
|
|
|
|
.assert_exit_code(1);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_with_conflict_file_exists_error() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("args.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("args")
|
|
|
|
};
|
|
|
|
std::fs::write(&exe, b"SHOULD NOT BE OVERWRITTEN").unwrap();
|
2023-11-14 11:58:06 -05:00
|
|
|
context.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/args.ts"
|
|
|
|
]).run()
|
|
|
|
.assert_matches_text(&format!(
|
|
|
|
concat!(
|
|
|
|
"[WILDCARD]error: Could not compile to file '{}' because the file already exists ",
|
|
|
|
"and cannot be overwritten. Please delete the existing file or ",
|
|
|
|
"use the `--output <file-path>` flag to provide an alternative name.\n"
|
|
|
|
),
|
|
|
|
exe
|
|
|
|
))
|
|
|
|
.assert_exit_code(1);
|
2023-11-17 10:05:42 -05:00
|
|
|
exe.assert_matches_text("SHOULD NOT BE OVERWRITTEN");
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_and_overwrite_file() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("args.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("args")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
|
|
|
|
// do this twice
|
|
|
|
for _ in 0..2 {
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/args.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
assert!(&exe.exists());
|
|
|
|
}
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_runtime_flags() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("flags.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("flags")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--allow-read",
|
|
|
|
"--seed",
|
|
|
|
"1",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/standalone_runtime_flags.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.name(&exe)
|
|
|
|
.split_output()
|
|
|
|
.run()
|
|
|
|
.assert_stdout_matches_text("0.147205063401058\n")
|
|
|
|
.assert_stderr_matches_text(
|
|
|
|
"[WILDCARD]PermissionDenied: Requires write access to[WILDCARD]",
|
|
|
|
)
|
|
|
|
.assert_exit_code(1);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
2023-03-22 10:15:53 -04:00
|
|
|
#[test]
|
|
|
|
fn standalone_ext_flag_ts() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-03-22 10:15:53 -04:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("ext_flag_ts.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("ext_flag_ts")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--ext",
|
|
|
|
"ts",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./file_extensions/ts_without_extension",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("executing typescript with no extension\n")
|
|
|
|
.assert_exit_code(0);
|
2023-03-22 10:15:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_ext_flag_js() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-03-22 10:15:53 -04:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("ext_flag_js.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("ext_flag_js")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--ext",
|
|
|
|
"js",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./file_extensions/js_without_extension",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("executing javascript with no extension\n");
|
2023-03-22 10:15:53 -04:00
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn standalone_import_map() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("import_map.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("import_map")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--allow-read",
|
|
|
|
"--import-map",
|
|
|
|
"compile/standalone_import_map.json",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/standalone_import_map.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_import_map_config_file() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("import_map.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("import_map")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--allow-read",
|
|
|
|
"--config",
|
|
|
|
"compile/standalone_import_map_config.json",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/standalone_import_map.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
// https://github.com/denoland/deno/issues/12670
|
|
|
|
fn skip_rebundle() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("hello_world.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("hello_world")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./run/001_hello.js",
|
|
|
|
])
|
|
|
|
.run();
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
//no "Bundle testdata_path/run/001_hello.js" in output
|
2023-11-14 11:58:06 -05:00
|
|
|
assert_not_contains!(output.combined_output(), "Bundle");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("Hello World\n")
|
|
|
|
.assert_exit_code(0);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_local_by_default() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContext::with_http_server();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("welcome.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("welcome")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/check_local_by_default.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn check_local_by_default2() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContext::with_http_server();
|
|
|
|
let dir = context.temp_dir();
|
2023-01-12 20:59:13 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("welcome.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("welcome")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/check_local_by_default2.ts"
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.assert_matches_text(
|
|
|
|
r#"[WILDCARD]error: TS2322 [ERROR]: Type '12' is not assignable to type '"b"'.[WILDCARD]"#,
|
|
|
|
)
|
|
|
|
.assert_exit_code(1);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
2023-03-04 20:37:54 -05:00
|
|
|
|
2023-03-19 18:32:54 -04:00
|
|
|
#[test]
|
|
|
|
fn workers_basic() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContext::with_http_server();
|
|
|
|
let dir = context.temp_dir();
|
2023-03-19 18:32:54 -04:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("basic.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("basic")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--no-check",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/workers/basic.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.run()
|
|
|
|
.assert_matches_file("./compile/workers/basic.out")
|
|
|
|
.assert_exit_code(0);
|
2023-03-19 18:32:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn workers_not_in_module_map() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContext::with_http_server();
|
2023-05-10 20:06:59 -04:00
|
|
|
let temp_dir = context.temp_dir();
|
2023-03-19 18:32:54 -04:00
|
|
|
let exe = if cfg!(windows) {
|
2023-05-10 20:06:59 -04:00
|
|
|
temp_dir.path().join("not_in_module_map.exe")
|
2023-03-19 18:32:54 -04:00
|
|
|
} else {
|
2023-05-10 20:06:59 -04:00
|
|
|
temp_dir.path().join("not_in_module_map")
|
2023-03-19 18:32:54 -04:00
|
|
|
};
|
2023-05-10 20:06:59 -04:00
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
2023-11-14 11:58:06 -05:00
|
|
|
"./compile/workers/not_in_module_map.ts",
|
2023-05-10 20:06:59 -04:00
|
|
|
])
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
2023-03-19 18:32:54 -04:00
|
|
|
|
2023-10-25 14:39:00 -04:00
|
|
|
let output = context.new_command().name(exe).env("NO_COLOR", "").run();
|
2023-05-10 20:06:59 -04:00
|
|
|
output.assert_exit_code(1);
|
|
|
|
output.assert_matches_text(concat!(
|
|
|
|
"error: Uncaught (in worker \"\") Module not found: [WILDCARD]",
|
|
|
|
"error: Uncaught (in promise) Error: Unhandled error in child worker.\n[WILDCARD]"
|
|
|
|
));
|
2023-03-19 18:32:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn workers_with_include_flag() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContext::with_http_server();
|
|
|
|
let dir = context.temp_dir();
|
2023-03-19 18:32:54 -04:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("workers_with_include_flag.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("workers_with_include_flag")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"--include",
|
|
|
|
"./compile/workers/worker.ts",
|
|
|
|
"./compile/workers/not_in_module_map.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.env("NO_COLOR", "")
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("Hello from worker!\nReceived 42\nClosing\n");
|
2023-03-19 18:32:54 -04:00
|
|
|
}
|
|
|
|
|
2023-03-04 20:37:54 -05:00
|
|
|
#[test]
|
|
|
|
fn dynamic_import() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContext::with_http_server();
|
|
|
|
let dir = context.temp_dir();
|
2023-03-04 20:37:54 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("dynamic_import.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("dynamic_import")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/dynamic_imports/main.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&exe)
|
|
|
|
.env("NO_COLOR", "")
|
|
|
|
.run()
|
|
|
|
.assert_matches_file("./compile/dynamic_imports/main.out")
|
|
|
|
.assert_exit_code(0);
|
2023-03-04 20:37:54 -05:00
|
|
|
}
|
2023-03-18 19:43:07 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dynamic_import_unanalyzable() {
|
2023-11-14 11:58:06 -05:00
|
|
|
let context = TestContext::with_http_server();
|
|
|
|
let dir = context.temp_dir();
|
2023-03-18 19:43:07 -04:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("dynamic_import_unanalyzable.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("dynamic_import_unanalyzable")
|
|
|
|
};
|
2023-11-14 11:58:06 -05:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--allow-read",
|
|
|
|
"--include",
|
|
|
|
"./compile/dynamic_imports/import1.ts",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/dynamic_imports/main_unanalyzable.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
|
|
|
|
context
|
|
|
|
.new_command()
|
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.
2024-02-10 15:22:13 -05:00
|
|
|
.current_dir(util::root_path())
|
2023-11-14 11:58:06 -05:00
|
|
|
.name(&exe)
|
|
|
|
.env("NO_COLOR", "")
|
|
|
|
.run()
|
|
|
|
.assert_matches_file("./compile/dynamic_imports/main.out")
|
|
|
|
.assert_exit_code(0);
|
2023-03-18 19:43:07 -04:00
|
|
|
}
|
2023-05-10 20:06:59 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_specifiers() {
|
2023-09-18 10:46:44 -04:00
|
|
|
let context = TestContextBuilder::for_npm().use_temp_cwd().build();
|
2023-05-10 20:06:59 -04:00
|
|
|
|
|
|
|
let temp_dir = context.temp_dir();
|
|
|
|
temp_dir.write(
|
|
|
|
"main.ts",
|
|
|
|
concat!(
|
|
|
|
"import path from 'node:path';\n",
|
|
|
|
"import { getValue, setValue } from 'npm:@denotest/esm-basic';\n",
|
|
|
|
"import getValueDefault from 'npm:@denotest/esm-import-cjs-default';\n",
|
|
|
|
"setValue(2);\n",
|
|
|
|
"console.log(path.join('testing', 'this'));",
|
|
|
|
"console.log(getValue());",
|
|
|
|
"console.log(getValueDefault());",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
let binary_path = if cfg!(windows) {
|
|
|
|
temp_dir.path().join("binary.exe")
|
|
|
|
} else {
|
|
|
|
temp_dir.path().join("binary")
|
|
|
|
};
|
|
|
|
|
|
|
|
// try with and without --node-modules-dir
|
|
|
|
let compile_commands = &[
|
2023-05-18 19:26:49 -04:00
|
|
|
"compile --output binary main.ts",
|
|
|
|
"compile --node-modules-dir --output binary main.ts",
|
2023-05-10 20:06:59 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
for compile_command in compile_commands {
|
|
|
|
let output = context.new_command().args(compile_command).run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
|
|
|
|
2023-10-25 14:39:00 -04:00
|
|
|
let output = context.new_command().name(&binary_path).run();
|
2023-05-10 20:06:59 -04:00
|
|
|
output.assert_matches_text(
|
|
|
|
r#"Node esm importing node cjs
|
|
|
|
===========================
|
|
|
|
{
|
|
|
|
default: [Function (anonymous)],
|
|
|
|
named: [Function (anonymous)],
|
|
|
|
MyClass: [class MyClass]
|
|
|
|
}
|
|
|
|
{ default: [Function (anonymous)], named: [Function (anonymous)] }
|
|
|
|
[Module: null prototype] {
|
|
|
|
MyClass: [class MyClass],
|
|
|
|
__esModule: true,
|
|
|
|
default: {
|
|
|
|
default: [Function (anonymous)],
|
|
|
|
named: [Function (anonymous)],
|
|
|
|
MyClass: [class MyClass]
|
|
|
|
},
|
|
|
|
named: [Function (anonymous)]
|
|
|
|
}
|
|
|
|
[Module: null prototype] {
|
|
|
|
__esModule: true,
|
|
|
|
default: { default: [Function (anonymous)], named: [Function (anonymous)] },
|
|
|
|
named: [Function (anonymous)]
|
|
|
|
}
|
|
|
|
===========================
|
|
|
|
static method
|
|
|
|
testing[WILDCARD]this
|
|
|
|
2
|
|
|
|
5
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// try with a package.json
|
|
|
|
temp_dir.remove_dir_all("node_modules");
|
|
|
|
temp_dir.write(
|
|
|
|
"main.ts",
|
|
|
|
concat!(
|
|
|
|
"import { getValue, setValue } from '@denotest/esm-basic';\n",
|
|
|
|
"setValue(2);\n",
|
|
|
|
"console.log(getValue());",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
temp_dir.write(
|
|
|
|
"package.json",
|
|
|
|
r#"{ "dependencies": { "@denotest/esm-basic": "1" } }"#,
|
|
|
|
);
|
|
|
|
|
2023-11-29 09:32:23 -05:00
|
|
|
context
|
2023-05-10 20:06:59 -04:00
|
|
|
.new_command()
|
2023-05-18 19:26:49 -04:00
|
|
|
.args("compile --output binary main.ts")
|
2023-11-29 09:32:23 -05:00
|
|
|
.run()
|
|
|
|
.assert_exit_code(0)
|
|
|
|
.skip_output_check();
|
|
|
|
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&binary_path)
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("2\n");
|
2023-05-10 20:06:59 -04:00
|
|
|
|
2023-11-29 09:32:23 -05:00
|
|
|
// now try with byonm
|
|
|
|
temp_dir.remove_dir_all("node_modules");
|
|
|
|
temp_dir.write("deno.json", r#"{"unstable":["byonm"]}"#);
|
|
|
|
context.run_npm("install");
|
|
|
|
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args("compile --output binary main.ts")
|
|
|
|
.run()
|
|
|
|
.assert_exit_code(0)
|
2024-07-03 20:54:33 -04:00
|
|
|
.assert_matches_text("Check file:///[WILDLINE]/main.ts\nCompile file:///[WILDLINE]/main.ts to binary[WILDLINE]\n");
|
2023-11-29 09:32:23 -05:00
|
|
|
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.name(&binary_path)
|
|
|
|
.run()
|
|
|
|
.assert_matches_text("2\n");
|
2023-05-10 20:06:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_file_system() {
|
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "compile/npm_fs/main.ts",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: Some("compile/npm_fs"),
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec!["-A"],
|
|
|
|
run_args: vec![],
|
2023-05-10 20:06:59 -04:00
|
|
|
output_file: "compile/npm_fs/main.out",
|
|
|
|
node_modules_dir: true,
|
|
|
|
input_name: Some("binary"),
|
|
|
|
expected_name: "binary",
|
2023-05-26 13:33:38 -04:00
|
|
|
exit_code: 0,
|
2023-05-10 20:06:59 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_bin_esm() {
|
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "npm:@denotest/bin/cli-esm",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: None,
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec![],
|
2023-05-10 20:06:59 -04:00
|
|
|
run_args: vec!["this", "is", "a", "test"],
|
|
|
|
output_file: "npm/deno_run_esm.out",
|
|
|
|
node_modules_dir: false,
|
|
|
|
input_name: None,
|
|
|
|
expected_name: "cli-esm",
|
2023-05-26 13:33:38 -04:00
|
|
|
exit_code: 0,
|
2023-05-10 20:06:59 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_bin_cjs() {
|
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "npm:@denotest/bin/cli-cjs",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: None,
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec![],
|
2023-05-10 20:06:59 -04:00
|
|
|
run_args: vec!["this", "is", "a", "test"],
|
|
|
|
output_file: "npm/deno_run_cjs.out",
|
|
|
|
node_modules_dir: false,
|
|
|
|
input_name: None,
|
|
|
|
expected_name: "cli-cjs",
|
2023-05-26 13:33:38 -04:00
|
|
|
exit_code: 0,
|
2023-05-10 20:06:59 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-05-26 13:33:38 -04:00
|
|
|
fn compile_npm_cowsay_main() {
|
2023-05-10 20:06:59 -04:00
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "npm:cowsay@1.5.0",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: None,
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec!["--allow-read"],
|
2023-05-10 20:06:59 -04:00
|
|
|
run_args: vec!["Hello"],
|
|
|
|
output_file: "npm/deno_run_cowsay.out",
|
|
|
|
node_modules_dir: false,
|
|
|
|
input_name: None,
|
|
|
|
expected_name: "cowsay",
|
2023-05-26 13:33:38 -04:00
|
|
|
exit_code: 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_vfs_implicit_read_permissions() {
|
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "compile/vfs_implicit_read_permission/main.ts",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: Some("compile/vfs_implicit_read_permission"),
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec![],
|
|
|
|
run_args: vec![],
|
|
|
|
output_file: "compile/vfs_implicit_read_permission/main.out",
|
|
|
|
node_modules_dir: false,
|
|
|
|
input_name: Some("binary"),
|
|
|
|
expected_name: "binary",
|
|
|
|
exit_code: 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_no_permissions() {
|
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "npm:cowsay@1.5.0",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: None,
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec![],
|
|
|
|
run_args: vec!["Hello"],
|
|
|
|
output_file: "npm/deno_run_cowsay_no_permissions.out",
|
|
|
|
node_modules_dir: false,
|
|
|
|
input_name: None,
|
|
|
|
expected_name: "cowsay",
|
|
|
|
exit_code: 1,
|
2023-05-10 20:06:59 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_cowsay_explicit() {
|
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "npm:cowsay@1.5.0/cowsay",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: None,
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec!["--allow-read"],
|
2023-05-10 20:06:59 -04:00
|
|
|
run_args: vec!["Hello"],
|
|
|
|
output_file: "npm/deno_run_cowsay.out",
|
|
|
|
node_modules_dir: false,
|
|
|
|
input_name: None,
|
|
|
|
expected_name: "cowsay",
|
2023-05-26 13:33:38 -04:00
|
|
|
exit_code: 0,
|
2023-05-10 20:06:59 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_npm_cowthink() {
|
|
|
|
run_npm_bin_compile_test(RunNpmBinCompileOptions {
|
|
|
|
input_specifier: "npm:cowsay@1.5.0/cowthink",
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: None,
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: vec!["--allow-read"],
|
2023-05-10 20:06:59 -04:00
|
|
|
run_args: vec!["Hello"],
|
|
|
|
output_file: "npm/deno_run_cowthink.out",
|
|
|
|
node_modules_dir: false,
|
|
|
|
input_name: None,
|
|
|
|
expected_name: "cowthink",
|
2023-05-26 13:33:38 -04:00
|
|
|
exit_code: 0,
|
2023-05-10 20:06:59 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RunNpmBinCompileOptions<'a> {
|
|
|
|
input_specifier: &'a str,
|
2024-07-03 20:54:33 -04:00
|
|
|
copy_temp_dir: Option<&'a str>,
|
2023-05-10 20:06:59 -04:00
|
|
|
node_modules_dir: bool,
|
2023-05-26 13:33:38 -04:00
|
|
|
output_file: &'a str,
|
2023-05-10 20:06:59 -04:00
|
|
|
input_name: Option<&'a str>,
|
|
|
|
expected_name: &'a str,
|
|
|
|
run_args: Vec<&'a str>,
|
2023-05-26 13:33:38 -04:00
|
|
|
compile_args: Vec<&'a str>,
|
|
|
|
exit_code: i32,
|
2023-05-10 20:06:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn run_npm_bin_compile_test(opts: RunNpmBinCompileOptions) {
|
2024-07-03 20:54:33 -04:00
|
|
|
let builder = TestContextBuilder::for_npm();
|
|
|
|
let context = match opts.copy_temp_dir {
|
|
|
|
Some(copy_temp_dir) => builder.use_copy_temp_dir(copy_temp_dir).build(),
|
|
|
|
None => builder.use_temp_cwd().build(),
|
2023-05-10 20:06:59 -04:00
|
|
|
};
|
|
|
|
|
2024-07-03 20:54:33 -04:00
|
|
|
let temp_dir = context.temp_dir();
|
2023-05-26 13:33:38 -04:00
|
|
|
let mut args = vec!["compile".to_string()];
|
|
|
|
|
|
|
|
args.extend(opts.compile_args.iter().map(|s| s.to_string()));
|
2023-05-10 20:06:59 -04:00
|
|
|
|
|
|
|
if opts.node_modules_dir {
|
|
|
|
args.push("--node-modules-dir".to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(bin_name) = opts.input_name {
|
|
|
|
args.push("--output".to_string());
|
|
|
|
args.push(bin_name.to_string());
|
|
|
|
}
|
|
|
|
|
2024-07-03 20:54:33 -04:00
|
|
|
args.push(opts.input_specifier.to_string());
|
2023-05-10 20:06:59 -04:00
|
|
|
|
|
|
|
// compile
|
|
|
|
let output = context.new_command().args_vec(args).run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
|
|
|
|
2023-06-08 11:48:29 -04:00
|
|
|
// delete the npm folder in the DENO_DIR to ensure it's not using it
|
|
|
|
context.deno_dir().remove_dir_all("./npm");
|
|
|
|
|
2023-05-10 20:06:59 -04:00
|
|
|
// run
|
|
|
|
let binary_path = if cfg!(windows) {
|
|
|
|
temp_dir.path().join(format!("{}.exe", opts.expected_name))
|
|
|
|
} else {
|
|
|
|
temp_dir.path().join(opts.expected_name)
|
|
|
|
};
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
2023-10-25 14:39:00 -04:00
|
|
|
.name(binary_path)
|
2023-05-10 20:06:59 -04:00
|
|
|
.args_vec(opts.run_args)
|
|
|
|
.run();
|
|
|
|
output.assert_matches_file(opts.output_file);
|
2023-05-26 13:33:38 -04:00
|
|
|
output.assert_exit_code(opts.exit_code);
|
2023-05-10 20:06:59 -04:00
|
|
|
}
|
2023-05-27 10:33:15 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compile_node_modules_symlink_outside() {
|
2024-07-03 20:54:33 -04:00
|
|
|
// this code is using a canonicalized temp dir because otherwise
|
|
|
|
// it fails on the Windows CI because Deno makes the root directory
|
|
|
|
// a common ancestor of the symlinked temp dir and the canonicalized
|
|
|
|
// temp dir, which causes the warnings to not be surfaced
|
|
|
|
#[allow(deprecated)]
|
2023-05-27 10:33:15 -04:00
|
|
|
let context = TestContextBuilder::for_npm()
|
2024-07-03 20:54:33 -04:00
|
|
|
.use_canonicalized_temp_dir()
|
2023-05-27 10:33:15 -04:00
|
|
|
.use_copy_temp_dir("compile/node_modules_symlink_outside")
|
|
|
|
.cwd("compile/node_modules_symlink_outside")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
let temp_dir = context.temp_dir();
|
|
|
|
let project_dir = temp_dir
|
|
|
|
.path()
|
|
|
|
.join("compile")
|
|
|
|
.join("node_modules_symlink_outside");
|
2024-07-03 20:54:33 -04:00
|
|
|
let symlink_target_dir = temp_dir.path().join("some_folder");
|
|
|
|
project_dir.join("node_modules").create_dir_all();
|
|
|
|
symlink_target_dir.create_dir_all();
|
|
|
|
let symlink_target_file = temp_dir.path().join("target.txt");
|
|
|
|
symlink_target_file.write("5");
|
|
|
|
let symlink_dir = project_dir.join("node_modules").join("symlink_dir");
|
|
|
|
|
|
|
|
// create a symlink in the node_modules directory that points to a folder outside the project
|
|
|
|
temp_dir.symlink_dir(&symlink_target_dir, &symlink_dir);
|
2023-05-27 10:33:15 -04:00
|
|
|
// compile folder
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("compile --allow-read --node-modules-dir --output bin main.ts")
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.assert_matches_file(
|
|
|
|
"compile/node_modules_symlink_outside/main_compile_folder.out",
|
|
|
|
);
|
2024-07-03 20:54:33 -04:00
|
|
|
assert!(symlink_dir.exists());
|
2023-05-27 10:33:15 -04:00
|
|
|
|
|
|
|
// Cleanup and remove the folder. The folder test is done separately from
|
|
|
|
// the file symlink test because different systems would traverse
|
|
|
|
// the directory items in different order.
|
2024-07-03 20:54:33 -04:00
|
|
|
symlink_dir.remove_dir_all();
|
2023-05-27 10:33:15 -04:00
|
|
|
|
|
|
|
// create a symlink in the node_modules directory that points to a file in the cwd
|
|
|
|
temp_dir.symlink_file(
|
2024-07-03 20:54:33 -04:00
|
|
|
&symlink_target_file,
|
2023-05-27 10:33:15 -04:00
|
|
|
project_dir.join("node_modules").join("test.txt"),
|
|
|
|
);
|
|
|
|
assert!(project_dir.join("node_modules/test.txt").exists());
|
|
|
|
|
|
|
|
// compile
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("compile --allow-read --node-modules-dir --output bin main.ts")
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.assert_matches_file(
|
|
|
|
"compile/node_modules_symlink_outside/main_compile_file.out",
|
|
|
|
);
|
|
|
|
|
|
|
|
// run
|
|
|
|
let binary_path =
|
|
|
|
project_dir.join(if cfg!(windows) { "bin.exe" } else { "bin" });
|
2023-10-25 14:39:00 -04:00
|
|
|
let output = context.new_command().name(binary_path).run();
|
2023-05-27 10:33:15 -04:00
|
|
|
output.assert_matches_file("compile/node_modules_symlink_outside/main.out");
|
|
|
|
}
|
2023-12-01 15:12:10 -05:00
|
|
|
|
2023-12-06 16:25:24 -05:00
|
|
|
#[test]
|
|
|
|
fn compile_node_modules_symlink_non_existent() {
|
|
|
|
let context = TestContextBuilder::for_npm().use_temp_cwd().build();
|
|
|
|
let temp_dir = context.temp_dir().path();
|
|
|
|
temp_dir.join("main.ts").write(
|
|
|
|
r#"import { getValue, setValue } from "npm:@denotest/esm-basic";
|
|
|
|
setValue(4);
|
|
|
|
console.log(getValue());"#,
|
|
|
|
);
|
|
|
|
let node_modules_dir = temp_dir.join("node_modules");
|
|
|
|
node_modules_dir.create_dir_all();
|
|
|
|
// create a symlink that points to a non_existent file
|
|
|
|
node_modules_dir.symlink_dir("non_existent", "folder");
|
|
|
|
// compile folder
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args("compile --allow-read --node-modules-dir --output bin main.ts")
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.assert_matches_text(
|
2024-05-07 13:21:56 -04:00
|
|
|
r#"Download http://localhost:4260/@denotest/esm-basic
|
|
|
|
Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz
|
2023-12-06 16:25:24 -05:00
|
|
|
Initialize @denotest/esm-basic@1.0.0
|
|
|
|
Check file:///[WILDCARD]/main.ts
|
|
|
|
Compile file:///[WILDCARD]/main.ts to [WILDCARD]
|
|
|
|
Warning Failed resolving symlink. Ignoring.
|
|
|
|
Path: [WILDCARD]
|
|
|
|
Message: [WILDCARD])
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
// run
|
|
|
|
let binary_path =
|
|
|
|
temp_dir.join(if cfg!(windows) { "bin.exe" } else { "bin" });
|
|
|
|
let output = context.new_command().name(binary_path).run();
|
|
|
|
output.assert_matches_text("4\n");
|
|
|
|
}
|
|
|
|
|
2023-12-01 15:12:10 -05:00
|
|
|
#[test]
|
|
|
|
fn dynamic_imports_tmp_lit() {
|
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("app.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("app")
|
|
|
|
};
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/dynamic_imports_tmp_lit/main.js",
|
|
|
|
])
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
|
|
|
let output = context.new_command().name(&exe).run();
|
|
|
|
output.assert_matches_text("a\nb\n{ data: 5 }\n{ data: 1 }\n");
|
|
|
|
}
|
2024-01-06 09:01:09 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn granular_unstable_features() {
|
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("app.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("app")
|
|
|
|
};
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"--unstable-kv",
|
2024-03-07 19:32:11 -05:00
|
|
|
"--unstable-temporal",
|
2024-01-06 09:01:09 -05:00
|
|
|
"./compile/unstable_features.ts",
|
|
|
|
])
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
|
|
|
let output = context.new_command().name(&exe).run();
|
|
|
|
output.assert_exit_code(0);
|
2024-03-07 19:32:11 -05:00
|
|
|
output.assert_matches_text("Kv {}\nObject [Temporal] {}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn granular_unstable_features_config_file() {
|
2024-07-03 20:54:33 -04:00
|
|
|
let context = TestContextBuilder::new().use_temp_cwd().build();
|
2024-03-07 19:32:11 -05:00
|
|
|
let dir = context.temp_dir();
|
2024-07-03 20:54:33 -04:00
|
|
|
testdata_path()
|
|
|
|
.join("compile/unstable_features.ts")
|
|
|
|
.copy(&dir.path().join("unstable_features.ts"));
|
2024-03-07 19:32:11 -05:00
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("app.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("app")
|
|
|
|
};
|
|
|
|
dir.write(
|
|
|
|
"deno.json",
|
|
|
|
serde_json::to_string_pretty(&serde_json::json!({
|
|
|
|
"unstable": ["kv", "temporal"]
|
|
|
|
}))
|
|
|
|
.unwrap(),
|
|
|
|
);
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--config",
|
|
|
|
&dir.path().join("deno.json").to_string(),
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
2024-07-03 20:54:33 -04:00
|
|
|
"./unstable_features.ts",
|
2024-03-07 19:32:11 -05:00
|
|
|
])
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
|
|
|
let output = context.new_command().name(&exe).run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.assert_matches_text("Kv {}\nObject [Temporal] {}\n");
|
2024-01-06 09:01:09 -05:00
|
|
|
}
|
2024-01-31 22:15:22 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn dynamic_import_bad_data_uri() {
|
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("app.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("app")
|
|
|
|
};
|
|
|
|
let file = dir.path().join("bad_data_uri.ts");
|
|
|
|
file.write("await import('data:application/')");
|
|
|
|
let output = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
&file.to_string_lossy(),
|
|
|
|
])
|
|
|
|
.run();
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.skip_output_check();
|
|
|
|
let output = context.new_command().name(&exe).run();
|
|
|
|
output.assert_exit_code(1);
|
|
|
|
output.assert_matches_text(
|
|
|
|
"[WILDCARD]TypeError: Unable to decode data url.[WILDCARD]",
|
|
|
|
);
|
|
|
|
}
|
2024-02-21 18:03:11 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_config_file_respects_compiler_options() {
|
|
|
|
let context = TestContextBuilder::new().build();
|
|
|
|
let dir = context.temp_dir();
|
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("compiler_options.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("compiler_options")
|
|
|
|
};
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--allow-read",
|
|
|
|
"--config",
|
|
|
|
"compile/compiler_options/deno.json",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/compiler_options/main.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
let output = context.new_command().name(&exe).run();
|
|
|
|
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.assert_matches_text("[WILDCARD]C.test() called[WILDCARD]");
|
|
|
|
}
|
2024-04-12 06:27:34 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn standalone_jsr_dynamic_import() {
|
|
|
|
let context = TestContextBuilder::for_jsr().build();
|
|
|
|
let dir = context.temp_dir();
|
|
|
|
let exe = if cfg!(windows) {
|
|
|
|
dir.path().join("jsr_dynamic_import.exe")
|
|
|
|
} else {
|
|
|
|
dir.path().join("jsr_dynamic_import")
|
|
|
|
};
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"compile",
|
|
|
|
"--output",
|
|
|
|
&exe.to_string_lossy(),
|
|
|
|
"./compile/jsr_dynamic_import/main.ts",
|
|
|
|
])
|
|
|
|
.run()
|
|
|
|
.skip_output_check()
|
|
|
|
.assert_exit_code(0);
|
|
|
|
let output = context.new_command().name(&exe).run();
|
|
|
|
|
|
|
|
output.assert_exit_code(0);
|
|
|
|
output.assert_matches_text("Hello world\n");
|
|
|
|
}
|