mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
fix(coverage): do not verify emit source hash for coverage (#15260)
This commit is contained in:
parent
d53936eb7d
commit
5f5bbd597a
3 changed files with 22 additions and 17 deletions
32
cli/cache/emit.rs
vendored
32
cli/cache/emit.rs
vendored
|
@ -46,7 +46,7 @@ impl EmitCache {
|
||||||
pub fn get_emit_code(
|
pub fn get_emit_code(
|
||||||
&self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
expected_source_hash: u64,
|
expected_source_hash: Option<u64>,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let meta_filename = self.get_meta_filename(specifier)?;
|
let meta_filename = self.get_meta_filename(specifier)?;
|
||||||
let emit_filename = self.get_emit_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
|
// load and verify the meta data file is for this source and CLI version
|
||||||
let bytes = self.disk_cache.get(&meta_filename).ok()?;
|
let bytes = self.disk_cache.get(&meta_filename).ok()?;
|
||||||
let meta: EmitMetadata = serde_json::from_slice(&bytes).ok()?;
|
let meta: EmitMetadata = serde_json::from_slice(&bytes).ok()?;
|
||||||
if meta.source_hash != expected_source_hash.to_string()
|
if meta.cli_version != self.cli_version {
|
||||||
|| meta.cli_version != self.cli_version
|
|
||||||
{
|
|
||||||
return None;
|
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
|
// load and verify the emit is for the meta data
|
||||||
let emit_bytes = self.disk_cache.get(&emit_filename).ok()?;
|
let emit_bytes = self.disk_cache.get(&emit_filename).ok()?;
|
||||||
|
@ -171,26 +174,31 @@ mod test {
|
||||||
let specifier2 =
|
let specifier2 =
|
||||||
ModuleSpecifier::from_file_path(temp_dir.path().join("file2.ts"))
|
ModuleSpecifier::from_file_path(temp_dir.path().join("file2.ts"))
|
||||||
.unwrap();
|
.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_code1 = "text1".to_string();
|
||||||
let emit_code2 = "text2".to_string();
|
let emit_code2 = "text2".to_string();
|
||||||
cache.set_emit_code(&specifier1, 10, &emit_code1);
|
cache.set_emit_code(&specifier1, 10, &emit_code1);
|
||||||
cache.set_emit_code(&specifier2, 2, &emit_code2);
|
cache.set_emit_code(&specifier2, 2, &emit_code2);
|
||||||
// providing the incorrect source hash
|
// 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
|
// providing the correct source hash
|
||||||
assert_eq!(
|
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()),
|
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)
|
// try changing the cli version (should not load previous ones)
|
||||||
let cache = EmitCache {
|
let cache = EmitCache {
|
||||||
disk_cache: disk_cache.clone(),
|
disk_cache: disk_cache.clone(),
|
||||||
cli_version: "2.0.0".to_string(),
|
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);
|
cache.set_emit_code(&specifier1, 5, &emit_code1);
|
||||||
|
|
||||||
// recreating the cache should still load the data because the CLI version is the same
|
// recreating the cache should still load the data because the CLI version is the same
|
||||||
|
@ -198,12 +206,12 @@ mod test {
|
||||||
disk_cache,
|
disk_cache,
|
||||||
cli_version: "2.0.0".to_string(),
|
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
|
// adding when already exists should not cause issue
|
||||||
let emit_code3 = "asdf".to_string();
|
let emit_code3 = "asdf".to_string();
|
||||||
cache.set_emit_code(&specifier1, 20, &emit_code3);
|
cache.set_emit_code(&specifier1, 20, &emit_code3);
|
||||||
assert_eq!(cache.get_emit_code(&specifier1, 5), None);
|
assert_eq!(cache.get_emit_code(&specifier1, Some(5)), None);
|
||||||
assert_eq!(cache.get_emit_code(&specifier1, 20), Some(emit_code3));
|
assert_eq!(cache.get_emit_code(&specifier1, Some(20)), Some(emit_code3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,7 +249,7 @@ pub fn emit_parsed_source(
|
||||||
let source_hash =
|
let source_hash =
|
||||||
get_source_hash(parsed_source.text_info().text_str(), emit_config_hash);
|
get_source_hash(parsed_source.text_info().text_str(), emit_config_hash);
|
||||||
|
|
||||||
if let Some(emit_code) = cache.get_emit_code(specifier, source_hash) {
|
if let Some(emit_code) = cache.get_emit_code(specifier, Some(source_hash)) {
|
||||||
Ok(emit_code)
|
Ok(emit_code)
|
||||||
} else {
|
} else {
|
||||||
let transpiled_source = parsed_source.transpile(emit_options)?;
|
let transpiled_source = parsed_source.transpile(emit_options)?;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use crate::args::CoverageFlags;
|
use crate::args::CoverageFlags;
|
||||||
use crate::args::Flags;
|
use crate::args::Flags;
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::emit::get_source_hash;
|
|
||||||
use crate::fs_util::collect_files;
|
use crate::fs_util::collect_files;
|
||||||
use crate::proc_state::ProcState;
|
use crate::proc_state::ProcState;
|
||||||
use crate::text_encoding::source_map_from_code;
|
use crate::text_encoding::source_map_from_code;
|
||||||
|
@ -678,9 +677,7 @@ pub async fn cover_files(
|
||||||
| MediaType::Mts
|
| MediaType::Mts
|
||||||
| MediaType::Cts
|
| MediaType::Cts
|
||||||
| MediaType::Tsx => {
|
| MediaType::Tsx => {
|
||||||
let source_hash =
|
match ps.emit_cache.get_emit_code(&file.specifier, None) {
|
||||||
get_source_hash(original_source, ps.emit_options_hash);
|
|
||||||
match ps.emit_cache.get_emit_code(&file.specifier, source_hash) {
|
|
||||||
Some(code) => code,
|
Some(code) => code,
|
||||||
None => {
|
None => {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
|
|
Loading…
Reference in a new issue