mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 08:41:35 +00:00
cargo +nightly fmt --all
Rustfmt all the things!
This commit is contained in:
@ -3,8 +3,8 @@
|
||||
//! Currently this is quite simple, rendering the same as the console tests in
|
||||
//! node.js. Output here is rendered in a `pre`, however.
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
use js_sys::Error;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Implementation of `Formatter` for browsers.
|
||||
///
|
||||
@ -15,7 +15,7 @@ pub struct Browser {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
type HTMLDocument;
|
||||
static document: HTMLDocument;
|
||||
#[wasm_bindgen(method, structural)]
|
||||
@ -38,9 +38,7 @@ impl Browser {
|
||||
pub fn new() -> Browser {
|
||||
let pre = document.getElementById("output");
|
||||
pre.set_inner_html("");
|
||||
Browser {
|
||||
pre,
|
||||
}
|
||||
Browser { pre }
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,11 +73,10 @@ impl super::Formatter for Browser {
|
||||
// probably a chome-like error which is already rendered well, so just
|
||||
// return this info
|
||||
if stack.contains(&header) {
|
||||
return stack
|
||||
return stack;
|
||||
}
|
||||
|
||||
// Fallback to make sure we don't lose any info
|
||||
format!("{}\n{}", header, stack)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
//! Runtime detection of whether we're in node.js or a browser.
|
||||
|
||||
use js_sys;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use js_sys;
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
type This;
|
||||
#[wasm_bindgen(method, getter, structural, js_name = self)]
|
||||
fn self_(me: &This) -> JsValue;
|
||||
|
@ -87,8 +87,7 @@
|
||||
// Overall this is all somewhat in flux as it's pretty new, and feedback is
|
||||
// always of course welcome!
|
||||
|
||||
|
||||
use std::cell::{RefCell, Cell};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
||||
@ -107,9 +106,9 @@ use wasm_bindgen_futures::future_to_promise;
|
||||
// conccurrently doing things by default would likely end up in a bad situation.
|
||||
const CONCURRENCY: usize = 1;
|
||||
|
||||
pub mod node;
|
||||
pub mod browser;
|
||||
pub mod detect;
|
||||
pub mod node;
|
||||
|
||||
/// Runtime test harness support instantiated in JS.
|
||||
///
|
||||
@ -182,7 +181,7 @@ trait Formatter {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console, js_name = log)]
|
||||
#[doc(hidden)]
|
||||
pub fn js_console_log(s: &str);
|
||||
@ -259,7 +258,9 @@ impl Context {
|
||||
/// `false` if at least one test failed.
|
||||
pub fn run(&self, tests: Vec<JsValue>) -> Promise {
|
||||
let noun = if tests.len() == 1 { "test" } else { "tests" };
|
||||
self.state.formatter.writeln(&format!("running {} {}", tests.len(), noun));
|
||||
self.state
|
||||
.formatter
|
||||
.writeln(&format!("running {} {}", tests.len(), noun));
|
||||
self.state.formatter.writeln("");
|
||||
|
||||
// Execute all our test functions through their wasm shims (unclear how
|
||||
@ -271,8 +272,10 @@ impl Context {
|
||||
match Function::from(test).call1(&JsValue::null(), &cx_arg) {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
panic!("exception thrown while creating a test: {}",
|
||||
self.state.formatter.stringify_error(&e));
|
||||
panic!(
|
||||
"exception thrown while creating a test: {}",
|
||||
self.state.formatter.stringify_error(&e)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -280,7 +283,8 @@ impl Context {
|
||||
// Now that we've collected all our tests we wrap everything up in a
|
||||
// future to actually do all the processing, and pass it out to JS as a
|
||||
// `Promise`.
|
||||
let future = ExecuteTests(self.state.clone()).map(JsValue::from)
|
||||
let future = ExecuteTests(self.state.clone())
|
||||
.map(JsValue::from)
|
||||
.map_err(|e| match e {});
|
||||
future_to_promise(future)
|
||||
}
|
||||
@ -316,7 +320,7 @@ pub fn __wbgtest_console_error(original: &Function, args: &Array) {
|
||||
fn record(orig: &Function, args: &Array, dst: impl FnOnce(&mut Output) -> &mut String) {
|
||||
if !CURRENT_OUTPUT.is_set() {
|
||||
drop(orig.apply(&JsValue::null(), args));
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
CURRENT_OUTPUT.with(|output| {
|
||||
@ -343,16 +347,13 @@ impl Context {
|
||||
/// `#[wasm_bindgen_test(async)]` macro generates invocations of this
|
||||
/// method.
|
||||
pub fn execute_async<F>(&self, name: &str, f: impl FnOnce() -> F + 'static)
|
||||
where F: Future<Item = (), Error = JsValue> + 'static,
|
||||
where
|
||||
F: Future<Item = (), Error = JsValue> + 'static,
|
||||
{
|
||||
self.execute(name, future::lazy(f))
|
||||
}
|
||||
|
||||
fn execute(
|
||||
&self,
|
||||
name: &str,
|
||||
test: impl Future<Item = (), Error = JsValue> + 'static,
|
||||
) {
|
||||
fn execute(&self, name: &str, test: impl Future<Item = (), Error = JsValue> + 'static) {
|
||||
// If our test is filtered out, record that it was filtered and move
|
||||
// on, nothing to do here.
|
||||
let filter = self.state.filter.borrow();
|
||||
@ -360,7 +361,7 @@ impl Context {
|
||||
if !name.contains(filter) {
|
||||
let ignored = self.state.ignored.get();
|
||||
self.state.ignored.set(ignored + 1);
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,7 +417,7 @@ impl Future for ExecuteTests {
|
||||
Ok(Async::Ready(())) => Ok(()),
|
||||
Ok(Async::NotReady) => {
|
||||
running.push(test);
|
||||
continue
|
||||
continue;
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
};
|
||||
@ -426,7 +427,7 @@ impl Future for ExecuteTests {
|
||||
// Tests are still executing, we're registered to get a notification,
|
||||
// keep going.
|
||||
if running.len() != 0 {
|
||||
return Ok(Async::NotReady)
|
||||
return Ok(Async::NotReady);
|
||||
}
|
||||
|
||||
// If there are no tests running then we must have finished everything,
|
||||
@ -532,7 +533,7 @@ struct TestFuture<F> {
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
#[wasm_bindgen(catch)]
|
||||
fn __wbg_test_invoke(f: &mut FnMut()) -> Result<(), JsValue>;
|
||||
}
|
||||
|
@ -6,11 +6,10 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
/// Implementation of the `Formatter` trait for node.js
|
||||
pub struct Node {
|
||||
}
|
||||
pub struct Node {}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
extern "C" {
|
||||
// Not using `js_sys::Error` because node's errors specifically have a
|
||||
// `stack` attribute.
|
||||
type NodeError;
|
||||
@ -23,9 +22,9 @@ impl Node {
|
||||
/// is executing in a browser and Node won't work.
|
||||
pub fn new() -> Option<Node> {
|
||||
if super::detect::is_browser() {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
Some(Node { })
|
||||
Some(Node {})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user