summaryrefslogtreecommitdiff
path: root/cli/tests/integration
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-10-21 11:20:18 -0400
committerGitHub <noreply@github.com>2022-10-21 15:20:18 +0000
commitbcfe279fba865763c87f9cd8d5a2d0b2cbf451be (patch)
tree68e4d1bc52e261df50279f9ecea14795d1c46f6c /cli/tests/integration
parent0e1a71fec6fff5fe62d7e6b2bfffb7ab877d7b71 (diff)
feat(unstable/npm): initial type checking of npm specifiers (#16332)
Diffstat (limited to 'cli/tests/integration')
-rw-r--r--cli/tests/integration/check_tests.rs7
-rw-r--r--cli/tests/integration/lsp_tests.rs194
-rw-r--r--cli/tests/integration/npm_tests.rs49
3 files changed, 237 insertions, 13 deletions
diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs
index ab96670ef..f42cd4a7a 100644
--- a/cli/tests/integration/check_tests.rs
+++ b/cli/tests/integration/check_tests.rs
@@ -50,6 +50,13 @@ itest!(declaration_header_file_with_no_exports {
output_str: Some(""),
});
+itest!(check_npm_install_diagnostics {
+ args: "check --quiet check/npm_install_diagnostics/main.ts",
+ output: "check/npm_install_diagnostics/main.out",
+ envs: vec![("NO_COLOR".to_string(), "1".to_string())],
+ exit_code: 1,
+});
+
#[test]
fn cache_switching_config_then_no_config() {
let deno_dir = util::new_deno_dir();
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 8390b0f6f..9a0d407df 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -3347,6 +3347,37 @@ fn lsp_code_actions_deno_cache() {
}
#[test]
+fn lsp_code_actions_deno_cache_npm() {
+ let mut session = TestSession::from_file("initialize_params.json");
+ let diagnostics = session.did_open(json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import chalk from \"npm:chalk\";\n\nconsole.log(chalk.green);\n"
+ }
+ }));
+ assert_eq!(
+ diagnostics.with_source("deno"),
+ load_fixture_as("code_actions/cache_npm/diagnostics.json")
+ );
+
+ let (maybe_res, maybe_err) = session
+ .client
+ .write_request(
+ "textDocument/codeAction",
+ load_fixture("code_actions/cache_npm/cache_action.json"),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(load_fixture("code_actions/cache_npm/cache_response.json"))
+ );
+ session.shutdown_and_exit();
+}
+
+#[test]
fn lsp_code_actions_imports() {
let mut session = TestSession::from_file("initialize_params.json");
session.did_open(json!({
@@ -4047,6 +4078,169 @@ fn lsp_completions_no_snippet() {
}
#[test]
+fn lsp_completions_npm() {
+ let _g = http_server();
+ let mut client = init("initialize_params.json");
+ did_open(
+ &mut client,
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import cjsDefault from 'npm:@denotest/cjs-default-export';import chalk from 'npm:chalk';\n\n",
+ }
+ }),
+ );
+ let (maybe_res, maybe_err) = client
+ .write_request::<_, _, Value>(
+ "deno/cache",
+ json!({
+ "referrer": {
+ "uri": "file:///a/file.ts",
+ },
+ "uris": [
+ {
+ "uri": "npm:@denotest/cjs-default-export",
+ },
+ {
+ "uri": "npm:chalk",
+ }
+ ]
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert!(maybe_res.is_some());
+
+ // check importing a cjs default import
+ client
+ .write_notification(
+ "textDocument/didChange",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "version": 2
+ },
+ "contentChanges": [
+ {
+ "range": {
+ "start": {
+ "line": 2,
+ "character": 0
+ },
+ "end": {
+ "line": 2,
+ "character": 0
+ }
+ },
+ "text": "cjsDefault."
+ }
+ ]
+ }),
+ )
+ .unwrap();
+ read_diagnostics(&mut client);
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/completion",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts"
+ },
+ "position": {
+ "line": 2,
+ "character": 11
+ },
+ "context": {
+ "triggerKind": 2,
+ "triggerCharacter": "."
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ if let Some(lsp::CompletionResponse::List(list)) = maybe_res {
+ assert!(!list.is_incomplete);
+ assert_eq!(list.items.len(), 3);
+ assert!(list.items.iter().any(|i| i.label == "default"));
+ assert!(list.items.iter().any(|i| i.label == "MyClass"));
+ } else {
+ panic!("unexpected response");
+ }
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "completionItem/resolve",
+ load_fixture("completions/npm/resolve_params.json"),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ assert_eq!(
+ maybe_res,
+ Some(load_fixture("completions/npm/resolve_response.json"))
+ );
+
+ // now check chalk, which is esm
+ client
+ .write_notification(
+ "textDocument/didChange",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts",
+ "version": 3
+ },
+ "contentChanges": [
+ {
+ "range": {
+ "start": {
+ "line": 2,
+ "character": 0
+ },
+ "end": {
+ "line": 2,
+ "character": 11
+ }
+ },
+ "text": "chalk."
+ }
+ ]
+ }),
+ )
+ .unwrap();
+ read_diagnostics(&mut client);
+
+ let (maybe_res, maybe_err) = client
+ .write_request(
+ "textDocument/completion",
+ json!({
+ "textDocument": {
+ "uri": "file:///a/file.ts"
+ },
+ "position": {
+ "line": 2,
+ "character": 6
+ },
+ "context": {
+ "triggerKind": 2,
+ "triggerCharacter": "."
+ }
+ }),
+ )
+ .unwrap();
+ assert!(maybe_err.is_none());
+ if let Some(lsp::CompletionResponse::List(list)) = maybe_res {
+ assert!(!list.is_incomplete);
+ assert!(list.items.iter().any(|i| i.label == "green"));
+ assert!(list.items.iter().any(|i| i.label == "red"));
+ } else {
+ panic!("unexpected response");
+ }
+
+ shutdown(&mut client);
+}
+
+#[test]
fn lsp_completions_registry() {
let _g = http_server();
let mut client = init("initialize_params_registry.json");
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index bc19c613d..9fc817141 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -1,6 +1,5 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-use deno_core::url::Url;
use std::process::Stdio;
use test_util as util;
use util::assert_contains;
@@ -34,7 +33,7 @@ itest!(esm_module_deno_test {
});
itest!(esm_import_cjs_default {
- args: "run --allow-read --allow-env --unstable --quiet npm/esm_import_cjs_default/main.js",
+ args: "run --allow-read --allow-env --unstable --quiet --check=all npm/esm_import_cjs_default/main.ts",
output: "npm/esm_import_cjs_default/main.out",
envs: env_vars(),
http_server: true,
@@ -84,7 +83,7 @@ itest!(translate_cjs_to_esm {
});
itest!(compare_globals {
- args: "run --allow-read --unstable npm/compare_globals/main.js",
+ args: "run --allow-read --unstable --check=all npm/compare_globals/main.ts",
output: "npm/compare_globals/main.out",
envs: env_vars(),
http_server: true,
@@ -210,6 +209,38 @@ itest!(deno_cache {
http_server: true,
});
+itest!(check_all {
+ args: "check --unstable --remote npm/check_errors/main.ts",
+ output: "npm/check_errors/main_all.out",
+ envs: env_vars(),
+ http_server: true,
+ exit_code: 1,
+});
+
+itest!(check_local {
+ args: "check --unstable npm/check_errors/main.ts",
+ output: "npm/check_errors/main_local.out",
+ envs: env_vars(),
+ http_server: true,
+ exit_code: 1,
+});
+
+itest!(types_ambient_module {
+ args: "check --unstable --quiet npm/types_ambient_module/main.ts",
+ output: "npm/types_ambient_module/main.out",
+ envs: env_vars(),
+ http_server: true,
+ exit_code: 1,
+});
+
+itest!(types_ambient_module_import_map {
+ args: "check --unstable --quiet --import-map=npm/types_ambient_module/import_map.json npm/types_ambient_module/main_import_map.ts",
+ output: "npm/types_ambient_module/main_import_map.out",
+ envs: env_vars(),
+ http_server: true,
+ exit_code: 1,
+});
+
#[test]
fn parallel_downloading() {
let (out, _err) = util::run_and_collect_output_with_args(
@@ -672,18 +703,10 @@ fn ensure_registry_files_local() {
}
}
-fn std_file_url() -> String {
- let u = Url::from_directory_path(util::std_path()).unwrap();
- u.to_string()
-}
-
fn env_vars_no_sync_download() -> Vec<(String, String)> {
vec![
- ("DENO_NODE_COMPAT_URL".to_string(), std_file_url()),
- (
- "DENO_NPM_REGISTRY".to_string(),
- "http://localhost:4545/npm/registry/".to_string(),
- ),
+ ("DENO_NODE_COMPAT_URL".to_string(), util::std_file_url()),
+ ("DENO_NPM_REGISTRY".to_string(), util::npm_registry_url()),
("NO_COLOR".to_string(), "1".to_string()),
]
}