diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-02-27 13:30:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-27 18:30:21 +0000 |
commit | e9fe71acb53c8856754ef892c463253cb96087ce (patch) | |
tree | dedffed4cbee198a064bd3ff81058f951bf0b401 /tests/integration/check_tests.rs | |
parent | 8d5c2313495014a6af842e21da802e01e11b8e08 (diff) |
fix(unstable): sloppy imports should resolve .d.ts files during types resolution (#22602)
Diffstat (limited to 'tests/integration/check_tests.rs')
-rw-r--r-- | tests/integration/check_tests.rs | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/integration/check_tests.rs b/tests/integration/check_tests.rs index d4d996b00..e97a40141 100644 --- a/tests/integration/check_tests.rs +++ b/tests/integration/check_tests.rs @@ -418,3 +418,105 @@ fn npm_module_check_then_error() { .assert_matches_text("Check [WILDCARD]main.ts\nerror: TS2305[WILDCARD]has no exported member 'oldName'[WILDCARD]") .assert_exit_code(1); } + +#[test] +fn test_unstable_sloppy_imports_dts_files() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let temp_dir = context.temp_dir(); + temp_dir.write("a.ts", "export class A {}"); // resolves this + temp_dir.write("a.d.ts", "export class A2 {}"); + + temp_dir.write("b.js", "export class B {}"); + temp_dir.write("b.d.ts", "export class B2 {}"); // this + + temp_dir.write("c.mts", "export class C {}"); // this + temp_dir.write("c.d.mts", "export class C2 {}"); + + temp_dir.write("d.mjs", "export class D {}"); + temp_dir.write("d.d.mts", "export class D2 {}"); // this + + let temp_dir = temp_dir.path(); + + let dir = temp_dir.join("dir_ts"); + dir.create_dir_all(); + dir.join("index.ts").write("export class Dir {}"); // this + dir.join("index.d.ts").write("export class Dir2 {}"); + + let dir = temp_dir.join("dir_js"); + dir.create_dir_all(); + dir.join("index.js").write("export class Dir {}"); + dir.join("index.d.ts").write("export class Dir2 {}"); // this + + let dir = temp_dir.join("dir_mts"); + dir.create_dir_all(); + dir.join("index.mts").write("export class Dir {}"); // this + dir.join("index.d.ts").write("export class Dir2 {}"); + + let dir = temp_dir.join("dir_mjs"); + dir.create_dir_all(); + dir.join("index.mjs").write("export class Dir {}"); + dir.join("index.d.ts").write("export class Dir2 {}"); // this + + temp_dir.join("main.ts").write( + r#"import * as a from "./a.js"; +import * as b from "./b.js"; +import * as c from "./c.mjs"; +import * as d from "./d.mjs"; + +console.log(a.A); +console.log(b.B2); +console.log(c.C); +console.log(d.D2); + +import * as a2 from "./a"; +import * as b2 from "./b"; +import * as c2 from "./c"; +import * as d2 from "./d"; + +console.log(a2.A); +console.log(b2.B2); +console.log(c2.C); +console.log(d2.D2); + +import * as dirTs from "./dir_ts"; +import * as dirJs from "./dir_js"; +import * as dirMts from "./dir_mts"; +import * as dirMjs from "./dir_mjs"; + +console.log(dirTs.Dir); +console.log(dirJs.Dir2); +console.log(dirMts.Dir); +console.log(dirMjs.Dir2); +"#, + ); + + context + .new_command() + .args("check --unstable-sloppy-imports main.ts") + .run() + .assert_matches_text( + r#"Warning Sloppy module resolution (hint: update .js extension to .ts) + at file:///[WILDCARD]/main.ts:1:20 +Warning Sloppy module resolution (hint: update .mjs extension to .mts) + at file:///[WILDCARD]/main.ts:3:20 +Warning Sloppy module resolution (hint: add .ts extension) + at file:///[WILDCARD]/main.ts:11:21 +Warning Sloppy module resolution (hint: add .js extension) + at file:///[WILDCARD]/main.ts:12:21 +Warning Sloppy module resolution (hint: add .mts extension) + at file:///[WILDCARD]/main.ts:13:21 +Warning Sloppy module resolution (hint: add .mjs extension) + at file:///[WILDCARD]/main.ts:14:21 +Warning Sloppy module resolution (hint: specify path to index.ts file in directory instead) + at file:///[WILDCARD]/main.ts:21:24 +Warning Sloppy module resolution (hint: specify path to index.js file in directory instead) + at file:///[WILDCARD]/main.ts:22:24 +Warning Sloppy module resolution (hint: specify path to index.mts file in directory instead) + at file:///[WILDCARD]/main.ts:23:25 +Warning Sloppy module resolution (hint: specify path to index.mjs file in directory instead) + at file:///[WILDCARD]/main.ts:24:25 +Check [WILDCARD]main.ts +"#, + ) + .assert_exit_code(0); +} |