1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 12:58:54 -05:00

feat(compat): inject Node globals in REPL (#12352)

This commit is contained in:
Bartek Iwańczuk 2021-10-08 17:11:33 +02:00 committed by GitHub
parent 6b43e862fd
commit c49a057599
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View file

@ -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

View file

@ -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",
@ -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"));
}