diff options
Diffstat (limited to 'cli/tests')
5 files changed, 81 insertions, 0 deletions
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index 4938b36cd..f202fc87e 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -1082,3 +1082,68 @@ fn run_npm_bin_compile_test(opts: RunNpmBinCompileOptions) { output.assert_matches_file(opts.output_file); output.assert_exit_code(opts.exit_code); } + +#[test] +fn compile_node_modules_symlink_outside() { + let context = TestContextBuilder::for_npm() + .use_sync_npm_download() + .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"); + temp_dir.create_dir_all(project_dir.join("node_modules")); + temp_dir.create_dir_all(project_dir.join("some_folder")); + temp_dir.write(project_dir.join("test.txt"), "5"); + + // create a symlink in the node_modules directory that points to a folder in the cwd + temp_dir.symlink_dir( + project_dir.join("some_folder"), + project_dir.join("node_modules").join("some_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_file( + "compile/node_modules_symlink_outside/main_compile_folder.out", + ); + assert!(project_dir.join("node_modules/some_folder").exists()); + + // 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. + temp_dir.remove_dir_all(project_dir.join("node_modules/some_folder")); + + // create a symlink in the node_modules directory that points to a file in the cwd + temp_dir.symlink_file( + project_dir.join("test.txt"), + 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" }); + let output = context + .new_command() + .command_name(binary_path.to_string_lossy()) + .run(); + output.assert_matches_file("compile/node_modules_symlink_outside/main.out"); +} diff --git a/cli/tests/testdata/compile/node_modules_symlink_outside/main.out b/cli/tests/testdata/compile/node_modules_symlink_outside/main.out new file mode 100644 index 000000000..61c83cba4 --- /dev/null +++ b/cli/tests/testdata/compile/node_modules_symlink_outside/main.out @@ -0,0 +1,2 @@ +4 +5 diff --git a/cli/tests/testdata/compile/node_modules_symlink_outside/main.ts b/cli/tests/testdata/compile/node_modules_symlink_outside/main.ts new file mode 100644 index 000000000..45f681f7c --- /dev/null +++ b/cli/tests/testdata/compile/node_modules_symlink_outside/main.ts @@ -0,0 +1,6 @@ +import { getValue, setValue } from "npm:@denotest/esm-basic"; + +setValue(4); + +console.log(getValue()); +console.log(Deno.readTextFileSync("./node_modules/test.txt")); diff --git a/cli/tests/testdata/compile/node_modules_symlink_outside/main_compile_file.out b/cli/tests/testdata/compile/node_modules_symlink_outside/main_compile_file.out new file mode 100644 index 000000000..7602a4002 --- /dev/null +++ b/cli/tests/testdata/compile/node_modules_symlink_outside/main_compile_file.out @@ -0,0 +1,2 @@ +Compile file:///[WILDCARD]/node_modules_symlink_outside/main.ts to [WILDCARD] +Symlink target is outside '[WILDCARD]node_modules_symlink_outside[WILDCARD]node_modules'. Inlining symlink at '[WILDCARD]node_modules_symlink_outside[WILDCARD]node_modules[WILDCARD]test.txt' to '[WILDCARD]node_modules_symlink_outside[WILDCARD]test.txt' as file. diff --git a/cli/tests/testdata/compile/node_modules_symlink_outside/main_compile_folder.out b/cli/tests/testdata/compile/node_modules_symlink_outside/main_compile_folder.out new file mode 100644 index 000000000..883a3f262 --- /dev/null +++ b/cli/tests/testdata/compile/node_modules_symlink_outside/main_compile_folder.out @@ -0,0 +1,6 @@ +Download http://localhost:4545/npm/registry/@denotest/esm-basic +Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 +Check file:///[WILDCARD]/node_modules_symlink_outside/main.ts +Compile file:///[WILDCARD]/node_modules_symlink_outside/main.ts to [WILDCARD] +Symlink target is outside '[WILDCARD]node_modules_symlink_outside[WILDCARD]node_modules'. Excluding symlink at '[WILDCARD]node_modules_symlink_outside[WILDCARD]node_modules[WILDCARD]some_folder' with target '[WILDCARD]node_modules_symlink_outside[WILDCARD]some_folder'. |