-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
109 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ mod test { | |
use sweet::prelude::*; | ||
|
||
#[test] | ||
fn works() { expect(true).to_be_false(); } | ||
fn works() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,31 @@ | ||
use crate::prelude::*; | ||
use flume::Sender; | ||
use forky::web::ClosureFnMutT2Ext; | ||
use test::TestDescAndFn; | ||
use wasm_bindgen::prelude::Closure; | ||
use wasm_bindgen::JsCast; | ||
use wasm_bindgen::JsValue; | ||
|
||
|
||
/// Run sync tests, and return async tests | ||
pub fn run_wasm_tests_sync( | ||
tests: Vec<TestDescAndFn>, | ||
result_tx: &Sender<TestDescAndResult>, | ||
) -> Vec<TestDescAndFuture> { | ||
tests | ||
.into_iter() | ||
.filter_map(|test| { | ||
let func = TestDescAndFnExt::func(&test); | ||
let mut func = TestDescAndFnExt::func(&test); | ||
|
||
let result = SweetTestCollector::with_scope(&test.desc, || { | ||
PanicStore::with_scope(&test.desc, || { | ||
// dont worry if it returned error, we will catch the panic | ||
run_no_abort(func) | ||
js_runtime::panic_to_error(&mut func) | ||
}) | ||
}); | ||
|
||
match result { | ||
Ok(PanicStoreOut::Panicked(result)) => { | ||
result_tx.send(result).expect("channel was dropped"); | ||
None | ||
} | ||
Ok(PanicStoreOut::Ok(_)) => { | ||
let test_result = | ||
TestResult::from_test_result(Ok(()), &test.desc); | ||
result_tx | ||
.send(TestDescAndResult::new( | ||
test.desc.clone(), | ||
test_result, | ||
)) | ||
.expect("channel was dropped"); | ||
Ok(panic_out) => { | ||
panic_out.send(result_tx, &test.desc); | ||
None | ||
} | ||
Err(val) => Some(val), | ||
} | ||
}) | ||
.collect() | ||
} | ||
|
||
/// this function may panic. In js that will abort execution | ||
/// so we send it out of the wasm boundary | ||
/// TODO try the wb_test func might be cheaper than closure | ||
fn run_no_abort(func: fn() -> Result<(), String>) { | ||
// fn run_no_abort(func: fn() -> Result<(), String>) -> Result<(), String> { | ||
let closure = Closure::from_func_no_args(move || { | ||
TestDescExt::result_to_panic(func()); | ||
}); | ||
let func: &js_sys::Function = closure.as_ref().unchecked_ref(); | ||
func.call0(&JsValue::NULL).ok(); | ||
// match func.call0(&JsValue::NULL) { | ||
// Ok(_) => Ok(()), | ||
// Err(err) => Err(format!("{:?}", err)), | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters