summaryrefslogtreecommitdiff
path: root/cli/compilers/ts.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-10-06 21:03:30 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-10-06 15:03:30 -0400
commite1d49fe0fec2f0573f38d24c47c128b78cb43498 (patch)
treed5bbc5338919145e76c3031854b9d8b951f10901 /cli/compilers/ts.rs
parent3e02d7ddbc04cf3bfc681a5f4cfe6b91a9860cbd (diff)
remove more calls to tokio_util::block_on (#3059)
towards #2960
Diffstat (limited to 'cli/compilers/ts.rs')
-rw-r--r--cli/compilers/ts.rs92
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]