diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-04-15 17:50:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-15 17:50:52 -0400 |
commit | 6f278e5c40d101f0fb8e7b69e28d34b1c766a8fe (patch) | |
tree | 97d3edc0f0b527c3dc7f07ba71d5828cd2c77943 /tests/integration/lsp_tests.rs | |
parent | 7e4ee02e2e37db8adfaf4a05aba3819838904650 (diff) |
fix(lsp): improved cjs tracking (#23374)
Our cjs tracking was a bit broken. It was marking stuff as esm that was
actually cjs leading to type checking errors.
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r-- | tests/integration/lsp_tests.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index a3d2cf57e..76d6e22e1 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -12287,3 +12287,52 @@ fn lsp_uses_lockfile_for_npm_initialization() { assert_eq!(skipping_count, 1); client.shutdown(); } + +#[test] +fn lsp_cjs_internal_types_default_export() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .add_npm_env_vars() + .env("DENO_FUTURE", "1") + .build(); + let temp_dir = context.temp_dir(); + temp_dir.write("deno.json", r#"{}"#); + temp_dir.write( + "package.json", + r#"{ + "dependencies": { + "@denotest/cjs-internal-types-default-export": "*" + } +}"#, + ); + context.run_npm("install"); + + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + // this was previously being resolved as ESM and not correctly as CJS + let node_modules_index_d_ts = temp_dir.path().join( + "node_modules/@denotest/cjs-internal-types-default-export/index.d.ts", + ); + client.did_open(json!({ + "textDocument": { + "uri": node_modules_index_d_ts.uri_file(), + "languageId": "typescript", + "version": 1, + "text": node_modules_index_d_ts.read_to_string(), + } + })); + let main_url = temp_dir.path().join("main.ts").uri_file(); + let diagnostics = client.did_open( + json!({ + "textDocument": { + "uri": main_url, + "languageId": "typescript", + "version": 1, + "text": "import * as mod from '@denotest/cjs-internal-types-default-export';\nmod.add(1, 2);", + } + }), + ); + // previously, diagnostic about `add` not being callable + assert_eq!(json!(diagnostics.all()), json!([])); +} |