diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-02-10 13:22:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-10 20:22:13 +0000 |
commit | f5e46c9bf2f50d66a953fa133161fc829cecff06 (patch) | |
tree | 8faf2f5831c1c7b11d842cd9908d141082c869a5 /tests/integration/eval_tests.rs | |
parent | d2477f780630a812bfd65e3987b70c0d309385bb (diff) |
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
Diffstat (limited to 'tests/integration/eval_tests.rs')
-rw-r--r-- | tests/integration/eval_tests.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/integration/eval_tests.rs b/tests/integration/eval_tests.rs new file mode 100644 index 000000000..1ae65e49e --- /dev/null +++ b/tests/integration/eval_tests.rs @@ -0,0 +1,89 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use test_util as util; + +#[test] +fn eval_p() { + let output = util::deno_cmd() + .arg("eval") + .arg("-p") + .arg("1+2") + .stdout_piped() + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let stdout_str = + util::strip_ansi_codes(std::str::from_utf8(&output.stdout).unwrap().trim()); + assert_eq!("3", stdout_str); +} + +// Make sure that snapshot flags don't affect runtime. +#[test] +fn eval_randomness() { + let mut numbers = Vec::with_capacity(10); + for _ in 0..10 { + let output = util::deno_cmd() + .arg("eval") + .arg("-p") + .arg("Math.random()") + .stdout_piped() + .spawn() + .unwrap() + .wait_with_output() + .unwrap(); + assert!(output.status.success()); + let stdout_str = util::strip_ansi_codes( + std::str::from_utf8(&output.stdout).unwrap().trim(), + ); + numbers.push(stdout_str.to_string()); + } + numbers.dedup(); + assert!(numbers.len() > 1); +} + +itest!(eval_basic { + args: "eval console.log(\"hello\")", + output_str: Some("hello\n"), +}); + +// Ugly parentheses due to whitespace delimiting problem. +itest!(eval_ts { + args: "eval --quiet --ext=ts console.log((123)as(number))", // 'as' is a TS keyword only + output_str: Some("123\n"), +}); + +itest!(dyn_import_eval { + args: "eval import('./subdir/mod4.js').then(console.log)", + output: "eval/dyn_import_eval.out", +}); + +// Cannot write the expression to evaluate as "console.log(typeof gc)" +// because itest! splits args on whitespace. +itest!(v8_flags_eval { + args: "eval --v8-flags=--expose-gc console.log(typeof(gc))", + output: "run/v8_flags.js.out", +}); + +itest!(check_local_by_default { + args: "eval --quiet import('http://localhost:4545/subdir/type_error.ts').then(console.log);", + output: "eval/check_local_by_default.out", + http_server: true, +}); + +itest!(check_local_by_default2 { + args: "eval --quiet import('./eval/check_local_by_default2.ts').then(console.log);", + output: "eval/check_local_by_default2.out", + http_server: true, +}); + +itest!(env_file { + args: "eval --env=env console.log(Deno.env.get(\"ANOTHER_FOO\"))", + output_str: Some("ANOTHER_BAR\n"), +}); + +itest!(env_file_missing { + args: "eval --env=missing console.log(Deno.env.get(\"ANOTHER_FOO\"))", + output: "eval/env_file_missing.out", +}); |