diff options
author | Luca Casonato <hello@lcas.dev> | 2024-04-30 20:12:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 18:12:35 +0000 |
commit | 6cdf81db7c4a41d036eefc17e41ffb8db0cf54a1 (patch) | |
tree | 6e21e240c12d8fc9856fbc342aab3d986e338e70 /tests | |
parent | 8c3f8ba13605d1c69eba4272179bce5ca0d10fe3 (diff) |
feat(cli): add support for jsxImportSourceTypes (#23419)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'tests')
10 files changed, 157 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs index 2e4b6da30..d000973c0 100644 --- a/tests/integration/lsp_tests.rs +++ b/tests/integration/lsp_tests.rs @@ -10525,6 +10525,10 @@ export function B() { } }) ); + + let diagnostics = client.read_diagnostics(); + println!("{:?}", diagnostics); + client.shutdown(); } @@ -10584,6 +10588,74 @@ fn lsp_jsx_import_source_config_file_automatic_cache() { client.shutdown(); } +#[test] +fn lsp_jsx_import_source_types_pragma() { + let context = TestContextBuilder::new() + .use_http_server() + .use_temp_cwd() + .build(); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + client.did_open(json!({ + "textDocument": { + "uri": "file:///a/file.tsx", + "languageId": "typescriptreact", + "version": 1, + "text": +"/** @jsxImportSource http://localhost:4545/jsx */ +/** @jsxImportSourceTypes http://localhost:4545/jsx-types */ +/** @jsxRuntime automatic */ + +function A() { + return <a>Hello</a>; +} + +export function B() { + return <A></A>; +} +", + } + })); + client.write_request( + "workspace/executeCommand", + json!({ + "command": "deno.cache", + "arguments": [ + [], + "file:///a/file.tsx", + ], + }), + ); + + let diagnostics = client.read_diagnostics(); + assert_eq!(diagnostics.all().len(), 0); + + let res = client.write_request( + "textDocument/hover", + json!({ + "textDocument": { + "uri": "file:///a/file.tsx" + }, + "position": { "line": 0, "character": 25 } + }), + ); + assert_eq!( + res, + json!({ + "contents": { + "kind": "markdown", + "value": "**Resolved Dependency**\n\n**Code**: http​://localhost:4545/jsx/jsx-runtime\n\n**Types**: http​://localhost:4545/jsx-types/jsx-runtime\n", + }, + "range": { + "start": { "line": 0, "character": 21 }, + "end": { "line": 0, "character": 46 } + } + }) + ); + + client.shutdown(); +} + #[derive(Debug, Clone, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] struct TestData { diff --git a/tests/specs/check/jsx_import_source_types/__test__.jsonc b/tests/specs/check/jsx_import_source_types/__test__.jsonc new file mode 100644 index 000000000..4cd2aa423 --- /dev/null +++ b/tests/specs/check/jsx_import_source_types/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "check --all main.tsx", + "output": "main.out" +} diff --git a/tests/specs/check/jsx_import_source_types/main.out b/tests/specs/check/jsx_import_source_types/main.out new file mode 100644 index 000000000..b1fade200 --- /dev/null +++ b/tests/specs/check/jsx_import_source_types/main.out @@ -0,0 +1,3 @@ +Download http://localhost:4545/jsx-types/jsx-runtime +Download http://localhost:4545/jsx-types/jsx-runtime.d.ts +Check file:///[WILDLINE]/main.tsx diff --git a/tests/specs/check/jsx_import_source_types/main.tsx b/tests/specs/check/jsx_import_source_types/main.tsx new file mode 100644 index 000000000..c46ae9d46 --- /dev/null +++ b/tests/specs/check/jsx_import_source_types/main.tsx @@ -0,0 +1,11 @@ +/** @jsxImportSource http://localhost:4545/jsx */ +/** @jsxImportSourceTypes http://localhost:4545/jsx-types */ +/** @jsxRuntime automatic */ + +function A() { + return <a>Hello</a>; +} + +export function B() { + return <A></A>; +} diff --git a/tests/specs/check/jsx_import_source_types_config/__test__.jsonc b/tests/specs/check/jsx_import_source_types_config/__test__.jsonc new file mode 100644 index 000000000..4cd2aa423 --- /dev/null +++ b/tests/specs/check/jsx_import_source_types_config/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "check --all main.tsx", + "output": "main.out" +} diff --git a/tests/specs/check/jsx_import_source_types_config/deno.json b/tests/specs/check/jsx_import_source_types_config/deno.json new file mode 100644 index 000000000..2f5ef6b0d --- /dev/null +++ b/tests/specs/check/jsx_import_source_types_config/deno.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "jsx": "react-jsx", + "jsxImportSource": "http://localhost:4545/jsx", + "jsxImportSourceTypes": "http://localhost:4545/jsx-types" + } +} diff --git a/tests/specs/check/jsx_import_source_types_config/deno.lock b/tests/specs/check/jsx_import_source_types_config/deno.lock new file mode 100644 index 000000000..30d3ed1f7 --- /dev/null +++ b/tests/specs/check/jsx_import_source_types_config/deno.lock @@ -0,0 +1,6 @@ +{ + "version": "3", + "remote": { + "http://localhost:4545/jsx-types/jsx-runtime": "a9bf78bd825e7db35e1932615ea3a8bee5302a9fe7802f58d52859505ac9cf4a" + } +} diff --git a/tests/specs/check/jsx_import_source_types_config/main.out b/tests/specs/check/jsx_import_source_types_config/main.out new file mode 100644 index 000000000..b1fade200 --- /dev/null +++ b/tests/specs/check/jsx_import_source_types_config/main.out @@ -0,0 +1,3 @@ +Download http://localhost:4545/jsx-types/jsx-runtime +Download http://localhost:4545/jsx-types/jsx-runtime.d.ts +Check file:///[WILDLINE]/main.tsx diff --git a/tests/specs/check/jsx_import_source_types_config/main.tsx b/tests/specs/check/jsx_import_source_types_config/main.tsx new file mode 100644 index 000000000..c38572fc3 --- /dev/null +++ b/tests/specs/check/jsx_import_source_types_config/main.tsx @@ -0,0 +1,7 @@ +function A() { + return <a>Hello</a>; +} + +export function B() { + return <A></A>; +} diff --git a/tests/util/server/src/servers/mod.rs b/tests/util/server/src/servers/mod.rs index 18f893a11..38f6d8dfd 100644 --- a/tests/util/server/src/servers/mod.rs +++ b/tests/util/server/src/servers/mod.rs @@ -801,6 +801,46 @@ async fn main_server( ); Ok(res) } + (_, "/jsx-types/jsx-runtime") | (_, "/jsx-types/jsx-dev-runtime") => { + let mut res = Response::new(string_body( + r#" +/// <reference types="./jsx-runtime.d.ts" /> + "#, + )); + res.headers_mut().insert( + "Content-type", + HeaderValue::from_static("application/javascript"), + ); + Ok(res) + } + (_, "/jsx-types/jsx-runtime.d.ts") => { + let mut res = Response::new(string_body( + r#"export function jsx( + _type: "a" | "b", + _props: any, + _key: any, + _source: any, + _self: any, + ): any; + export const jsxs: typeof jsx; + export const jsxDEV: typeof jsx; + export const Fragment: unique symbol; + + declare global { + namespace JSX { + interface IntrinsicElements { + [tagName: string]: Record<string, any>; + } + } + } + "#, + )); + res.headers_mut().insert( + "Content-type", + HeaderValue::from_static("application/typescript"), + ); + Ok(res) + } (_, "/dynamic") => { let mut res = Response::new(string_body( &serde_json::to_string_pretty(&std::time::SystemTime::now()).unwrap(), |