diff options
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/check_tests.rs | 102 | ||||
-rw-r--r-- | tests/integration/lsp_tests.rs | 90 | ||||
-rw-r--r-- | tests/integration/run_tests.rs | 80 |
3 files changed, 86 insertions, 186 deletions
diff --git a/tests/integration/check_tests.rs b/tests/integration/check_tests.rs index 78ab859f9..b560b352e 100644 --- a/tests/integration/check_tests.rs +++ b/tests/integration/check_tests.rs @@ -392,105 +392,3 @@ 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); -} diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index e8904942d..cbc175ec6 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -14459,7 +14459,67 @@ fn lsp_sloppy_imports() { }, })); - assert_eq!(json!(diagnostics.all()), json!([])); + assert_eq!( + json!(diagnostics.all()), + json!([{ + "range": { + "start": { "line": 0, "character": 19 }, + "end": { "line": 0, "character": 24 } + }, + "severity": 2, + "code": "no-sloppy-imports", + "source": "deno-lint", + "message": "Sloppy imports are not allowed.", + "data": [{ + "description": "Add a '.ts' extension.", + "changes": [{ + "range": { + "start": { "line": 0, "character": 19 }, + "end": { "line": 0, "character": 24 }, + }, + "new_text": "'./a.ts'" + }] + }] + }, { + "range": { + "start": { "line": 1, "character": 19 }, + "end": { "line": 1, "character": 27 } + }, + "severity": 2, + "code": "no-sloppy-imports", + "source": "deno-lint", + "message": "Sloppy imports are not allowed.", + "data": [{ + "description": "Change the extension to '.ts'.", + "changes": [{ + "range": { + "start": { "line": 1, "character": 19 }, + "end": { "line": 1, "character": 27 }, + }, + "new_text": "'./b.ts'" + }] + }] + }, { + "range": { + "start": { "line": 2, "character": 19 }, + "end": { "line": 2, "character": 27 } + }, + "severity": 2, + "code": "no-sloppy-imports", + "source": "deno-lint", + "message": "Sloppy imports are not allowed.", + "data": [{ + "description": "Change the extension to '.d.ts'.", + "changes": [{ + "range": { + "start": { "line": 2, "character": 19 }, + "end": { "line": 2, "character": 27 }, + }, + "new_text": "'./c.d.ts'" + }] + }] + }]) + ); client.shutdown(); } @@ -14488,11 +14548,33 @@ fn lsp_sloppy_imports_prefers_dts() { "import { foo } from './a.js';\nconsole.log(foo);", ); let diagnostics = client.did_open_file(&file); - // no warnings because "a.js" exists - assert_eq!(diagnostics.all().len(), 0); + // no other warnings because "a.js" exists + assert_eq!( + json!(diagnostics.all()), + json!([{ + "range": { + "start": { "line": 0, "character": 20 }, + "end": { "line": 0, "character": 28 } + }, + "severity": 2, + "code": "no-sloppy-imports", + "source": "deno-lint", + "message": "Sloppy imports are not allowed.", + "data": [{ + "description": "Change the extension to '.d.ts'.", + "changes": [{ + "range": { + "start": { "line": 0, "character": 20 }, + "end": { "line": 0, "character": 28 }, + }, + "new_text": "'./a.d.ts'" + }] + }] + }]) + ); let diagnostics = client.did_open_file(&a_dts); - assert_eq!(diagnostics.all().len(), 0, "Got {:#?}", diagnostics.all()); + assert_eq!(json!(diagnostics.for_file(&a_dts.uri())), json!([])); let response = client.write_request( "textDocument/references", diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 73d98aff5..7a6ee61cf 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -4851,86 +4851,6 @@ itest!(unsafe_proto_flag { exit_code: 0, }); -#[test] -fn test_unstable_sloppy_imports() { - let context = TestContextBuilder::new().use_temp_cwd().build(); - let temp_dir = context.temp_dir(); - temp_dir.write("a.ts", "export class A {}"); - temp_dir.write("b.js", "export class B {}"); - temp_dir.write("c.mts", "export class C {}"); - temp_dir.write("d.mjs", "export class D {}"); - temp_dir.write("e.tsx", "export class E {}"); - temp_dir.write("f.jsx", "export class F {}"); - let dir = temp_dir.path().join("dir"); - dir.create_dir_all(); - dir.join("index.tsx").write("export class G {}"); - temp_dir.write( - "main.ts", - r#"import * as a from "./a.js"; -import * as b from "./b"; -import * as c from "./c"; -import * as d from "./d"; -import * as e from "./e"; -import * as e2 from "./e.js"; -import * as f from "./f"; -import * as g from "./dir"; -console.log(a.A); -console.log(b.B); -console.log(c.C); -console.log(d.D); -console.log(e.E); -console.log(e2.E); -console.log(f.F); -console.log(g.G); -"#, - ); - - // run without sloppy imports - context - .new_command() - .args("run main.ts") - .run() - .assert_matches_text(r#"error: Module not found "file:///[WILDCARD]/a.js". Maybe change the extension to '.ts' or run with --unstable-sloppy-imports - at file:///[WILDCARD]/main.ts:1:20 -"#) - .assert_exit_code(1); - - // now run with sloppy imports - temp_dir.write("deno.json", r#"{ "unstable": ["sloppy-imports"] }"#); - context - .new_command() - .args("run main.ts") - .run() - .assert_matches_text( - "Warning Sloppy imports are not recommended and have a negative impact on performance. -Warning Sloppy module resolution (hint: update .js extension to .ts) - at file:///[WILDCARD]/main.ts:1:20 -Warning Sloppy module resolution (hint: add .js extension) - at file:///[WILDCARD]/main.ts:2:20 -Warning Sloppy module resolution (hint: add .mts extension) - at file:///[WILDCARD]/main.ts:3:20 -Warning Sloppy module resolution (hint: add .mjs extension) - at file:///[WILDCARD]/main.ts:4:20 -Warning Sloppy module resolution (hint: add .tsx extension) - at file:///[WILDCARD]/main.ts:5:20 -Warning Sloppy module resolution (hint: update .js extension to .tsx) - at file:///[WILDCARD]/main.ts:6:21 -Warning Sloppy module resolution (hint: add .jsx extension) - at file:///[WILDCARD]/main.ts:7:20 -Warning Sloppy module resolution (hint: specify path to index.tsx file in directory instead) - at file:///[WILDCARD]/main.ts:8:20 -[class A] -[class B] -[class C] -[class D] -[class E] -[class E] -[class F] -[class G] -", - ); -} - itest!(unstable_temporal_api { args: "run --no-config --unstable-temporal --check run/unstable_temporal_api/main.ts", output: "run/unstable_temporal_api/main.out", |