remove more calls to tokio_util::block_on (#3059)

towards #2960
This commit is contained in:
Bartek Iwańczuk 2019-10-06 21:03:30 +02:00 committed by Ryan Dahl
parent 3e02d7ddbc
commit e1d49fe0fe
4 changed files with 566 additions and 518 deletions

View file

@ -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();
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 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]