Skip to content

Commit 5b8ed84

Browse files
committed
add working test harness site
1 parent af58f64 commit 5b8ed84

File tree

17 files changed

+1425
-0
lines changed

17 files changed

+1425
-0
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ members = [
2929
"stageleft_tool",
3030
"topolotree",
3131
"variadics",
32+
"wasm_test_site",
3233
"website_playground",
3334
]
3435

docs/src/pages/playground.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ if (siteConfig.customFields.LOAD_PLAYGROUND === '1') {
3030
}
3131

3232
playgroundJS.init();
33+
34+
window.test_hydroflow = playgroundJS.test_hydroflow;
3335
}
3436

3537
import mermaid from "mermaid";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "08:00"
8+
open-pull-requests-limit: 10

wasm_test_site/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/target
2+
**/*.rs.bk
3+
Cargo.lock
4+
bin/
5+
pkg/
6+
wasm-pack.log

wasm_test_site/Cargo.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "wasm_test_site"
3+
version = "0.1.0"
4+
authors = ["Mingwei Samuel <mingwei.samuel@gmail.com>"]
5+
edition = "2018"
6+
7+
[lib]
8+
crate-type = ["cdylib", "rlib"]
9+
10+
[dependencies]
11+
hydroflow = { path = "../hydroflow" }
12+
wasm-bindgen = "0.2.84"
13+
wasm-bindgen-futures = "0.4.43"
14+
web-sys = { version = "0.3.51", features = [ "console" ] }
15+
16+
# The `console_error_panic_hook` crate provides better debugging of panics by
17+
# logging them with `console.error`. This is great for development, but requires
18+
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
19+
# code size when deploying.
20+
console_error_panic_hook = "0.1.7"
21+
22+
[dev-dependencies]
23+
wasm-bindgen-test = "0.3.34"
24+
25+
[profile.release]
26+
# Tell `rustc` to optimize for small code size.
27+
opt-level = "s"

wasm_test_site/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Go to `www/README.md`
2+
3+
---
4+
5+
<div align="center">
6+
7+
<h1><code>wasm-pack-template</code></h1>
8+
9+
<strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong>
10+
11+
<p>
12+
<a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a>
13+
</p>
14+
15+
<h3>
16+
<a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a>
17+
<span> | </span>
18+
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a>
19+
</h3>
20+
21+
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub>
22+
</div>
23+
24+
## About
25+
26+
[**📚 Read this template tutorial! 📚**][template-docs]
27+
28+
This template is designed for compiling Rust libraries into WebAssembly and
29+
publishing the resulting package to NPM.
30+
31+
Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other
32+
templates and usages of `wasm-pack`.
33+
34+
[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html
35+
[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html
36+
37+
## 🚴 Usage
38+
39+
### 🐑 Use `cargo generate` to Clone this Template
40+
41+
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate)
42+
43+
```
44+
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
45+
cd my-project
46+
```
47+
48+
### 🛠️ Build with `wasm-pack build`
49+
50+
```
51+
wasm-pack build
52+
```
53+
54+
### 🔬 Test in Headless Browsers with `wasm-pack test`
55+
56+
```
57+
wasm-pack test --headless --firefox
58+
```
59+
60+
### 🎁 Publish to NPM with `wasm-pack publish`
61+
62+
```
63+
wasm-pack publish
64+
```
65+
66+
## 🔋 Batteries Included
67+
68+
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating
69+
between WebAssembly and JavaScript.
70+
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook)
71+
for logging panic messages to the developer console.
72+
* `LICENSE-APACHE` and `LICENSE-MIT`: most Rust projects are licensed this way, so these are included for you
73+
74+
## License
75+
76+
Licensed under either of
77+
78+
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
79+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
80+
81+
at your option.
82+
83+
### Contribution
84+
85+
Unless you explicitly state otherwise, any contribution intentionally
86+
submitted for inclusion in the work by you, as defined in the Apache-2.0
87+
license, shall be dual licensed as above, without any additional terms or
88+
conditions.

wasm_test_site/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use wasm_bindgen::prelude::*;
2+
3+
fn log(string: impl AsRef<str>) {
4+
web_sys::console::log_1(&JsValue::from_str(string.as_ref()));
5+
}
6+
7+
#[wasm_bindgen]
8+
pub fn greet() {
9+
console_error_panic_hook::set_once();
10+
11+
log("Hello, wasm_test_site!");
12+
}
13+
14+
#[wasm_bindgen]
15+
pub fn test_hydroflow() -> web_sys::js_sys::Promise {
16+
console_error_panic_hook::set_once();
17+
18+
let mut df = hydroflow::hydroflow_syntax! {
19+
// https://hydro.run/docs/hydroflow/quickstart/example_1_simplest
20+
source_iter(0..10) -> for_each(|n| log(format!("Hello {}", n)));
21+
};
22+
23+
wasm_bindgen_futures::future_to_promise(async move {
24+
let work_done = df.run_available_async().await;
25+
Ok(if work_done {
26+
JsValue::TRUE
27+
} else {
28+
JsValue::FALSE
29+
})
30+
})
31+
}

wasm_test_site/tests/web.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Test suite for the Web and headless browsers.
2+
3+
#![cfg(target_arch = "wasm32")]
4+
5+
extern crate wasm_bindgen_test;
6+
use wasm_bindgen_test::*;
7+
8+
wasm_bindgen_test_configure!(run_in_browser);
9+
10+
#[wasm_bindgen_test]
11+
fn pass() {
12+
assert_eq!(1 + 1, 2);
13+
}

wasm_test_site/www/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

0 commit comments

Comments
 (0)