Alex Crichton 7b4f0072c8 Add support for headless testing
This commit adds support to the `wasm-bindgen-test-runner` binary to
perform headless testing via browsers. The previous commit introduced a
local server to serve up files and run tests in a browser, and this
commit adds support for executing that in an automated fashion.

The general idea here is that each browser has a binary that implements
the WebDriver specification. These binaries (typically `foodriver` for
the browser "Foo") are interfaced with using HTTP and JSON messages. The
implementation was simple enough and the crates.io support was lacking
enough that a small implementation of the WebDriver protocol was added
directly to this crate.

Currently Firefox (`geckodriver`), Chrome (`chromedriver`), and Safari
(`safaridriver`) are supported for running tests. The test harness will
recognize env vars like `GECKODRIVER=foo` to specifically use one or
otherwise detects the first driver in `PATH`. Eventually we may wish to
automatically download a driver if one isn't found, but that isn't
implemented yet.

Headless testing is turned on with the `CI=1` env var currently to be
amenable with things like Travis and AppVeyor, but this may wish to grow
an explicit option to run headless tests in the future.
2018-07-30 11:07:07 -07:00

63 lines
1.6 KiB
Rust

use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use js_sys::*;
#[wasm_bindgen]
extern {
#[wasm_bindgen(js_name = max, js_namespace = Math)]
static MAX: Function;
type ArrayPrototype;
#[wasm_bindgen(method, getter, structural)]
pub fn push(this: &ArrayPrototype) -> Function;
#[wasm_bindgen(js_name = prototype, js_namespace = Array)]
static ARRAY_PROTOTYPE2: ArrayPrototype;
}
#[wasm_bindgen_test]
fn apply() {
let args = Array::new();
args.push(&1.into());
args.push(&2.into());
args.push(&3.into());
assert_eq!(MAX.apply(&JsValue::undefined(), &args).unwrap(), 3);
let arr = JsValue::from(Array::new());
let args = Array::new();
args.push(&1.into());
ARRAY_PROTOTYPE2.push().apply(&arr, &args).unwrap();
assert_eq!(Array::from(&arr).length(), 1);
}
#[wasm_bindgen(module = "tests/wasm/Function.js", version = "*")]
extern {
fn get_function_to_bind() -> Function;
fn get_value_to_bind_to() -> JsValue;
fn call_function(f: Function) -> JsValue;
}
#[wasm_bindgen_test]
fn bind() {
let f = get_function_to_bind();
let new_f = f.bind(&get_value_to_bind_to());
assert_eq!(call_function(f), 1);
assert_eq!(call_function(new_f), 2);
}
#[wasm_bindgen_test]
fn length() {
assert_eq!(MAX.length(), 2);
assert_eq!(ARRAY_PROTOTYPE2.push().length(), 1);
}
#[wasm_bindgen_test]
fn name() {
assert_eq!(JsValue::from(MAX.name()), "max");
assert_eq!(JsValue::from(ARRAY_PROTOTYPE2.push().name()), "push");
}
#[wasm_bindgen_test]
fn to_string() {
assert!(MAX.to_string().length() > 0);
}