wasm_testing working

This commit is contained in:
andy 2021-06-22 21:05:22 +01:00
parent 2151d0991b
commit 9da8496e73
4 changed files with 27 additions and 11 deletions

View File

@ -21,11 +21,8 @@ jobs:
- name: Build Rust for WASM - name: Build Rust for WASM
run: wasm-pack build run: wasm-pack build
- name: Test WASM on Firefox - name: Test WASM in-browser
run: wasm-pack test --firefox --headless run: wasm-pack test --firefox --chrome --headless
- name: Test WASM on Chrome
run: wasm-pack test --chrome --headless
- name: Install Node - name: Install Node
uses: actions/setup-node@v2 uses: actions/setup-node@v2

View File

@ -23,7 +23,7 @@ macro_rules! log {
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn init() { pub fn init_game() {
log!("initialising wasm"); log!("initialising wasm");
utils::set_panic_hook(); utils::set_panic_hook();

View File

@ -3,11 +3,30 @@
#![cfg(target_arch = "wasm32")] #![cfg(target_arch = "wasm32")]
extern crate wasm_bindgen_test; extern crate wasm_bindgen_test;
use wasm_bindgen_test::*; // use wasm_bindgen_test::*;
use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure};
wasm_bindgen_test_configure!(run_in_browser); wasm_bindgen_test_configure!(run_in_browser);
extern crate gameoflife;
use gameoflife::Universe;
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn pass() { fn get_width() {
assert_eq!(1 + 1, 2); let uni = Universe::new(10, 15, 1, 1.0);
assert_eq!(uni.width(), 10);
} }
#[wasm_bindgen_test]
fn get_height() {
let uni = Universe::new(10, 15, 1, 1.0);
assert_eq!(uni.height(), 15);
}
#[wasm_bindgen_test]
fn get_cells() {
let uni = Universe::new(10, 15, 1, 1.0);
uni.cells();
}

View File

@ -1,9 +1,9 @@
import { Universe, Cell, init } from "gameoflife"; import { Universe, Cell, init_game } from "gameoflife";
import { memory } from "gameoflife/gameoflife_bg.wasm"; import { memory } from "gameoflife/gameoflife_bg.wasm";
// let PLAY = true; // let PLAY = true;
// let PLAY = false; // let PLAY = false;
init(); init_game();
const randSlider = document.getElementById("randThreshold"); const randSlider = document.getElementById("randThreshold");
const randSliderLabel = document.getElementById("randThreshold-label"); const randSliderLabel = document.getElementById("randThreshold-label");