mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
chore: fix flaky test_include_dir_recursive (#19291)
Maybe fixes this on main.
This commit is contained in:
parent
a96844118c
commit
d43e75cbb2
2 changed files with 26 additions and 17 deletions
|
@ -536,7 +536,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
||||||
|
|
||||||
fn build_vfs(&self) -> Result<VfsBuilder, AnyError> {
|
fn build_vfs(&self) -> Result<VfsBuilder, AnyError> {
|
||||||
if let Some(node_modules_path) = self.npm_resolver.node_modules_path() {
|
if let Some(node_modules_path) = self.npm_resolver.node_modules_path() {
|
||||||
let mut builder = VfsBuilder::new(node_modules_path.clone());
|
let mut builder = VfsBuilder::new(node_modules_path.clone())?;
|
||||||
builder.add_dir_recursive(&node_modules_path)?;
|
builder.add_dir_recursive(&node_modules_path)?;
|
||||||
Ok(builder)
|
Ok(builder)
|
||||||
} else {
|
} else {
|
||||||
|
@ -544,7 +544,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
||||||
// but also don't make this dependent on the registry url
|
// but also don't make this dependent on the registry url
|
||||||
let registry_url = self.npm_api.base_url();
|
let registry_url = self.npm_api.base_url();
|
||||||
let root_path = self.npm_cache.registry_folder(registry_url);
|
let root_path = self.npm_cache.registry_folder(registry_url);
|
||||||
let mut builder = VfsBuilder::new(root_path);
|
let mut builder = VfsBuilder::new(root_path)?;
|
||||||
for package in self
|
for package in self
|
||||||
.npm_resolution
|
.npm_resolution
|
||||||
.all_system_packages(&self.npm_system_info)
|
.all_system_packages(&self.npm_system_info)
|
||||||
|
|
|
@ -27,6 +27,7 @@ use serde::Serialize;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
use crate::util::fs::canonicalize_path;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
#[error(
|
#[error(
|
||||||
|
@ -46,9 +47,10 @@ pub struct VfsBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VfsBuilder {
|
impl VfsBuilder {
|
||||||
pub fn new(root_path: PathBuf) -> Self {
|
pub fn new(root_path: PathBuf) -> Result<Self, AnyError> {
|
||||||
|
let root_path = canonicalize_path(&root_path)?;
|
||||||
log::debug!("Building vfs with root '{}'", root_path.display());
|
log::debug!("Building vfs with root '{}'", root_path.display());
|
||||||
Self {
|
Ok(Self {
|
||||||
root_dir: VirtualDirectory {
|
root_dir: VirtualDirectory {
|
||||||
name: root_path
|
name: root_path
|
||||||
.file_stem()
|
.file_stem()
|
||||||
|
@ -61,7 +63,7 @@ impl VfsBuilder {
|
||||||
files: Vec::new(),
|
files: Vec::new(),
|
||||||
current_offset: 0,
|
current_offset: 0,
|
||||||
file_offsets: Default::default(),
|
file_offsets: Default::default(),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_root_dir_name(&mut self, name: String) {
|
pub fn set_root_dir_name(&mut self, name: String) {
|
||||||
|
@ -69,6 +71,14 @@ impl VfsBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_dir_recursive(&mut self, path: &Path) -> Result<(), AnyError> {
|
pub fn add_dir_recursive(&mut self, path: &Path) -> Result<(), AnyError> {
|
||||||
|
let path = canonicalize_path(path)?;
|
||||||
|
self.add_dir_recursive_internal(&path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_dir_recursive_internal(
|
||||||
|
&mut self,
|
||||||
|
path: &Path,
|
||||||
|
) -> Result<(), AnyError> {
|
||||||
self.add_dir(path)?;
|
self.add_dir(path)?;
|
||||||
let read_dir = std::fs::read_dir(path)
|
let read_dir = std::fs::read_dir(path)
|
||||||
.with_context(|| format!("Reading {}", path.display()))?;
|
.with_context(|| format!("Reading {}", path.display()))?;
|
||||||
|
@ -79,7 +89,7 @@ impl VfsBuilder {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
if file_type.is_dir() {
|
if file_type.is_dir() {
|
||||||
self.add_dir_recursive(&path)?;
|
self.add_dir_recursive_internal(&path)?;
|
||||||
} else if file_type.is_file() {
|
} else if file_type.is_file() {
|
||||||
let file_bytes = std::fs::read(&path)
|
let file_bytes = std::fs::read(&path)
|
||||||
.with_context(|| format!("Reading {}", path.display()))?;
|
.with_context(|| format!("Reading {}", path.display()))?;
|
||||||
|
@ -115,7 +125,7 @@ impl VfsBuilder {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_dir(
|
fn add_dir(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> Result<&mut VirtualDirectory, StripRootError> {
|
) -> Result<&mut VirtualDirectory, StripRootError> {
|
||||||
|
@ -152,11 +162,7 @@ impl VfsBuilder {
|
||||||
Ok(current_dir)
|
Ok(current_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_file(
|
fn add_file(&mut self, path: &Path, data: Vec<u8>) -> Result<(), AnyError> {
|
||||||
&mut self,
|
|
||||||
path: &Path,
|
|
||||||
data: Vec<u8>,
|
|
||||||
) -> Result<(), AnyError> {
|
|
||||||
log::debug!("Adding file '{}'", path.display());
|
log::debug!("Adding file '{}'", path.display());
|
||||||
let checksum = util::checksum::gen(&[&data]);
|
let checksum = util::checksum::gen(&[&data]);
|
||||||
let offset = if let Some(offset) = self.file_offsets.get(&checksum) {
|
let offset = if let Some(offset) = self.file_offsets.get(&checksum) {
|
||||||
|
@ -193,7 +199,7 @@ impl VfsBuilder {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_symlink(
|
fn add_symlink(
|
||||||
&mut self,
|
&mut self,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
target: &Path,
|
target: &Path,
|
||||||
|
@ -833,6 +839,7 @@ mod test {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
fn read_file(vfs: &FileBackedVfs, path: &Path) -> String {
|
fn read_file(vfs: &FileBackedVfs, path: &Path) -> String {
|
||||||
let file = vfs.file_entry(path).unwrap();
|
let file = vfs.file_entry(path).unwrap();
|
||||||
String::from_utf8(vfs.read_file_all(file).unwrap()).unwrap()
|
String::from_utf8(vfs.read_file_all(file).unwrap()).unwrap()
|
||||||
|
@ -842,7 +849,8 @@ mod test {
|
||||||
fn builds_and_uses_virtual_fs() {
|
fn builds_and_uses_virtual_fs() {
|
||||||
let temp_dir = TempDir::new();
|
let temp_dir = TempDir::new();
|
||||||
let src_path = temp_dir.path().join("src");
|
let src_path = temp_dir.path().join("src");
|
||||||
let mut builder = VfsBuilder::new(src_path.clone());
|
temp_dir.create_dir_all(&src_path);
|
||||||
|
let mut builder = VfsBuilder::new(src_path.clone()).unwrap();
|
||||||
builder
|
builder
|
||||||
.add_file(&src_path.join("a.txt"), "data".into())
|
.add_file(&src_path.join("a.txt"), "data".into())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -923,7 +931,7 @@ mod test {
|
||||||
|
|
||||||
// build and create the virtual fs
|
// build and create the virtual fs
|
||||||
let src_path = temp_dir.path().join("src");
|
let src_path = temp_dir.path().join("src");
|
||||||
let mut builder = VfsBuilder::new(src_path.clone());
|
let mut builder = VfsBuilder::new(src_path.clone()).unwrap();
|
||||||
builder.add_dir_recursive(&src_path).unwrap();
|
builder.add_dir_recursive(&src_path).unwrap();
|
||||||
let (dest_path, virtual_fs) = into_virtual_fs(builder, &temp_dir);
|
let (dest_path, virtual_fs) = into_virtual_fs(builder, &temp_dir);
|
||||||
|
|
||||||
|
@ -987,7 +995,8 @@ mod test {
|
||||||
fn circular_symlink() {
|
fn circular_symlink() {
|
||||||
let temp_dir = TempDir::new();
|
let temp_dir = TempDir::new();
|
||||||
let src_path = temp_dir.path().join("src");
|
let src_path = temp_dir.path().join("src");
|
||||||
let mut builder = VfsBuilder::new(src_path.clone());
|
temp_dir.create_dir_all(&src_path);
|
||||||
|
let mut builder = VfsBuilder::new(src_path.clone()).unwrap();
|
||||||
builder
|
builder
|
||||||
.add_symlink(&src_path.join("a.txt"), &src_path.join("b.txt"))
|
.add_symlink(&src_path.join("a.txt"), &src_path.join("b.txt"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -1020,7 +1029,7 @@ mod test {
|
||||||
async fn test_open_file() {
|
async fn test_open_file() {
|
||||||
let temp_dir = TempDir::new();
|
let temp_dir = TempDir::new();
|
||||||
let temp_path = temp_dir.path();
|
let temp_path = temp_dir.path();
|
||||||
let mut builder = VfsBuilder::new(temp_path.to_path_buf());
|
let mut builder = VfsBuilder::new(temp_path.to_path_buf()).unwrap();
|
||||||
builder
|
builder
|
||||||
.add_file(
|
.add_file(
|
||||||
&temp_path.join("a.txt"),
|
&temp_path.join("a.txt"),
|
||||||
|
|
Loading…
Add table
Reference in a new issue