From 3833d37b15e1e8380efd1a9eea956a8b33745555 Mon Sep 17 00:00:00 2001 From: Naju Mancheril Date: Wed, 20 Apr 2022 08:16:37 -0400 Subject: feat(repl): add "--eval-file" flag to execute a script file on startup (#14247) This commit adds support for "--eval-file" in "deno repl" subcommand. This flag can be used to pass paths or URLs to files, that will be executed on REPL startup. All files will be executed in the same context as the REPL (ie. as "plain old scripts", not ES modules), sharing the global scope. This feature allows to implement custom REPLs on top of Deno's REPL. --- cli/tests/integration/repl_tests.rs | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'cli/tests') diff --git a/cli/tests/integration/repl_tests.rs b/cli/tests/integration/repl_tests.rs index 59acc7dfb..a63be3ece 100644 --- a/cli/tests/integration/repl_tests.rs +++ b/cli/tests/integration/repl_tests.rs @@ -709,3 +709,55 @@ fn eval_flag_runtime_error() { assert!(out.contains("2500")); // should not prevent input assert!(err.is_empty()); } + +#[test] +fn eval_file_flag_valid_input() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--eval-file=./001_hello.js"], + None, + None, + false, + ); + assert!(out.contains("Hello World")); + assert!(err.is_empty()); +} + +#[test] +fn eval_file_flag_call_defined_function() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--eval-file=./tsc/d.ts"], + Some(vec!["v4()"]), + None, + false, + ); + assert!(out.contains("hello")); + assert!(err.is_empty()); +} + +#[test] +fn eval_file_flag_http_input() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--eval-file=http://127.0.0.1:4545/tsc/d.ts"], + Some(vec!["v4()"]), + None, + true, + ); + assert!(out.contains("hello")); + assert!(err.contains("Download")); +} + +#[test] +fn eval_file_flag_multiple_files() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--eval-file=http://127.0.0.1:4545/import_type.ts,./tsc/d.ts,http://127.0.0.1:4545/type_definitions/foo.js"], + Some(vec!["b.method1=v4", "b.method1()+foo.toUpperCase()"]), + None, + true, + ); + assert!(out.contains("helloFOO")); + assert!(err.contains("Download")); +} -- cgit v1.2.3