summaryrefslogtreecommitdiff
path: root/cli/cache
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-07-20 16:30:57 -0400
committerGitHub <noreply@github.com>2022-07-20 16:30:57 -0400
commit5f5bbd597ad3454469b3e51a80cd7cb9be39c04d (patch)
tree94fe1ea9df63b9763107bbcccd6fcb7d811a0593 /cli/cache
parentd53936eb7d3fe4cda8e06f7310e4c8f12702b413 (diff)
fix(coverage): do not verify emit source hash for coverage (#15260)
Diffstat (limited to 'cli/cache')
-rw-r--r--cli/cache/emit.rs32
1 files changed, 20 insertions, 12 deletions
diff --git a/cli/cache/emit.rs b/cli/cache/emit.rs
index 61039a966..5260a7fb3 100644
--- a/cli/cache/emit.rs
+++ b/cli/cache/emit.rs
@@ -46,7 +46,7 @@ impl EmitCache {
pub fn get_emit_code(
&self,
specifier: &ModuleSpecifier,
- expected_source_hash: u64,
+ expected_source_hash: Option<u64>,
) -> Option<String> {
let meta_filename = self.get_meta_filename(specifier)?;
let emit_filename = self.get_emit_filename(specifier)?;
@@ -54,11 +54,14 @@ impl EmitCache {
// load and verify the meta data file is for this source and CLI version
let bytes = self.disk_cache.get(&meta_filename).ok()?;
let meta: EmitMetadata = serde_json::from_slice(&bytes).ok()?;
- if meta.source_hash != expected_source_hash.to_string()
- || meta.cli_version != self.cli_version
- {
+ if meta.cli_version != self.cli_version {
return None;
}
+ if let Some(expected_source_hash) = expected_source_hash {
+ if meta.source_hash != expected_source_hash.to_string() {
+ return None;
+ }
+ }
// load and verify the emit is for the meta data
let emit_bytes = self.disk_cache.get(&emit_filename).ok()?;
@@ -171,26 +174,31 @@ mod test {
let specifier2 =
ModuleSpecifier::from_file_path(temp_dir.path().join("file2.ts"))
.unwrap();
- assert_eq!(cache.get_emit_code(&specifier1, 1), None);
+ assert_eq!(cache.get_emit_code(&specifier1, Some(1)), None);
let emit_code1 = "text1".to_string();
let emit_code2 = "text2".to_string();
cache.set_emit_code(&specifier1, 10, &emit_code1);
cache.set_emit_code(&specifier2, 2, &emit_code2);
// providing the incorrect source hash
- assert_eq!(cache.get_emit_code(&specifier1, 5), None);
+ assert_eq!(cache.get_emit_code(&specifier1, Some(5)), None);
// providing the correct source hash
assert_eq!(
- cache.get_emit_code(&specifier1, 10),
+ cache.get_emit_code(&specifier1, Some(10)),
+ Some(emit_code1.clone()),
+ );
+ assert_eq!(cache.get_emit_code(&specifier2, Some(2)), Some(emit_code2));
+ // providing no hash
+ assert_eq!(
+ cache.get_emit_code(&specifier1, None),
Some(emit_code1.clone()),
);
- assert_eq!(cache.get_emit_code(&specifier2, 2), Some(emit_code2),);
// try changing the cli version (should not load previous ones)
let cache = EmitCache {
disk_cache: disk_cache.clone(),
cli_version: "2.0.0".to_string(),
};
- assert_eq!(cache.get_emit_code(&specifier1, 10), None);
+ assert_eq!(cache.get_emit_code(&specifier1, Some(10)), None);
cache.set_emit_code(&specifier1, 5, &emit_code1);
// recreating the cache should still load the data because the CLI version is the same
@@ -198,12 +206,12 @@ mod test {
disk_cache,
cli_version: "2.0.0".to_string(),
};
- assert_eq!(cache.get_emit_code(&specifier1, 5), Some(emit_code1));
+ assert_eq!(cache.get_emit_code(&specifier1, Some(5)), Some(emit_code1));
// adding when already exists should not cause issue
let emit_code3 = "asdf".to_string();
cache.set_emit_code(&specifier1, 20, &emit_code3);
- assert_eq!(cache.get_emit_code(&specifier1, 5), None);
- assert_eq!(cache.get_emit_code(&specifier1, 20), Some(emit_code3));
+ assert_eq!(cache.get_emit_code(&specifier1, Some(5)), None);
+ assert_eq!(cache.get_emit_code(&specifier1, Some(20)), Some(emit_code3));
}
}