From 435948e47057a5d8f2ffffebf74b9f84e31770f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 13 Dec 2022 13:53:32 +0100 Subject: feat(repl): support npm packages (#16770) Co-authored-by: David Sherret --- cli/tests/repl_tests.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'cli/tests/repl_tests.rs') diff --git a/cli/tests/repl_tests.rs b/cli/tests/repl_tests.rs index d1af6d844..a5c64f3b6 100644 --- a/cli/tests/repl_tests.rs +++ b/cli/tests/repl_tests.rs @@ -897,4 +897,56 @@ mod repl { assert_ends_with!(out, "\"done\"\n"); assert!(err.is_empty()); } + + #[test] + fn npm_packages() { + let mut env_vars = util::env_vars_for_npm_tests(); + env_vars.push(("NO_COLOR".to_owned(), "1".to_owned())); + + { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--quiet", "--allow-read", "--allow-env"], + Some(vec![ + r#"import chalk from "npm:chalk";"#, + "chalk.red('hel' + 'lo')", + ]), + Some(env_vars.clone()), + true, + ); + + assert_contains!(out, "hello"); + assert!(err.is_empty()); + } + + { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--quiet", "--allow-read", "--allow-env"], + Some(vec![ + r#"const chalk = await import("npm:chalk");"#, + "chalk.default.red('hel' + 'lo')", + ]), + Some(env_vars.clone()), + true, + ); + + assert_contains!(out, "hello"); + assert!(err.is_empty()); + } + + { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--quiet", "--allow-read", "--allow-env"], + Some(vec![r#"export {} from "npm:chalk";"#]), + Some(env_vars), + true, + ); + + assert_contains!(out, "Module {"); + assert_contains!(out, "Chalk: [Function: Chalk],"); + assert!(err.is_empty()); + } + } } -- cgit v1.2.3