diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-03-05 19:23:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-06 00:23:51 +0000 |
commit | 3eaf174bfc64b7c277899abd44ae3877538028df (patch) | |
tree | 6a99dfd592681ca4beac81aaa9e5115e3dd801d7 /tests/integration/npm_tests.rs | |
parent | 3fd4b882a4bd0087ebf112615aafc314bb71e594 (diff) |
fix(node): improve cjs tracking (#22673)
We were missing saying that a file is CJS when some Deno code imported
from the node_modules directory at runtime.
Diffstat (limited to 'tests/integration/npm_tests.rs')
-rw-r--r-- | tests/integration/npm_tests.rs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index 33e331fc3..e4e06e830 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -2611,10 +2611,7 @@ fn cjs_rexport_analysis_json() { let dir = test_context.temp_dir(); dir.write("deno.json", r#"{ "unstable": [ "byonm" ] }"#); - dir.write( - "package.json", - r#"{ "name": "test", "packages": { "my-package": "1.0.0" } }"#, - ); + dir.write("package.json", r#"{ "name": "test" }"#); dir.write( "main.js", "import data from 'my-package';\nconsole.log(data);\n", @@ -2670,6 +2667,28 @@ fn cjs_rexport_analysis_json() { ); } +#[test] +fn cjs_export_analysis_import_cjs_directly_relative_import() { + let test_context = TestContextBuilder::for_npm().use_temp_cwd().build(); + let dir = test_context.temp_dir(); + dir.write("deno.json", r#"{ "unstable": [ "byonm" ] }"#); + + dir.write( + "package.json", + r#"{ "name": "test", "dependencies": { "@denotest/cjs-default-export": "1.0.0" } }"#, + ); + // previously it wasn't doing cjs export analysis on this file + dir.write( + "main.ts", + "import { named } from './node_modules/@denotest/cjs-default-export/index.js';\nconsole.log(named());\n", + ); + + test_context.run_npm("install"); + + let output = test_context.new_command().args("run main.ts").run(); + output.assert_matches_text("2\n"); +} + itest!(imports_package_json { args: "run --node-modules-dir=false npm/imports_package_json/main.js", output: "npm/imports_package_json/main.out", |