summaryrefslogtreecommitdiff
path: root/cli/tsc/mod.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-06-10 11:09:45 -0400
committerGitHub <noreply@github.com>2023-06-10 11:09:45 -0400
commit7f15126f23d97f20a4fb33e43136cd4d13825863 (patch)
tree85d77389969b31999680059e65954a9fa863758e /cli/tsc/mod.rs
parentf3326eebd6af2aaca1543e8cb543a7b16762bc96 (diff)
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.
Diffstat (limited to 'cli/tsc/mod.rs')
-rw-r--r--cli/tsc/mod.rs18
1 files changed, 8 insertions, 10 deletions
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))
}
}