diff options
Diffstat (limited to 'cli/compilers/ts.rs')
-rw-r--r-- | cli/compilers/ts.rs | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index 3e92e5ccf..9cbaaae09 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -656,50 +656,46 @@ mod tests { use crate::fs as deno_fs; use crate::tokio_util; use deno::ModuleSpecifier; + use futures::future::lazy; use std::path::PathBuf; use tempfile::TempDir; - impl TsCompiler { - fn compile_sync( - self: &Self, - state: ThreadSafeState, - source_file: &SourceFile, - ) -> Result<CompiledModule, ErrBox> { - tokio_util::block_on(self.compile_async(state, source_file)) - } - } - #[test] - fn test_compile_sync() { - tokio_util::init(|| { - let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .parent() - .unwrap() - .join("tests/002_hello.ts") - .to_owned(); - let specifier = - ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap(); - - let out = SourceFile { - url: specifier.as_url().clone(), - filename: PathBuf::from(p.to_str().unwrap().to_string()), - media_type: msg::MediaType::TypeScript, - source_code: include_bytes!("../tests/002_hello.ts").to_vec(), - }; + fn test_compile_async() { + let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .parent() + .unwrap() + .join("tests/002_hello.ts") + .to_owned(); + let specifier = + ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap(); + + let out = SourceFile { + url: specifier.as_url().clone(), + filename: PathBuf::from(p.to_str().unwrap().to_string()), + media_type: msg::MediaType::TypeScript, + source_code: include_bytes!("../tests/002_hello.ts").to_vec(), + }; - let mock_state = ThreadSafeState::mock(vec![ - String::from("deno"), - String::from("hello.js"), - ]); - let compiled = mock_state + let mock_state = ThreadSafeState::mock(vec![ + String::from("deno"), + String::from("hello.js"), + ]); + + tokio_util::run(lazy(move || { + mock_state .ts_compiler - .compile_sync(mock_state.clone(), &out) - .unwrap(); - assert!(compiled - .code - .as_bytes() - .starts_with("console.log(\"Hello World\");".as_bytes())); - }) + .compile_async(mock_state.clone(), &out) + .then(|result| { + assert!(result.is_ok()); + assert!(result + .unwrap() + .code + .as_bytes() + .starts_with("console.log(\"Hello World\");".as_bytes())); + Ok(()) + }) + })) } #[test] @@ -719,12 +715,20 @@ mod tests { p.to_string_lossy().into(), String::from("$deno$/bundle.js"), ]); - let out = state.ts_compiler.bundle_async( - state.clone(), - module_name, - String::from("$deno$/bundle.js"), - ); - assert!(tokio_util::block_on(out).is_ok()); + + tokio_util::run(lazy(move || { + state + .ts_compiler + .bundle_async( + state.clone(), + module_name, + String::from("$deno$/bundle.js"), + ) + .then(|result| { + assert!(result.is_ok()); + Ok(()) + }) + })) } #[test] |