summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/lsp_tests.rs89
-rw-r--r--cli/tests/integration/run_tests.rs37
-rw-r--r--cli/tests/testdata/run/node_prefix_missing/config.json1
-rw-r--r--cli/tests/testdata/run/node_prefix_missing/import_map.json1
-rw-r--r--cli/tests/testdata/run/node_prefix_missing/main.ts.out_feature_enabled2
5 files changed, 130 insertions, 0 deletions
diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs
index 544164978..85e55ee81 100644
--- a/cli/tests/integration/lsp_tests.rs
+++ b/cli/tests/integration/lsp_tests.rs
@@ -10419,3 +10419,92 @@ fn lsp_vendor_dir() {
client.shutdown();
}
+
+#[test]
+fn lsp_import_unstable_bare_node_builtins_auto_discovered() {
+ let context = TestContextBuilder::new().use_temp_cwd().build();
+ let temp_dir = context.temp_dir();
+
+ let contents = r#"import path from "path";"#;
+ temp_dir.write("main.ts", contents);
+ temp_dir.write("deno.json", r#"{ "unstable": ["bare-node-builtins"] }"#);
+ let main_script = temp_dir.uri().join("main.ts").unwrap();
+
+ let mut client = context.new_lsp_command().capture_stderr().build();
+ client.initialize_default();
+ let diagnostics = client.did_open(json!({
+ "textDocument": {
+ "uri": main_script,
+ "languageId": "typescript",
+ "version": 1,
+ "text": contents,
+ }
+ }));
+
+ let diagnostics = diagnostics
+ .messages_with_file_and_source(main_script.as_ref(), "deno")
+ .diagnostics
+ .into_iter()
+ .filter(|d| {
+ d.code
+ == Some(lsp::NumberOrString::String(
+ "import-node-prefix-missing".to_string(),
+ ))
+ })
+ .collect::<Vec<_>>();
+
+ // get the quick fixes
+ let res = client.write_request(
+ "textDocument/codeAction",
+ json!({
+ "textDocument": {
+ "uri": main_script
+ },
+ "range": {
+ "start": { "line": 0, "character": 16 },
+ "end": { "line": 0, "character": 18 },
+ },
+ "context": {
+ "diagnostics": json!(diagnostics),
+ "only": ["quickfix"]
+ }
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([{
+ "title": "Update specifier to node:path",
+ "kind": "quickfix",
+ "diagnostics": [
+ {
+ "range": {
+ "start": { "line": 0, "character": 17 },
+ "end": { "line": 0, "character": 23 }
+ },
+ "severity": 2,
+ "code": "import-node-prefix-missing",
+ "source": "deno",
+ "message": "\"path\" is resolved to \"node:path\". If you want to use a built-in Node module, add a \"node:\" prefix.",
+ "data": {
+ "specifier": "path"
+ },
+ }
+ ],
+ "edit": {
+ "changes": {
+ main_script: [
+ {
+ "range": {
+ "start": { "line": 0, "character": 17 },
+ "end": { "line": 0, "character": 23 }
+ },
+ "newText": "\"node:path\""
+ }
+ ]
+ }
+ }
+ }])
+ );
+
+ client.shutdown();
+}
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 1dff1f6d6..f70925289 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -4583,6 +4583,43 @@ itest!(node_prefix_missing {
exit_code: 1,
});
+itest!(node_prefix_missing_unstable_bare_node_builtins_enbaled {
+ args: "run --unstable-bare-node-builtins run/node_prefix_missing/main.ts",
+ output: "run/node_prefix_missing/main.ts.out_feature_enabled",
+ envs: env_vars_for_npm_tests(),
+ exit_code: 0,
+});
+
+itest!(
+ node_prefix_missing_unstable_bare_node_builtins_enbaled_by_env {
+ args: "run run/node_prefix_missing/main.ts",
+ output: "run/node_prefix_missing/main.ts.out_feature_enabled",
+ envs: [
+ env_vars_for_npm_tests(),
+ vec![(
+ "DENO_UNSTABLE_BARE_NODE_BUILTINS".to_string(),
+ "1".to_string()
+ )]
+ ]
+ .concat(),
+ exit_code: 0,
+ }
+);
+
+itest!(node_prefix_missing_unstable_bare_node_builtins_enbaled_by_config {
+ args: "run --config=run/node_prefix_missing/config.json run/node_prefix_missing/main.ts",
+ output: "run/node_prefix_missing/main.ts.out_feature_enabled",
+ envs: env_vars_for_npm_tests(),
+ exit_code: 0,
+});
+
+itest!(node_prefix_missing_unstable_bare_node_builtins_enbaled_with_import_map {
+ args: "run --unstable-bare-node-builtins --import-map run/node_prefix_missing/import_map.json run/node_prefix_missing/main.ts",
+ output: "run/node_prefix_missing/main.ts.out_feature_enabled",
+ envs: env_vars_for_npm_tests(),
+ exit_code: 0,
+});
+
itest!(dynamic_import_syntax_error {
args: "run -A run/dynamic_import_syntax_error.js",
output: "run/dynamic_import_syntax_error.js.out",
diff --git a/cli/tests/testdata/run/node_prefix_missing/config.json b/cli/tests/testdata/run/node_prefix_missing/config.json
new file mode 100644
index 000000000..67480c3d4
--- /dev/null
+++ b/cli/tests/testdata/run/node_prefix_missing/config.json
@@ -0,0 +1 @@
+{ "unstable": ["bare-node-builtins"] }
diff --git a/cli/tests/testdata/run/node_prefix_missing/import_map.json b/cli/tests/testdata/run/node_prefix_missing/import_map.json
new file mode 100644
index 000000000..3add7d009
--- /dev/null
+++ b/cli/tests/testdata/run/node_prefix_missing/import_map.json
@@ -0,0 +1 @@
+{ "imports": {} }
diff --git a/cli/tests/testdata/run/node_prefix_missing/main.ts.out_feature_enabled b/cli/tests/testdata/run/node_prefix_missing/main.ts.out_feature_enabled
new file mode 100644
index 000000000..0d8c1e93a
--- /dev/null
+++ b/cli/tests/testdata/run/node_prefix_missing/main.ts.out_feature_enabled
@@ -0,0 +1,2 @@
+[WILDCARD]Warning: Resolving "fs" as "node:fs" at file:///[WILDCARD]/cli/tests/testdata/run/node_prefix_missing/main.ts:1:16. If you want to use a built-in Node module, add a "node:" prefix.
+[Function: writeFile]