diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-04-27 22:36:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 23:36:49 +0200 |
commit | 504482dadd4d8cd9e4105d56ed86802906767f39 (patch) | |
tree | acacb80e50ccfae578822dda63a3ec9e61108d60 /cli/tests/integration/repl_tests.rs | |
parent | 6cd62ea5e969de258b1d308daf5bec91e73e79d3 (diff) |
fix(repl): print unhandled rejections and event errors (#18878)
Fixes #8858.
Fixes #8869.
```
$ target/debug/deno
Deno 1.32.5
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
> Promise.reject(new Error("bar"));
Promise { <rejected> Error: bar
at <anonymous>:2:16 }
Uncaught (in promise) Error: bar
at <anonymous>:2:16
> reportError(new Error("baz"));
undefined
Uncaught Error: baz
at <anonymous>:2:13
>
Diffstat (limited to 'cli/tests/integration/repl_tests.rs')
-rw-r--r-- | cli/tests/integration/repl_tests.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index a473dc200..d9966fe8f 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -784,13 +784,41 @@ fn pty_tab_handler() { } #[test] +fn repl_error() { + util::with_pty(&["repl"], |mut console| { + console.write_line("console.log(1);"); + console.expect_all(&["1", "undefined"]); + console.write_line(r#"throw new Error("foo");"#); + console.expect("Uncaught Error: foo"); + console.expect(" at <anonymous>"); + console.write_line("console.log(2);"); + console.expect("2"); + }); +} + +#[test] +fn repl_reject() { + util::with_pty(&["repl"], |mut console| { + console.write_line("console.log(1);"); + console.expect_all(&["1", "undefined"]); + console.write_line(r#"Promise.reject(new Error("foo"));"#); + console.expect("Promise { <rejected> Error: foo"); + console.expect("Uncaught (in promise) Error: foo"); + console.expect(" at <anonymous>"); + console.write_line("console.log(2);"); + console.expect("2"); + }); +} + +#[test] fn repl_report_error() { util::with_pty(&["repl"], |mut console| { console.write_line("console.log(1);"); console.expect_all(&["1", "undefined"]); - // TODO(nayeemrmn): The REPL should report event errors and rejections. console.write_line(r#"reportError(new Error("foo"));"#); console.expect("undefined"); + console.expect("Uncaught Error: foo"); + console.expect(" at <anonymous>"); console.write_line("console.log(2);"); console.expect("2"); }); |