From 1117d2db3965fc44f174be3fd029293b7e2b952e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Nov 2021 16:55:10 +0100 Subject: compat: support compat mode in REPL (#12882) This commit introduces "ProcState::maybe_resolver" field, which stores a single instance of resolver for the whole lifetime of the process, instead of creating these resolvers for each creation of module graph. As a result, this resolver can be used in fallback case where graph is not constructed (REPL, loading modules using "require") unifying resolution logic. --- cli/tests/integration/compat_tests.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'cli/tests/integration/compat_tests.rs') diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs index 70c224e31..fdd9813f0 100644 --- a/cli/tests/integration/compat_tests.rs +++ b/cli/tests/integration/compat_tests.rs @@ -46,6 +46,12 @@ itest!(compat_dyn_import_rejects_with_node_compatible_error { envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())], }); +itest!(import_esm_from_cjs { + args: + "run --compat --unstable -A --quiet compat/import_esm_from_cjs/index.js", + output_str: Some("function\n"), +}); + #[test] fn globals_in_repl() { let (out, _err) = util::run_and_collect_output_with_args( @@ -58,6 +64,20 @@ fn globals_in_repl() { assert!(out.contains("true")); } +#[test] +fn require_in_repl() { + let (out, _err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--compat", "--unstable", "--quiet"], + Some(vec![ + "const foo = require('./compat/import_esm_from_cjs/index');", + ]), + None, + false, + ); + assert!(out.contains("function")); +} + #[test] fn node_compat_url() { let (out, err) = util::run_and_collect_output_with_args( -- cgit v1.2.3