summaryrefslogtreecommitdiff
path: root/cli/specifier_handler.rs
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-10-07 16:24:15 +1100
committerGitHub <noreply@github.com>2020-10-07 16:24:15 +1100
commit7ab645f512057d74fda2d0edf2d336cea3ed524e (patch)
tree7c208585997475cc6fa808d17d3c2b58c065c4cd /cli/specifier_handler.rs
parentece400d13fdb38d7acaa57a17354538bd5d6a44c (diff)
refactor(cli): cleanups to new module graph (#7846)
Diffstat (limited to 'cli/specifier_handler.rs')
-rw-r--r--cli/specifier_handler.rs131
1 files changed, 0 insertions, 131 deletions
diff --git a/cli/specifier_handler.rs b/cli/specifier_handler.rs
index 80fb28b19..c2f852ab6 100644
--- a/cli/specifier_handler.rs
+++ b/cli/specifier_handler.rs
@@ -372,140 +372,9 @@ impl SpecifierHandler for FetchHandler {
#[cfg(test)]
pub mod tests {
use super::*;
-
use crate::http_cache::HttpCache;
-
- use deno_core::futures::future;
- use std::fs;
- use std::path::PathBuf;
use tempfile::TempDir;
- /// This is a testing mock for `SpecifierHandler` that uses a special file
- /// system renaming to mock local and remote modules as well as provides
- /// "spies" for the critical methods for testing purposes.
- #[derive(Debug, Default)]
- pub struct MockSpecifierHandler {
- pub fixtures: PathBuf,
- pub build_info: HashMap<ModuleSpecifier, TextDocument>,
- pub build_info_calls: Vec<(ModuleSpecifier, EmitType, TextDocument)>,
- pub cache_calls: Vec<(
- ModuleSpecifier,
- EmitType,
- TextDocument,
- Option<TextDocument>,
- )>,
- pub deps_calls: Vec<(ModuleSpecifier, DependencyMap)>,
- pub types_calls: Vec<(ModuleSpecifier, String)>,
- pub version_calls: Vec<(ModuleSpecifier, String)>,
- }
-
- impl MockSpecifierHandler {}
-
- impl MockSpecifierHandler {
- fn get_cache(
- &self,
- specifier: ModuleSpecifier,
- ) -> Result<CachedModule, AnyError> {
- let specifier_text = specifier
- .to_string()
- .replace(":///", "_")
- .replace("://", "_")
- .replace("/", "-");
- let specifier_path = self.fixtures.join(specifier_text);
- let media_type =
- match specifier_path.extension().unwrap().to_str().unwrap() {
- "ts" => {
- if specifier_path.to_string_lossy().ends_with(".d.ts") {
- MediaType::Dts
- } else {
- MediaType::TypeScript
- }
- }
- "tsx" => MediaType::TSX,
- "js" => MediaType::JavaScript,
- "jsx" => MediaType::JSX,
- _ => MediaType::Unknown,
- };
- let source =
- TextDocument::new(fs::read(specifier_path)?, Option::<&str>::None);
-
- Ok(CachedModule {
- source,
- specifier,
- media_type,
- ..CachedModule::default()
- })
- }
- }
-
- impl SpecifierHandler for MockSpecifierHandler {
- fn fetch(&mut self, specifier: ModuleSpecifier) -> FetchFuture {
- Box::pin(future::ready(self.get_cache(specifier)))
- }
- fn get_build_info(
- &self,
- specifier: &ModuleSpecifier,
- _cache_type: &EmitType,
- ) -> Result<Option<TextDocument>, AnyError> {
- Ok(self.build_info.get(specifier).cloned())
- }
- fn set_cache(
- &mut self,
- specifier: &ModuleSpecifier,
- cache_type: &EmitType,
- code: TextDocument,
- maybe_map: Option<TextDocument>,
- ) -> Result<(), AnyError> {
- self.cache_calls.push((
- specifier.clone(),
- cache_type.clone(),
- code,
- maybe_map,
- ));
- Ok(())
- }
- fn set_types(
- &mut self,
- specifier: &ModuleSpecifier,
- types: String,
- ) -> Result<(), AnyError> {
- self.types_calls.push((specifier.clone(), types));
- Ok(())
- }
- fn set_build_info(
- &mut self,
- specifier: &ModuleSpecifier,
- cache_type: &EmitType,
- build_info: TextDocument,
- ) -> Result<(), AnyError> {
- self
- .build_info
- .insert(specifier.clone(), build_info.clone());
- self.build_info_calls.push((
- specifier.clone(),
- cache_type.clone(),
- build_info,
- ));
- Ok(())
- }
- fn set_deps(
- &mut self,
- specifier: &ModuleSpecifier,
- dependencies: DependencyMap,
- ) -> Result<(), AnyError> {
- self.deps_calls.push((specifier.clone(), dependencies));
- Ok(())
- }
- fn set_version(
- &mut self,
- specifier: &ModuleSpecifier,
- version: String,
- ) -> Result<(), AnyError> {
- self.version_calls.push((specifier.clone(), version));
- Ok(())
- }
- }
-
fn setup() -> (TempDir, FetchHandler) {
let temp_dir = TempDir::new().expect("could not setup");
let deno_dir = DenoDir::new(Some(temp_dir.path().to_path_buf()))