diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-10 14:46:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-10 14:46:25 -0400 |
commit | a49d0bd10ba2a4745c291f3f413d97396213e4ec (patch) | |
tree | 0c63c25304f465e969d2bcfb8bd71df8575c4033 /tests/integration/lsp_tests.rs | |
parent | 4d2d764816d266e42f3b2251248b100abb667c83 (diff) |
fix(check): CJS types importing dual ESM/CJS package should prefer CJS types (#24492)
Closes #16370
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 d42bff4bd..2e2e00942 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -14501,6 +14501,55 @@ fn lsp_cjs_internal_types_default_export() { } #[test] +fn lsp_cjs_import_dual() { + 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-import-dual": "1" + } +}"#, + ); + context.run_npm("install"); + + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + 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, + // getKind() should resolve as "cjs" and cause a type checker error + "text": "import { getKind } from 'npm:@denotest/cjs-import-dual@1';\nconst kind: 'esm' = getKind(); console.log(kind);", + } + }), + ); + assert_eq!( + json!(diagnostics.all()), + json!([{ + "range": { + "start": { "line": 1, "character": 6, }, + "end": { "line": 1, "character": 10, }, + }, + "severity": 1, + "code": 2322, + "source": "deno-ts", + "message": "Type '\"cjs\"' is not assignable to type '\"esm\"'.", + }]) + ); +} + +#[test] fn lsp_ts_code_fix_any_param() { let context = TestContextBuilder::new().use_temp_cwd().build(); let temp_dir = context.temp_dir(); |