mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-18 07:11:56 +03:00
7b4f0072c8
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.
49 lines
1.1 KiB
Rust
Executable File
49 lines
1.1 KiB
Rust
Executable File
#![feature(use_extern_macros)]
|
|
#![cfg(target_arch = "wasm32")]
|
|
|
|
extern crate wasm_bindgen_test;
|
|
extern crate wasm_bindgen;
|
|
extern crate js_sys;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen_test::*;
|
|
use js_sys::Array;
|
|
|
|
wasm_bindgen_test_configure!(run_in_browser);
|
|
|
|
#[wasm_bindgen(module = "./tests/headless.js")]
|
|
extern {
|
|
fn is_array_values_supported()-> bool;
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
extern {
|
|
type ValuesIterator;
|
|
#[wasm_bindgen(method, structural)]
|
|
fn next(this: &ValuesIterator) -> IterNext;
|
|
|
|
type IterNext;
|
|
|
|
#[wasm_bindgen(method, getter, structural)]
|
|
fn value(this: &IterNext) -> JsValue;
|
|
#[wasm_bindgen(method, getter, structural)]
|
|
fn done(this: &IterNext) -> bool;
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
fn array_iterator_values() {
|
|
if !is_array_values_supported() {
|
|
return
|
|
}
|
|
let array = Array::new();
|
|
array.push(&8.into());
|
|
array.push(&3.into());
|
|
array.push(&2.into());
|
|
let iter = ValuesIterator::from(JsValue::from(array.values()));
|
|
|
|
assert_eq!(iter.next().value(), 8);
|
|
assert_eq!(iter.next().value(), 3);
|
|
assert_eq!(iter.next().value(), 2);
|
|
assert!(iter.next().done());
|
|
}
|