summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/main.rs68
-rw-r--r--tests/integration/run_tests.rs7
-rw-r--r--tests/specs/run/unstable/__test__.jsonc34
-rw-r--r--tests/specs/run/unstable/broadcast_channel.out7
-rw-r--r--tests/specs/run/unstable/broadcast_channel.ts1
-rw-r--r--tests/specs/run/unstable/cron.out7
-rw-r--r--tests/specs/run/unstable/cron.ts1
-rw-r--r--tests/specs/run/unstable/http.out7
-rw-r--r--tests/specs/run/unstable/http.ts1
-rw-r--r--tests/specs/run/unstable/http_wss.out7
-rw-r--r--tests/specs/run/unstable/http_wss.ts1
-rw-r--r--tests/specs/run/unstable/kv.out7
-rw-r--r--tests/specs/run/unstable/kv.ts1
-rw-r--r--tests/specs/run/unstable/temporal.out7
-rw-r--r--tests/specs/run/unstable/temporal.ts (renamed from tests/testdata/run/unstable_temporal_api/missing_flag.js)0
-rw-r--r--tests/testdata/run/unstable_temporal_api/missing_flag.out4
-rwxr-xr-xtools/lint.js2
17 files changed, 138 insertions, 24 deletions
diff --git a/cli/main.rs b/cli/main.rs
index da274d8ed..c1f0c7910 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -337,17 +337,61 @@ fn exit_with_message(message: &str, code: i32) -> ! {
std::process::exit(code);
}
-fn get_suggestions_for_commonjs_error(e: &JsError) -> Vec<FixSuggestion> {
- if e.name.as_deref() == Some("ReferenceError") {
- if let Some(msg) = &e.message {
- if msg.contains("module is not defined")
- || msg.contains("exports is not defined")
- {
- return vec![
- FixSuggestion::info("Deno does not support CommonJS modules without `.cjs` extension."),
- FixSuggestion::hint("Rewrite this module to ESM or change the file extension to `.cjs`."),
- ];
- }
+fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
+ if let Some(msg) = &e.message {
+ if msg.contains("module is not defined")
+ || msg.contains("exports is not defined")
+ {
+ return vec![
+ FixSuggestion::info(
+ "Deno does not support CommonJS modules without `.cjs` extension.",
+ ),
+ FixSuggestion::hint(
+ "Rewrite this module to ESM or change the file extension to `.cjs`.",
+ ),
+ ];
+ } else if msg.contains("openKv is not a function") {
+ return vec![
+ FixSuggestion::info("Deno.openKv() is an unstable API."),
+ FixSuggestion::hint(
+ "Run again with `--unstable-kv` flag to enable this API.",
+ ),
+ ];
+ } else if msg.contains("cron is not a function") {
+ return vec![
+ FixSuggestion::info("Deno.cron() is an unstable API."),
+ FixSuggestion::hint(
+ "Run again with `--unstable-cron` flag to enable this API.",
+ ),
+ ];
+ } else if msg.contains("createHttpClient is not a function") {
+ return vec![
+ FixSuggestion::info("Deno.createHttpClient() is an unstable API."),
+ FixSuggestion::hint(
+ "Run again with `--unstable-http` flag to enable this API.",
+ ),
+ ];
+ } else if msg.contains("WebSocketStream is not defined") {
+ return vec![
+ FixSuggestion::info("new WebSocketStream() is an unstable API."),
+ FixSuggestion::hint(
+ "Run again with `--unstable-net` flag to enable this API.",
+ ),
+ ];
+ } else if msg.contains("Temporal is not defined") {
+ return vec![
+ FixSuggestion::info("Temporal is an unstable API."),
+ FixSuggestion::hint(
+ "Run again with `--unstable-temporal` flag to enable this API.",
+ ),
+ ];
+ } else if msg.contains("BroadcastChannel is not defined") {
+ return vec![
+ FixSuggestion::info("BroadcastChannel is an unstable API."),
+ FixSuggestion::hint(
+ "Run again with `--unstable-broadcast-channel` flag to enable this API.",
+ ),
+ ];
}
}
@@ -359,7 +403,7 @@ fn exit_for_error(error: AnyError) -> ! {
let mut error_code = 1;
if let Some(e) = error.downcast_ref::<JsError>() {
- let suggestions = get_suggestions_for_commonjs_error(e);
+ let suggestions = get_suggestions_for_terminal_errors(e);
error_string = format_js_error_with_suggestions(e, suggestions);
} else if let Some(SnapshotFromLockfileError::IntegrityCheckFailed(e)) =
error.downcast_ref::<SnapshotFromLockfileError>()
diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs
index 16faba438..301283e85 100644
--- a/tests/integration/run_tests.rs
+++ b/tests/integration/run_tests.rs
@@ -4811,13 +4811,6 @@ itest!(unstable_temporal_api_config_file {
exit_code: 0,
});
-itest!(unstable_temporal_api_missing_flag {
- args: "run --no-config run/unstable_temporal_api/missing_flag.js",
- output: "run/unstable_temporal_api/missing_flag.out",
- http_server: false,
- exit_code: 1,
-});
-
// TODO(bartlomieju): temporary disabled
// itest!(warn_on_deprecated_api {
// args: "run -A run/warn_on_deprecated_api/main.js",
diff --git a/tests/specs/run/unstable/__test__.jsonc b/tests/specs/run/unstable/__test__.jsonc
new file mode 100644
index 000000000..5748c5461
--- /dev/null
+++ b/tests/specs/run/unstable/__test__.jsonc
@@ -0,0 +1,34 @@
+{
+ "tests": {
+ "broadcast_channel": {
+ "args": "run broadcast_channel.ts",
+ "exitCode": 1,
+ "output": "broadcast_channel.out"
+ },
+ "cron": {
+ "args": "run cron.ts",
+ "exitCode": 1,
+ "output": "cron.out"
+ },
+ "http": {
+ "args": "run http.ts",
+ "exitCode": 1,
+ "output": "http.out"
+ },
+ "http_wss": {
+ "args": "run http_wss.ts",
+ "exitCode": 1,
+ "output": "http_wss.out"
+ },
+ "kv": {
+ "args": "run kv.ts",
+ "exitCode": 1,
+ "output": "kv.out"
+ },
+ "temporal": {
+ "args": "run temporal.ts",
+ "exitCode": 1,
+ "output": "temporal.out"
+ }
+ }
+}
diff --git a/tests/specs/run/unstable/broadcast_channel.out b/tests/specs/run/unstable/broadcast_channel.out
new file mode 100644
index 000000000..8a9a09ef2
--- /dev/null
+++ b/tests/specs/run/unstable/broadcast_channel.out
@@ -0,0 +1,7 @@
+error: Uncaught (in promise) ReferenceError: BroadcastChannel is not defined
+new BroadcastChannel("hello");
+^
+ at [WILDCARD]broadcast_channel.ts:1:1
+
+ info: BroadcastChannel is an unstable API.
+ hint: Run again with `--unstable-broadcast-channel` flag to enable this API.
diff --git a/tests/specs/run/unstable/broadcast_channel.ts b/tests/specs/run/unstable/broadcast_channel.ts
new file mode 100644
index 000000000..5fcbc34b5
--- /dev/null
+++ b/tests/specs/run/unstable/broadcast_channel.ts
@@ -0,0 +1 @@
+new BroadcastChannel("hello");
diff --git a/tests/specs/run/unstable/cron.out b/tests/specs/run/unstable/cron.out
new file mode 100644
index 000000000..76558bb38
--- /dev/null
+++ b/tests/specs/run/unstable/cron.out
@@ -0,0 +1,7 @@
+error: Uncaught (in promise) TypeError: Deno.cron is not a function
+Deno.cron();
+ ^
+ at [WILDCARD]cron.ts:1:6
+
+ info: Deno.cron() is an unstable API.
+ hint: Run again with `--unstable-cron` flag to enable this API.
diff --git a/tests/specs/run/unstable/cron.ts b/tests/specs/run/unstable/cron.ts
new file mode 100644
index 000000000..8ec4f21ea
--- /dev/null
+++ b/tests/specs/run/unstable/cron.ts
@@ -0,0 +1 @@
+Deno.cron();
diff --git a/tests/specs/run/unstable/http.out b/tests/specs/run/unstable/http.out
new file mode 100644
index 000000000..55e143c25
--- /dev/null
+++ b/tests/specs/run/unstable/http.out
@@ -0,0 +1,7 @@
+error: Uncaught (in promise) TypeError: Deno.createHttpClient is not a function
+Deno.createHttpClient();
+ ^
+ at [WILDCARD]http.ts:1:6
+
+ info: Deno.createHttpClient() is an unstable API.
+ hint: Run again with `--unstable-http` flag to enable this API.
diff --git a/tests/specs/run/unstable/http.ts b/tests/specs/run/unstable/http.ts
new file mode 100644
index 000000000..568d6a7cc
--- /dev/null
+++ b/tests/specs/run/unstable/http.ts
@@ -0,0 +1 @@
+Deno.createHttpClient();
diff --git a/tests/specs/run/unstable/http_wss.out b/tests/specs/run/unstable/http_wss.out
new file mode 100644
index 000000000..f62deaee8
--- /dev/null
+++ b/tests/specs/run/unstable/http_wss.out
@@ -0,0 +1,7 @@
+error: Uncaught (in promise) ReferenceError: WebSocketStream is not defined
+const wss = new WebSocketStream("ws://127.0.0.1:4513");
+ ^
+ at [WILDCARD]http_wss.ts:1:13
+
+ info: new WebSocketStream() is an unstable API.
+ hint: Run again with `--unstable-net` flag to enable this API.
diff --git a/tests/specs/run/unstable/http_wss.ts b/tests/specs/run/unstable/http_wss.ts
new file mode 100644
index 000000000..f4885f20f
--- /dev/null
+++ b/tests/specs/run/unstable/http_wss.ts
@@ -0,0 +1 @@
+const wss = new WebSocketStream("ws://127.0.0.1:4513");
diff --git a/tests/specs/run/unstable/kv.out b/tests/specs/run/unstable/kv.out
new file mode 100644
index 000000000..d0916604c
--- /dev/null
+++ b/tests/specs/run/unstable/kv.out
@@ -0,0 +1,7 @@
+error: Uncaught (in promise) TypeError: Deno.openKv is not a function
+const db = await Deno.openKv();
+ ^
+ at [WILDCARD]kv.ts:1:23
+
+ info: Deno.openKv() is an unstable API.
+ hint: Run again with `--unstable-kv` flag to enable this API.
diff --git a/tests/specs/run/unstable/kv.ts b/tests/specs/run/unstable/kv.ts
new file mode 100644
index 000000000..591bc3e37
--- /dev/null
+++ b/tests/specs/run/unstable/kv.ts
@@ -0,0 +1 @@
+const db = await Deno.openKv();
diff --git a/tests/specs/run/unstable/temporal.out b/tests/specs/run/unstable/temporal.out
new file mode 100644
index 000000000..f29f9acf8
--- /dev/null
+++ b/tests/specs/run/unstable/temporal.out
@@ -0,0 +1,7 @@
+error: Uncaught (in promise) ReferenceError: Temporal is not defined
+Temporal.Now.instant();
+^
+ at [WILDCARD]temporal.ts:1:1
+
+ info: Temporal is an unstable API.
+ hint: Run again with `--unstable-temporal` flag to enable this API.
diff --git a/tests/testdata/run/unstable_temporal_api/missing_flag.js b/tests/specs/run/unstable/temporal.ts
index 92aed7931..92aed7931 100644
--- a/tests/testdata/run/unstable_temporal_api/missing_flag.js
+++ b/tests/specs/run/unstable/temporal.ts
diff --git a/tests/testdata/run/unstable_temporal_api/missing_flag.out b/tests/testdata/run/unstable_temporal_api/missing_flag.out
deleted file mode 100644
index 8f8e23e70..000000000
--- a/tests/testdata/run/unstable_temporal_api/missing_flag.out
+++ /dev/null
@@ -1,4 +0,0 @@
-error: Uncaught (in promise) ReferenceError: Temporal is not defined
-Temporal.Now.instant();
-^
- at [WILDCARD]missing_flag.js:1:1
diff --git a/tools/lint.js b/tools/lint.js
index e692110fa..74b2c28d3 100755
--- a/tools/lint.js
+++ b/tools/lint.js
@@ -220,7 +220,7 @@ async function ensureNoNewITests() {
"pm_tests.rs": 0,
"publish_tests.rs": 0,
"repl_tests.rs": 0,
- "run_tests.rs": 348,
+ "run_tests.rs": 347,
"shared_library_tests.rs": 0,
"task_tests.rs": 30,
"test_tests.rs": 74,