diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index a63be3ece2..05a17d4b73 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -761,3 +761,21 @@ fn eval_file_flag_multiple_files() { assert!(out.contains("helloFOO")); assert!(err.contains("Download")); } + +#[test] +fn pty_clear_function() { + util::with_pty(&["repl"], |mut console| { + console.write_line("console.log('hello');"); + console.write_line("clear();"); + console.write_line("const clear = 1 + 2;"); + console.write_line("clear;"); + console.write_line("close();"); + + let output = console.read_all_output(); + assert!(output.contains("hello")); + assert!(output.contains("[1;1H")); + assert!(output.contains("undefined")); + assert!(output.contains("const clear = 1 + 2;")); + assert!(output.contains('3')); + }); +} diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 57109eb1d0..d72fc94996 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -41,6 +41,8 @@ Object.defineProperty(globalThis, "_error", { console.log("Last thrown error is no longer saved to _error."); }, }); + +globalThis.clear = console.clear.bind(console); "#; pub enum EvaluationOutput {