Skip to content

Commit d0ef531

Browse files
committed
test(cli/tools/installer): install with import maps
1 parent a38bd80 commit d0ef531

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

cli/tools/installer.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,4 +878,42 @@ mod tests {
878878
let status = Command::new(file_path).spawn().unwrap().wait().unwrap();
879879
assert!(status.success());
880880
}
881+
882+
#[test]
883+
fn install_with_import_map() {
884+
let temp_dir = TempDir::new().expect("tempdir fail");
885+
let bin_dir = temp_dir.path().join("bin");
886+
let import_map_path = temp_dir.path().join("import_map.json");
887+
let import_map_url = Url::from_file_path(&import_map_path).unwrap();
888+
let import_map = "{ \"imports\": {} }";
889+
let mut import_map_file = File::create(&import_map_path).unwrap();
890+
let result = import_map_file.write_all(import_map.as_bytes());
891+
assert!(result.is_ok());
892+
893+
let result = install(
894+
Flags {
895+
import_map_path: Some(import_map_path.to_string_lossy().to_string()),
896+
..Flags::default()
897+
},
898+
"http://localhost:4545/cli/tests/cat.ts",
899+
vec![],
900+
Some("echo_test".to_string()),
901+
Some(temp_dir.path().to_path_buf()),
902+
true,
903+
);
904+
assert!(result.is_ok());
905+
906+
let mut file_path = bin_dir.join("echo_test");
907+
if cfg!(windows) {
908+
file_path = file_path.with_extension("cmd");
909+
}
910+
assert!(file_path.exists());
911+
912+
let content = fs::read_to_string(file_path).unwrap();
913+
let expected_string = format!(
914+
"--import-map '{}' 'http://localhost:4545/cli/tests/cat.ts'",
915+
import_map_url.to_string()
916+
);
917+
assert!(content.contains(&expected_string));
918+
}
881919
}

0 commit comments

Comments
 (0)