1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00
denoland-deno/cli/tests/integration/compat_tests.rs
Bartek Iwańczuk f77c5701f7
feat(compat): integrate import map and classic resolutions in ESM resolution (#12549)
This commit integrates import map and "classic" resolutions in
the "--compat" mode when using ES modules; in effect
"http:", "https:" and "blob:" imports now work in compat mode.

The algorithm works as follows:

1. If there's an import map, try to resolve using it and if succeeded
return the specifier
2. Try to resolve using "Node ESM resolution", and if succeeded return
the specifier
3. Fall back to regular ESM resolution
2021-10-28 10:11:38 +02:00

53 lines
1.4 KiB
Rust

// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use crate::itest;
use test_util as util;
itest!(globals {
args: "run --compat --unstable --allow-read --allow-env compat/globals.ts",
output: "compat/globals.out",
});
itest!(fs_promises {
args: "run --compat --unstable -A compat/fs_promises.mjs",
output: "compat/fs_promises.out",
});
itest!(node_prefix_fs_promises {
args: "run --compat --unstable -A compat/node_fs_promises.mjs",
output: "compat/fs_promises.out",
});
itest!(compat_with_import_map_and_https_imports {
args: "run --quiet --compat --unstable -A --import-map=compat/import_map.json compat/import_map_https_imports.mjs",
output: "compat/import_map_https_imports.out",
});
#[test]
fn globals_in_repl() {
let (out, _err) = util::run_and_collect_output_with_args(
true,
vec!["repl", "--compat", "--unstable", "--quiet"],
Some(vec!["global == window"]),
None,
false,
);
assert!(out.contains("true"));
}
#[test]
fn node_compat_url() {
let (out, err) = util::run_and_collect_output_with_args(
false,
vec!["repl", "--compat", "--unstable", "--quiet"],
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"));
}