From 7f15126f23d97f20a4fb33e43136cd4d13825863 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 10 Jun 2023 11:09:45 -0400 Subject: chore(tests): test_util - Add `PathRef` (#19450) This adds a new `PathRef` struct to test_util for making it easier to work with paths in test code. I'm going to expand on this more in the future. --- cli/tsc/mod.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'cli/tsc/mod.rs') diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 83fd84f9d..a4d6640f7 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -841,11 +841,11 @@ mod tests { use deno_core::OpState; use deno_graph::GraphKind; use deno_graph::ModuleGraph; - use std::fs; + use test_util::PathRef; #[derive(Debug, Default)] pub struct MockLoader { - pub fixtures: PathBuf, + pub fixtures: PathRef, } impl deno_graph::source::Loader for MockLoader { @@ -860,15 +860,13 @@ mod tests { .replace("://", "_") .replace('/', "-"); let source_path = self.fixtures.join(specifier_text); - let response = fs::read_to_string(source_path) - .map(|c| { - Some(deno_graph::source::LoadResponse::Module { - specifier: specifier.clone(), - maybe_headers: None, - content: c.into(), - }) + let response = source_path.read_to_string_if_exists().map(|c| { + Some(deno_graph::source::LoadResponse::Module { + specifier: specifier.clone(), + maybe_headers: None, + content: c.into(), }) - .map_err(|err| err.into()); + }); Box::pin(future::ready(response)) } } -- cgit v1.2.3