test(cli): improve test of deno cache
@@ -5,7 +5,8 @@ use deno_core::serde_json;
use deno_core::url;
use deno_runtime::deno_fetch::reqwest;
use deno_runtime::deno_websocket::tokio_tungstenite;
-use std::io::{BufRead, Write};
+use std::fs;
+use std::io::{BufRead, Read, Write};
use std::process::Command;
use tempfile::TempDir;
use test_util as util;
@@ -336,14 +337,41 @@ mod integration {
.env("DENO_DIR", deno_dir.path())
.current_dir(util::root_path())
.arg("cache")
+ .arg("-L")
+ .arg("debug")
.arg(module_url.to_string())
.output()
.expect("Failed to spawn script");
assert!(output.status.success());
- let out = std::str::from_utf8(&output.stdout).unwrap();
- assert_eq!(out, "");
- // TODO(ry) Is there some way to check that the file was actually cached in
- // DENO_DIR?
+
+ let out = std::str::from_utf8(&output.stderr).unwrap();
+ // Check if file and dependencies are written successfully
+ assert!(out.contains("host.writeFile(\"deno://subdir/print_hello.js\")"));
+ assert!(out.contains("host.writeFile(\"deno://subdir/mod2.js\")"));
+ assert!(out.contains("host.writeFile(\"deno://006_url_imports.js\")"));
+
+ let prg = util::deno_exe_path();
+ let output = Command::new(&prg)
+ .env("DENO_DIR", deno_dir.path())
+ .env("HTTP_PROXY", "http://nil")
+ .env("NO_COLOR", "1")
+ .current_dir(util::root_path())
+ .arg("run")
+ .arg(module_url.to_string())
+ .output()
+ .expect("Failed to spawn script");
+
+ let str_output = std::str::from_utf8(&output.stdout).unwrap();
+
+ let module_output_path =
+ util::root_path().join("cli/tests/006_url_imports.ts.out");
+ let mut module_output = String::new();
+ let mut module_output_file = fs::File::open(module_output_path).unwrap();
+ module_output_file
+ .read_to_string(&mut module_output)
+ .unwrap();
+
+ assert_eq!(module_output, str_output);
}
#[test]
