summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/compiler_api_test.ts50
-rw-r--r--cli/tests/config_types.ts1
-rw-r--r--cli/tests/config_types.ts.out1
-rw-r--r--cli/tests/config_types.tsconfig.json7
-rw-r--r--cli/tests/config_types_remote.tsconfig.json7
-rw-r--r--cli/tests/integration_tests.rs25
-rw-r--r--cli/tests/integration_tests_lsp.rs85
-rw-r--r--cli/tests/lsp/a.d.ts1
-rw-r--r--cli/tests/lsp/b.d.ts1
-rw-r--r--cli/tests/lsp/types.tsconfig.json7
-rw-r--r--cli/tests/reference_types.ts3
-rw-r--r--cli/tests/reference_types.ts.out1
-rw-r--r--cli/tests/reference_types_remote.ts3
-rw-r--r--cli/tests/reference_types_remote.ts.out1
-rw-r--r--cli/tests/subdir/types.d.ts1
15 files changed, 193 insertions, 1 deletions
diff --git a/cli/tests/compiler_api_test.ts b/cli/tests/compiler_api_test.ts
index 00116e7e1..b9a08d5ca 100644
--- a/cli/tests/compiler_api_test.ts
+++ b/cli/tests/compiler_api_test.ts
@@ -93,6 +93,56 @@ Deno.test({
});
Deno.test({
+ name: "Deno.emit() - type references can be loaded",
+ async fn() {
+ const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
+ "file:///a.ts",
+ {
+ sources: {
+ "file:///a.ts": `/// <reference types="./b.d.ts" />
+ const b = new B();
+ console.log(b.b);`,
+ "file:///b.d.ts": `declare class B {
+ b: string;
+ }`,
+ },
+ },
+ );
+ assertEquals(diagnostics.length, 0);
+ assert(!ignoredOptions);
+ assertEquals(stats.length, 12);
+ const keys = Object.keys(files).sort();
+ assertEquals(keys, ["file:///a.ts.js", "file:///a.ts.js.map"]);
+ },
+});
+
+Deno.test({
+ name: "Deno.emit() - compilerOptions.types",
+ async fn() {
+ const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
+ "file:///a.ts",
+ {
+ compilerOptions: {
+ types: ["file:///b.d.ts"],
+ },
+ sources: {
+ "file:///a.ts": `const b = new B();
+ console.log(b.b);`,
+ "file:///b.d.ts": `declare class B {
+ b: string;
+ }`,
+ },
+ },
+ );
+ assertEquals(diagnostics.length, 0);
+ assert(!ignoredOptions);
+ assertEquals(stats.length, 12);
+ const keys = Object.keys(files).sort();
+ assertEquals(keys, ["file:///a.ts.js", "file:///a.ts.js.map"]);
+ },
+});
+
+Deno.test({
name: "Deno.emit() - import maps",
async fn() {
const { diagnostics, files, ignoredOptions, stats } = await Deno.emit(
diff --git a/cli/tests/config_types.ts b/cli/tests/config_types.ts
new file mode 100644
index 000000000..f1a8d6583
--- /dev/null
+++ b/cli/tests/config_types.ts
@@ -0,0 +1 @@
+console.log(globalThis.a);
diff --git a/cli/tests/config_types.ts.out b/cli/tests/config_types.ts.out
new file mode 100644
index 000000000..417b7b537
--- /dev/null
+++ b/cli/tests/config_types.ts.out
@@ -0,0 +1 @@
+undefined
diff --git a/cli/tests/config_types.tsconfig.json b/cli/tests/config_types.tsconfig.json
new file mode 100644
index 000000000..3810d4534
--- /dev/null
+++ b/cli/tests/config_types.tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "compilerOptions": {
+ "types": [
+ "./subdir/types.d.ts"
+ ]
+ }
+}
diff --git a/cli/tests/config_types_remote.tsconfig.json b/cli/tests/config_types_remote.tsconfig.json
new file mode 100644
index 000000000..745bb7b20
--- /dev/null
+++ b/cli/tests/config_types_remote.tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "compilerOptions": {
+ "types": [
+ "http://localhost:4545/cli/tests/subdir/types.d.ts"
+ ]
+ }
+}
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 081ea40e5..af3c9167c 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -3421,7 +3421,19 @@ console.log("finish");
output: "config.ts.out",
});
- itest!(emtpy_typescript {
+ itest!(config_types {
+ args:
+ "run --reload --quiet --config config_types.tsconfig.json config_types.ts",
+ output: "config_types.ts.out",
+ });
+
+ itest!(config_types_remote {
+ http_server: true,
+ args: "run --reload --quiet --config config_types_remote.tsconfig.json config_types.ts",
+ output: "config_types.ts.out",
+ });
+
+ itest!(empty_typescript {
args: "run --reload subdir/empty.ts",
output_str: Some("Check file:[WILDCARD]tests/subdir/empty.ts\n"),
});
@@ -4123,6 +4135,17 @@ console.log("finish");
output: "redirect_cache.out",
});
+ itest!(reference_types {
+ args: "run --reload --quiet reference_types.ts",
+ output: "reference_types.ts.out",
+ });
+
+ itest!(references_types_remote {
+ http_server: true,
+ args: "run --reload --quiet reference_types_remote.ts",
+ output: "reference_types_remote.ts.out",
+ });
+
itest!(deno_doc_types_header_direct {
args: "doc --reload http://127.0.0.1:4545/xTypeScriptTypes.js",
output: "doc/types_header.out",
diff --git a/cli/tests/integration_tests_lsp.rs b/cli/tests/integration_tests_lsp.rs
index afc93764a..04c66625c 100644
--- a/cli/tests/integration_tests_lsp.rs
+++ b/cli/tests/integration_tests_lsp.rs
@@ -21,6 +21,12 @@ fn load_fixture(path: &str) -> Value {
serde_json::from_str(&fixture_str).unwrap()
}
+fn load_fixture_str(path: &str) -> String {
+ let fixtures_path = root_path().join("cli/tests/lsp");
+ let path = fixtures_path.join(path);
+ fs::read_to_string(path).unwrap()
+}
+
fn init(init_path: &str) -> LspClient {
let deno_exe = deno_exe_path();
let mut client = LspClient::new(&deno_exe).unwrap();
@@ -123,6 +129,85 @@ fn lsp_init_tsconfig() {
}
#[test]
+fn lsp_tsconfig_types() {
+ let mut params: lsp::InitializeParams =
+ serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
+ let temp_dir = TempDir::new().expect("could not create temp dir");
+ let tsconfig =
+ serde_json::to_vec_pretty(&load_fixture("types.tsconfig.json")).unwrap();
+ fs::write(temp_dir.path().join("types.tsconfig.json"), tsconfig).unwrap();
+ let a_dts = load_fixture_str("a.d.ts");
+ fs::write(temp_dir.path().join("a.d.ts"), a_dts).unwrap();
+
+ params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap());
+ if let Some(Value::Object(mut map)) = params.initialization_options {
+ map.insert("config".to_string(), json!("./types.tsconfig.json"));
+ params.initialization_options = Some(Value::Object(map));
+ }
+
+ let deno_exe = deno_exe_path();
+ let mut client = LspClient::new(&deno_exe).unwrap();
+ client
+ .write_request::<_, _, Value>("initialize", params)
+ .unwrap();
+
+ client.write_notification("initialized", json!({})).unwrap();
+
+ let diagnostics = did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": Url::from_file_path(temp_dir.path().join("test.ts")).unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "console.log(a);\n"
+ }
+ }),
+ );
+
+ let diagnostics = diagnostics.into_iter().flat_map(|x| x.diagnostics);
+ assert_eq!(diagnostics.count(), 0);
+
+ shutdown(&mut client);
+}
+
+#[test]
+fn lsp_triple_slash_types() {
+ let mut params: lsp::InitializeParams =
+ serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
+ let temp_dir = TempDir::new().expect("could not create temp dir");
+ let a_dts = load_fixture_str("a.d.ts");
+ fs::write(temp_dir.path().join("a.d.ts"), a_dts).unwrap();
+
+ params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap());
+
+ let deno_exe = deno_exe_path();
+ let mut client = LspClient::new(&deno_exe).unwrap();
+ client
+ .write_request::<_, _, Value>("initialize", params)
+ .unwrap();
+
+ client.write_notification("initialized", json!({})).unwrap();
+
+ let diagnostics = did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": Url::from_file_path(temp_dir.path().join("test.ts")).unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "/// <reference types=\"./a.d.ts\" />\n\nconsole.log(a);\n"
+ }
+ }),
+ );
+
+ let diagnostics = diagnostics.into_iter().flat_map(|x| x.diagnostics);
+ assert_eq!(diagnostics.count(), 0);
+
+ shutdown(&mut client);
+}
+
+#[test]
fn lsp_hover() {
let mut client = init("initialize_params.json");
did_open(
diff --git a/cli/tests/lsp/a.d.ts b/cli/tests/lsp/a.d.ts
new file mode 100644
index 000000000..7f587e144
--- /dev/null
+++ b/cli/tests/lsp/a.d.ts
@@ -0,0 +1 @@
+declare var a: string;
diff --git a/cli/tests/lsp/b.d.ts b/cli/tests/lsp/b.d.ts
new file mode 100644
index 000000000..9d4b96cb8
--- /dev/null
+++ b/cli/tests/lsp/b.d.ts
@@ -0,0 +1 @@
+declare var b: string;
diff --git a/cli/tests/lsp/types.tsconfig.json b/cli/tests/lsp/types.tsconfig.json
new file mode 100644
index 000000000..ba7f3344d
--- /dev/null
+++ b/cli/tests/lsp/types.tsconfig.json
@@ -0,0 +1,7 @@
+{
+ "compilerOptions": {
+ "types": [
+ "./a.d.ts"
+ ]
+ }
+}
diff --git a/cli/tests/reference_types.ts b/cli/tests/reference_types.ts
new file mode 100644
index 000000000..105e23b37
--- /dev/null
+++ b/cli/tests/reference_types.ts
@@ -0,0 +1,3 @@
+/// <reference types="./subdir/types.d.ts" />
+
+console.log(globalThis.a);
diff --git a/cli/tests/reference_types.ts.out b/cli/tests/reference_types.ts.out
new file mode 100644
index 000000000..417b7b537
--- /dev/null
+++ b/cli/tests/reference_types.ts.out
@@ -0,0 +1 @@
+undefined
diff --git a/cli/tests/reference_types_remote.ts b/cli/tests/reference_types_remote.ts
new file mode 100644
index 000000000..2e7a80098
--- /dev/null
+++ b/cli/tests/reference_types_remote.ts
@@ -0,0 +1,3 @@
+/// <reference types="http://localhost:4545/cli/tests/subdir/types.d.ts" />
+
+console.log(globalThis.a);
diff --git a/cli/tests/reference_types_remote.ts.out b/cli/tests/reference_types_remote.ts.out
new file mode 100644
index 000000000..417b7b537
--- /dev/null
+++ b/cli/tests/reference_types_remote.ts.out
@@ -0,0 +1 @@
+undefined
diff --git a/cli/tests/subdir/types.d.ts b/cli/tests/subdir/types.d.ts
new file mode 100644
index 000000000..7f587e144
--- /dev/null
+++ b/cli/tests/subdir/types.d.ts
@@ -0,0 +1 @@
+declare var a: string;