Skip to content

Commit

Permalink
feat(compat): inject Node globals in REPL (denoland#12352)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Oct 8, 2021
1 parent 6b43e86 commit c49a057
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,14 @@ async fn format_command(
async fn run_repl(flags: Flags, repl_flags: ReplFlags) -> Result<(), AnyError> {
let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap();
let permissions = Permissions::from_options(&flags.clone().into());
let ps = ProcState::build(flags).await?;
let ps = ProcState::build(flags.clone()).await?;
let mut worker =
create_main_worker(&ps, main_module.clone(), permissions, None);
if flags.compat {
worker
.execute_side_module(&compat::get_node_globals_url())
.await?;
}
worker.run_event_loop(false).await?;

tools::repl::run(&ps, worker, repl_flags.eval).await
Expand Down
14 changes: 14 additions & 0 deletions cli/tests/integration/compat_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

use crate::itest;
use test_util as util;

itest!(globals {
args: "run --compat --unstable --allow-read --allow-env compat/globals.ts",
Expand All @@ -22,3 +23,16 @@ itest!(existing_import_map {
output: "compat/existing_import_map.out",
exit_code: 1,
});

#[test]
fn globals_in_repl() {
let (out, err) = util::run_and_collect_output_with_args(
true,
vec!["repl", "--compat", "--unstable", "--quiet"],
Some(vec!["global == window"]),
None,
false,
);
assert!(out.contains("true"));
assert!(err.contains("Implicitly using latest version"));
}

0 comments on commit c49a057

Please sign in to comment.