2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-10-04 19:35:55 -04:00
|
|
|
|
|
|
|
use crate::itest;
|
2021-11-24 06:24:13 -05:00
|
|
|
use deno_core::url::Url;
|
2021-10-08 11:11:33 -04:00
|
|
|
use test_util as util;
|
2021-10-04 19:35:55 -04:00
|
|
|
|
2021-11-24 06:24:13 -05:00
|
|
|
/// Tests in this file should use `std_file_url` to override `DENO_NODE_COMPAT_URL`
|
|
|
|
/// env variable. This speeds up tests significantly as they no longer
|
|
|
|
/// download contents of `deno_std` from `https://deno.land` in each test.
|
|
|
|
|
|
|
|
/// Return a file URL pointing to "std" submodule
|
|
|
|
/// in "test_util" directory. It must have a trailing slash.
|
|
|
|
fn std_file_url() -> String {
|
|
|
|
let u = Url::from_directory_path(util::std_path()).unwrap();
|
|
|
|
u.to_string()
|
|
|
|
}
|
|
|
|
|
2021-10-06 13:07:04 -04:00
|
|
|
itest!(globals {
|
2021-11-24 06:24:13 -05:00
|
|
|
args: "run --compat --no-check --unstable --allow-read --allow-env compat/globals.ts",
|
2021-10-06 13:07:04 -04:00
|
|
|
output: "compat/globals.out",
|
2021-11-24 06:24:13 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-10-06 13:07:04 -04:00
|
|
|
});
|
|
|
|
|
2021-10-04 19:35:55 -04:00
|
|
|
itest!(fs_promises {
|
2021-11-24 06:24:13 -05:00
|
|
|
args: "run --compat --no-check --unstable -A compat/fs_promises.mjs",
|
2021-10-04 19:35:55 -04:00
|
|
|
output: "compat/fs_promises.out",
|
2021-11-24 06:24:13 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-10-04 19:35:55 -04:00
|
|
|
});
|
|
|
|
|
2022-03-15 11:19:59 -04:00
|
|
|
// https://github.com/denoland/deno/issues/12494
|
|
|
|
itest_flaky!(node_prefix_fs_promises {
|
2021-11-24 06:24:13 -05:00
|
|
|
args: "run --compat --no-check --unstable -A compat/node_fs_promises.mjs",
|
2021-10-05 19:25:13 -04:00
|
|
|
output: "compat/fs_promises.out",
|
2021-11-24 06:24:13 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-10-05 19:25:13 -04:00
|
|
|
});
|
|
|
|
|
2021-10-28 04:11:38 -04:00
|
|
|
itest!(compat_with_import_map_and_https_imports {
|
2021-11-24 06:24:13 -05:00
|
|
|
args: "run --quiet --no-check --compat --unstable -A --import-map=compat/import_map.json compat/import_map_https_imports.mjs",
|
2021-10-28 04:11:38 -04:00
|
|
|
output: "compat/import_map_https_imports.out",
|
2021-11-24 06:24:13 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-10-28 04:11:38 -04:00
|
|
|
});
|
|
|
|
|
2021-11-08 02:02:40 -05:00
|
|
|
itest!(compat_dyn_import_rejects_with_node_compatible_error {
|
2021-11-24 06:24:13 -05:00
|
|
|
args:
|
|
|
|
"run --quiet --no-check --compat --unstable -A compat/dyn_import_reject.js",
|
2021-11-08 02:02:40 -05:00
|
|
|
output: "compat/dyn_import_reject.out",
|
2021-11-24 06:24:13 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-11-08 02:02:40 -05:00
|
|
|
});
|
|
|
|
|
2021-11-24 10:55:10 -05:00
|
|
|
itest!(import_esm_from_cjs {
|
|
|
|
args:
|
|
|
|
"run --compat --unstable -A --quiet compat/import_esm_from_cjs/index.js",
|
|
|
|
output_str: Some("function\n"),
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-11-24 10:55:10 -05:00
|
|
|
});
|
|
|
|
|
2021-12-30 11:18:30 -05:00
|
|
|
itest!(test_runner_cjs {
|
|
|
|
args: "test --compat --unstable -A --quiet compat/test_runner/cjs.js",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "compat/test_runner/cjs.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-12-30 11:18:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(test_runner_esm {
|
|
|
|
args: "test --compat --unstable -A --quiet compat/test_runner/esm.mjs",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "compat/test_runner/esm.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-12-30 11:18:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// Top level assertion test mostly just make sure that the test runner finishes correctly on compat mode
|
|
|
|
// when there is no tests
|
|
|
|
itest!(top_level_assertion_cjs {
|
|
|
|
args: "test --compat --unstable -A --quiet compat/test_runner/top_level_assertion_cjs.js",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "compat/test_runner/top_level_assertion_cjs.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-12-30 11:18:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(top_level_assertion_esm {
|
|
|
|
args: "test --compat --unstable -A --quiet compat/test_runner/top_level_assertion_esm.mjs",
|
|
|
|
exit_code: 0,
|
|
|
|
output: "compat/test_runner/top_level_assertion_esm.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-12-30 11:18:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(top_level_fail_cjs {
|
|
|
|
args: "test --compat --unstable -A --quiet compat/test_runner/top_level_fail_cjs.js",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "compat/test_runner/top_level_fail_cjs.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-12-30 11:18:30 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
itest!(top_level_fail_esm {
|
|
|
|
args: "test --compat --unstable -A --quiet compat/test_runner/top_level_fail_esm.mjs",
|
|
|
|
exit_code: 1,
|
|
|
|
output: "compat/test_runner/top_level_fail_esm.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2021-12-30 11:18:30 -05:00
|
|
|
});
|
|
|
|
|
2022-02-11 07:41:56 -05:00
|
|
|
itest!(compat_worker {
|
|
|
|
args: "run --compat --unstable -A --quiet --no-check compat/worker/worker_test.mjs",
|
|
|
|
output: "compat/worker/worker_test.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2022-02-11 07:41:56 -05:00
|
|
|
});
|
|
|
|
|
2022-02-27 08:38:45 -05:00
|
|
|
itest!(cjs_esm_interop {
|
|
|
|
args:
|
|
|
|
"run --compat --unstable -A --quiet --no-check compat/import_cjs_from_esm/main.mjs",
|
|
|
|
output: "compat/import_cjs_from_esm.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2022-02-27 08:38:45 -05:00
|
|
|
});
|
|
|
|
|
2022-03-10 20:33:02 -05:00
|
|
|
itest!(cjs_esm_interop_dynamic {
|
|
|
|
args:
|
|
|
|
"run --compat --unstable -A --quiet --no-check compat/import_cjs_from_esm/main_dynamic.mjs",
|
|
|
|
output: "compat/import_cjs_from_esm.out",
|
2022-03-11 20:08:55 -05:00
|
|
|
envs: vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())],
|
2022-03-10 20:33:02 -05:00
|
|
|
});
|
|
|
|
|
2021-10-08 11:11:33 -04:00
|
|
|
#[test]
|
|
|
|
fn globals_in_repl() {
|
2021-10-11 17:14:46 -04:00
|
|
|
let (out, _err) = util::run_and_collect_output_with_args(
|
2021-10-08 11:11:33 -04:00
|
|
|
true,
|
2021-11-24 06:24:13 -05:00
|
|
|
vec!["repl", "--compat", "--unstable", "--no-check", "--quiet"],
|
2021-10-08 11:11:33 -04:00
|
|
|
Some(vec!["global == window"]),
|
2021-11-24 06:24:13 -05:00
|
|
|
Some(vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())]),
|
2021-10-08 11:11:33 -04:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert!(out.contains("true"));
|
|
|
|
}
|
2021-10-20 18:23:57 -04:00
|
|
|
|
2021-11-24 10:55:10 -05:00
|
|
|
#[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');",
|
|
|
|
]),
|
2022-03-11 20:08:55 -05:00
|
|
|
Some(vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())]),
|
2021-11-24 10:55:10 -05:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert!(out.contains("function"));
|
|
|
|
}
|
|
|
|
|
2021-10-20 18:23:57 -04:00
|
|
|
#[test]
|
|
|
|
fn node_compat_url() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
false,
|
2021-11-24 06:24:13 -05:00
|
|
|
vec!["repl", "--compat", "--unstable", "--no-check", "--quiet"],
|
2021-10-20 18:23:57 -04:00
|
|
|
None,
|
|
|
|
Some(vec![(
|
|
|
|
"DENO_NODE_COMPAT_URL".to_string(),
|
|
|
|
"file:///non_existent/".to_string(),
|
|
|
|
)]),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert!(out.is_empty());
|
|
|
|
assert!(!err.is_empty());
|
|
|
|
assert!(err.contains("file:///non_existent/node/global.ts"));
|
|
|
|
}
|
2022-01-03 14:10:17 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn native_modules_as_global_vars() {
|
|
|
|
let (out, _err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--compat", "--unstable", "--quiet"],
|
|
|
|
Some(vec!["if(cluster && v8 && sys) { true } else { false }"]),
|
2022-03-11 20:08:55 -05:00
|
|
|
Some(vec![("DENO_NODE_COMPAT_URL".to_string(), std_file_url())]),
|
2022-01-03 14:10:17 -05:00
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert!(out.contains("true"));
|
|
|
|
}
|