diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-12-13 13:53:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-13 13:53:32 +0100 |
commit | 435948e47057a5d8f2ffffebf74b9f84e31770f8 (patch) | |
tree | 2b31cfb0b63b2436bf2d10e5ce867b7ae61a75d9 /cli/tests/repl_tests.rs | |
parent | 5d9bb8b4b042f4d4fbbe61b31a50a26db7f1ae63 (diff) |
feat(repl): support npm packages (#16770)
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/tests/repl_tests.rs')
-rw-r--r-- | cli/tests/repl_tests.rs | 52 |
1 files changed, 52 insertions, 0 deletions
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()); + } + } } |