Add a test harness to directly execute wasm tests (#524)

* Add a test harness to directly execute wasm tests

This commits adds a few new crates and infrastructure to enable comands like:

    cargo test --target wasm32-unknown-unknown

The intention here is to make it as low-friction as possible to write wasm tests
and also have them execute in a reasonable amount of time. Eventually this is
also hopefully enough support to do things like headless testing!

For now though this is defintely MVP status rather than fully fleshed out.
There's some more information at `crates/test/README.md` about how it works and
how to use it, but for now this is mainly intended to play around with locally
in this repository for our own tests.

* Port a numbe of `js-sys` tests to the new test framework

This commit ports a number of existing tests for the `js-sys` crate over to the
new test framework created in the previous commit, showing off how they can be
executed as well as drastictlly simplifying the tests themselves! This is
intended to be a proof of concept for now which we can refine over time. This
should also show off that it's possible to incrementally move over to the new
test framework.
This commit is contained in:
Alex Crichton
2018-07-20 13:47:49 -05:00
committed by GitHub
parent 722a87f324
commit f8d336d711
27 changed files with 946 additions and 326 deletions

View File

@ -118,6 +118,15 @@ extern "C" {
extern "C" {
pub type Array;
/// Creates a new empty array
#[wasm_bindgen(constructor)]
pub fn new() -> Array;
/// The `Array.from()` method creates a new, shallow-copied `Array` instance
/// from an array-like or iterable object.
#[wasm_bindgen(static_method_of = Array)]
pub fn from(val: JsValue) -> Array;
/// The copyWithin() method shallow copies part of an array to another
/// location in the same array and returns it, without modifying its size.
///
@ -720,6 +729,43 @@ extern "C" {
/// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/fill
#[wasm_bindgen(method)]
pub fn fill(this: &Int8Array, value: i8, start: u32, end: u32) -> Int8Array;
/// The `buffer` accessor property represents the `ArrayBuffer` referenced
/// by a `TypedArray` at construction time.
#[wasm_bindgen(getter, method)]
pub fn buffer(this: &Int8Array) -> ArrayBuffer;
// /// The `byteLength` accessor property represents the length (in bytes) of a
// /// typed array.
// #[wasm_bindgen(getter, method, js_name = byteLength)]
// pub fn byte_length(this: &Int8Array) -> u32;
//
// /// The `byteOffset` accessor property represents the offset (in bytes) of a
// /// typed array from the start of its `ArrayBuffer`.
// #[wasm_bindgen(getter, method, js_name = byteOffset)]
// pub fn byte_offset(this: &Int8Array) -> u32;
//
// /// The `length` accessor property represents the length (in elements) of a
// /// typed array.
// #[wasm_bindgen(getter, method)]
// pub fn length(this: &Int8Array) -> u32;
//
// /// The `set()` method stores multiple values in the typed array, reading
// /// input values from a specified array.
// #[wasm_bindgen(method)]
// pub fn set(this: &Int8Array, value: &JsValue, offset: u32);
/// The `subarray()` method stores multiple values in the typed array,
/// reading input values from a specified array.
#[wasm_bindgen(method)]
pub fn subarray(this: &Int8Array, begin: u32, end: u32) -> Int8Array;
/// The `forEach()` method executes a provided function once per array
/// element. This method has the same algorithm as
/// `Array.prototype.forEach()`. `TypedArray` is one of the typed array
/// types here.
#[wasm_bindgen(method, js_name = forEach)]
pub fn for_each(this: &Int8Array, callback: &mut FnMut(i8, u32, Int8Array));
}
// Int16Array