From ef3e4a8f74ea65cfed58c1276696f50a8779f816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 22 Sep 2024 23:05:42 +0100 Subject: feat: Show hints when using `window` global (#25805) This commit adds better handling for terminal errors when `window` global is used. This global is removed in Deno 2, and while we have lints to help with that, an information and hints are helpful to guide users to working code. Ref https://github.com/denoland/deno/issues/25797 --- tests/specs/run/window/__test__.jsonc | 19 +++++++++++++++++++ tests/specs/run/window/window1.js | 1 + tests/specs/run/window/window1.out | 7 +++++++ tests/specs/run/window/window2.js | 1 + tests/specs/run/window/window2.out | 7 +++++++ tests/specs/run/window/window3.js | 1 + tests/specs/run/window/window3.out | 7 +++++++ 7 files changed, 43 insertions(+) create mode 100644 tests/specs/run/window/__test__.jsonc create mode 100644 tests/specs/run/window/window1.js create mode 100644 tests/specs/run/window/window1.out create mode 100644 tests/specs/run/window/window2.js create mode 100644 tests/specs/run/window/window2.out create mode 100644 tests/specs/run/window/window3.js create mode 100644 tests/specs/run/window/window3.out (limited to 'tests') diff --git a/tests/specs/run/window/__test__.jsonc b/tests/specs/run/window/__test__.jsonc new file mode 100644 index 000000000..1ee4449b5 --- /dev/null +++ b/tests/specs/run/window/__test__.jsonc @@ -0,0 +1,19 @@ +{ + "tests": { + "window1": { + "args": "run window1.js", + "exitCode": 1, + "output": "window1.out" + }, + "window2": { + "args": "run window2.js", + "exitCode": 1, + "output": "window2.out" + }, + "window3": { + "args": "run window3.js", + "exitCode": 1, + "output": "window3.out" + } + } +} diff --git a/tests/specs/run/window/window1.js b/tests/specs/run/window/window1.js new file mode 100644 index 000000000..a480d4c2c --- /dev/null +++ b/tests/specs/run/window/window1.js @@ -0,0 +1 @@ +"TextEncoder" in window; diff --git a/tests/specs/run/window/window1.out b/tests/specs/run/window/window1.out new file mode 100644 index 000000000..4e1674425 --- /dev/null +++ b/tests/specs/run/window/window1.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: window is not defined +"TextEncoder" in window; + ^ + at [WILDCARD]window1.js:1:18 + + info: window global is not available in Deno 2. + hint: Replace `window` with `globalThis`. diff --git a/tests/specs/run/window/window2.js b/tests/specs/run/window/window2.js new file mode 100644 index 000000000..0fdf5dcb9 --- /dev/null +++ b/tests/specs/run/window/window2.js @@ -0,0 +1 @@ +window.atob; diff --git a/tests/specs/run/window/window2.out b/tests/specs/run/window/window2.out new file mode 100644 index 000000000..7d00cd7ed --- /dev/null +++ b/tests/specs/run/window/window2.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: window is not defined +window.atob; +^ + at [WILDCARD]window2.js:1:1 + + info: window global is not available in Deno 2. + hint: Replace `window` with `globalThis`. diff --git a/tests/specs/run/window/window3.js b/tests/specs/run/window/window3.js new file mode 100644 index 000000000..24fa32b5a --- /dev/null +++ b/tests/specs/run/window/window3.js @@ -0,0 +1 @@ +window.navigator; diff --git a/tests/specs/run/window/window3.out b/tests/specs/run/window/window3.out new file mode 100644 index 000000000..9a157975f --- /dev/null +++ b/tests/specs/run/window/window3.out @@ -0,0 +1,7 @@ +error: Uncaught (in promise) ReferenceError: window is not defined +window.navigator; +^ + at [WILDCARD]window3.js:1:1 + + info: window global is not available in Deno 2. + hint: Replace `window` with `globalThis`. -- cgit v1.2.3