diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/run_tests.rs | 7 | ||||
-rw-r--r-- | cli/tests/testdata/070_location.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/085_dynamic_import_async_error.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/086_dynamic_import_already_rejected.ts | 8 | ||||
-rw-r--r-- | cli/tests/testdata/error_019_stack_function.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/error_020_stack_constructor.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/error_021_stack_method.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/error_023_stack_async.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/error_024_stack_promise_all.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/resolve_dns.ts | 6 | ||||
-rw-r--r-- | cli/tests/testdata/useUnknownInCatchVariables.ts | 5 | ||||
-rw-r--r-- | cli/tests/testdata/useUnknownInCatchVariables.ts.out | 5 | ||||
-rw-r--r-- | cli/tests/unit/opcall_test.ts | 4 | ||||
-rw-r--r-- | cli/tests/unit/text_encoding_test.ts | 1 | ||||
-rw-r--r-- | cli/tests/unit/write_file_test.ts | 3 |
15 files changed, 56 insertions, 11 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index d4e7ccf72..ec42a8dc8 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -1367,6 +1367,13 @@ itest!(error_import_map_unable_to_load { exit_code: 1, }); +// This test ensure that useUnknownInCatchVariables is enabled by default. +itest!(use_unknown_in_catch_variables { + args: "run useUnknownInCatchVariables.ts", + output: "useUnknownInCatchVariables.ts.out", + exit_code: 1, +}); + // Test that setting `self` in the main thread to some other value doesn't break // the world. itest!(replace_self { diff --git a/cli/tests/testdata/070_location.ts b/cli/tests/testdata/070_location.ts index 61256dcbc..149de5423 100644 --- a/cli/tests/testdata/070_location.ts +++ b/cli/tests/testdata/070_location.ts @@ -4,5 +4,7 @@ console.log(location); try { location.hostname = "bar"; } catch (error) { - console.log(error.toString()); + if (error instanceof Error) { + console.log(error.toString()); + } } diff --git a/cli/tests/testdata/085_dynamic_import_async_error.ts b/cli/tests/testdata/085_dynamic_import_async_error.ts index aa5ff7277..998e7ed3e 100644 --- a/cli/tests/testdata/085_dynamic_import_async_error.ts +++ b/cli/tests/testdata/085_dynamic_import_async_error.ts @@ -1,5 +1,7 @@ try { await import("./delayed_error.ts"); } catch (error) { - console.log(`Caught: ${error.stack}`); + if (error instanceof Error) { + console.log(`Caught: ${error.stack}`); + } } diff --git a/cli/tests/testdata/086_dynamic_import_already_rejected.ts b/cli/tests/testdata/086_dynamic_import_already_rejected.ts index 359db670c..249de8d8b 100644 --- a/cli/tests/testdata/086_dynamic_import_already_rejected.ts +++ b/cli/tests/testdata/086_dynamic_import_already_rejected.ts @@ -1,11 +1,15 @@ try { await import("./error_001.ts"); } catch (error) { - console.log(`Caught: ${error.stack}`); + if (error instanceof Error) { + console.log(`Caught: ${error.stack}`); + } } try { await import("./error_001.ts"); } catch (error) { - console.log(`Caught: ${error.stack}`); + if (error instanceof Error) { + console.log(`Caught: ${error.stack}`); + } } diff --git a/cli/tests/testdata/error_019_stack_function.ts b/cli/tests/testdata/error_019_stack_function.ts index c5eeae8f4..a6a69d146 100644 --- a/cli/tests/testdata/error_019_stack_function.ts +++ b/cli/tests/testdata/error_019_stack_function.ts @@ -5,6 +5,8 @@ function foo(): never { try { foo(); } catch (error) { - console.log(error.stack); + if (error instanceof Error) { + console.log(error.stack); + } throw error; } diff --git a/cli/tests/testdata/error_020_stack_constructor.ts b/cli/tests/testdata/error_020_stack_constructor.ts index 49988280b..526d1a661 100644 --- a/cli/tests/testdata/error_020_stack_constructor.ts +++ b/cli/tests/testdata/error_020_stack_constructor.ts @@ -7,6 +7,8 @@ class A { try { new A(); } catch (error) { - console.log(error.stack); + if (error instanceof Error) { + console.log(error.stack); + } throw error; } diff --git a/cli/tests/testdata/error_021_stack_method.ts b/cli/tests/testdata/error_021_stack_method.ts index a52d00deb..b6ebe1f5e 100644 --- a/cli/tests/testdata/error_021_stack_method.ts +++ b/cli/tests/testdata/error_021_stack_method.ts @@ -7,6 +7,8 @@ class A { try { new A().m(); } catch (error) { - console.log(error.stack); + if (error instanceof Error) { + console.log(error.stack); + } throw error; } diff --git a/cli/tests/testdata/error_023_stack_async.ts b/cli/tests/testdata/error_023_stack_async.ts index 99e676e26..fdabaa5df 100644 --- a/cli/tests/testdata/error_023_stack_async.ts +++ b/cli/tests/testdata/error_023_stack_async.ts @@ -7,6 +7,8 @@ const p = (async () => { try { await p; } catch (error) { - console.log(error.stack); + if (error instanceof Error) { + console.log(error.stack); + } throw error; } diff --git a/cli/tests/testdata/error_024_stack_promise_all.ts b/cli/tests/testdata/error_024_stack_promise_all.ts index ddaf0dbaa..8ca7b203c 100644 --- a/cli/tests/testdata/error_024_stack_promise_all.ts +++ b/cli/tests/testdata/error_024_stack_promise_all.ts @@ -9,6 +9,8 @@ const p = Promise.all([ try { await p; } catch (error) { - console.log(error.stack); + if (error instanceof Error) { + console.log(error.stack); + } throw error; } diff --git a/cli/tests/testdata/resolve_dns.ts b/cli/tests/testdata/resolve_dns.ts index e4a50f7dc..1757c938e 100644 --- a/cli/tests/testdata/resolve_dns.ts +++ b/cli/tests/testdata/resolve_dns.ts @@ -38,5 +38,9 @@ console.log(JSON.stringify(txt)); try { await Deno.resolveDns("not-found-example.com", "A", nameServer); } catch (e) { - console.log(`Error ${e.name} thrown for not-found-example.com`); + console.log( + `Error ${ + e instanceof Error ? e.name : "[non-error]" + } thrown for not-found-example.com`, + ); } diff --git a/cli/tests/testdata/useUnknownInCatchVariables.ts b/cli/tests/testdata/useUnknownInCatchVariables.ts new file mode 100644 index 000000000..abab554a4 --- /dev/null +++ b/cli/tests/testdata/useUnknownInCatchVariables.ts @@ -0,0 +1,5 @@ +try { + throw new Error(); +} catch (e) { + console.log(e.message); +} diff --git a/cli/tests/testdata/useUnknownInCatchVariables.ts.out b/cli/tests/testdata/useUnknownInCatchVariables.ts.out new file mode 100644 index 000000000..3c29d3229 --- /dev/null +++ b/cli/tests/testdata/useUnknownInCatchVariables.ts.out @@ -0,0 +1,5 @@ +[WILDCARD] +error: TS2571 [ERROR]: Object is of type 'unknown'. + console.log(e.message); + ^ + at file://[WILDCARD]/useUnknownInCatchVariables.ts:4:15 diff --git a/cli/tests/unit/opcall_test.ts b/cli/tests/unit/opcall_test.ts index 7e3685320..e38f481d9 100644 --- a/cli/tests/unit/opcall_test.ts +++ b/cli/tests/unit/opcall_test.ts @@ -12,7 +12,9 @@ unitTest(async function sendAsyncStackTrace() { await Deno.read(rid, buf); unreachable(); } catch (error) { - const s = error.stack.toString(); + assert(error instanceof Error); + const s = error.stack?.toString(); + assert(s); console.log(s); assertStringIncludes(s, "opcall_test.ts"); assertStringIncludes(s, "read"); diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts index a65a4176b..d83d84584 100644 --- a/cli/tests/unit/text_encoding_test.ts +++ b/cli/tests/unit/text_encoding_test.ts @@ -98,6 +98,7 @@ unitTest(function textDecoderErrorEncoding() { new TextDecoder("Foo"); } catch (e) { didThrow = true; + assert(e instanceof Error); assertEquals(e.message, "The encoding label provided ('Foo') is invalid."); } assert(didThrow); diff --git a/cli/tests/unit/write_file_test.ts b/cli/tests/unit/write_file_test.ts index 0f99e2749..9ad8da578 100644 --- a/cli/tests/unit/write_file_test.ts +++ b/cli/tests/unit/write_file_test.ts @@ -1,5 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { + assert, assertEquals, assertRejects, assertThrows, @@ -251,6 +252,7 @@ unitTest( try { await Deno.writeFile(filename, data, { signal: ac.signal }); } catch (e) { + assert(e instanceof Error); assertEquals(e.name, "AbortError"); } const stat = Deno.statSync(filename); @@ -269,6 +271,7 @@ unitTest( try { await Deno.writeFile(filename, data, { signal: ac.signal }); } catch (e) { + assert(e instanceof Error); assertEquals(e.name, "AbortError"); } const stat = Deno.statSync(filename); |