mirror of https://github.com/http-rs/surf
actually test wasm
This commit is contained in:
parent
690ed8002a
commit
da849f1e51
|
@ -42,31 +42,23 @@ jobs:
|
|||
command: test
|
||||
args: --all --no-default-features --features '${{ matrix.backend }} middleware-logger encoding'
|
||||
|
||||
check_wasm:
|
||||
name: Check wasm targets
|
||||
test_wasm:
|
||||
name: Test wasm
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Install nightly with wasm32-unknown-unknown
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
target: wasm32-unknown-unknown
|
||||
override: true
|
||||
- name: Install
|
||||
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
|
||||
- name: check
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --target wasm32-unknown-unknown --no-default-features --features wasm-client
|
||||
- name: Chrome
|
||||
run: wasm-pack test --headless --chrome
|
||||
working-directory: wasm-test
|
||||
|
||||
- name: check with middleware and encoding
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
args: --target wasm32-unknown-unknown --no-default-features --features wasm-client,middleware-logger,encoding
|
||||
- name: Firefox
|
||||
run: wasm-pack test --headless --firefox
|
||||
working-directory: wasm-test
|
||||
|
||||
check_fmt_and_docs:
|
||||
name: Checking fmt, clippy, and docs
|
||||
|
|
|
@ -61,5 +61,5 @@ femme = "1.1.0"
|
|||
serde = { version = "1.0.97", features = ["derive"] }
|
||||
mockito = "0.23.3"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
wasm-bindgen = "0.2.48"
|
||||
[workspace]
|
||||
members = [ "wasm-test" ]
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "wasm-test"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
surf = {path = "..", default-features = false, features = ["wasm-client"]}
|
||||
wasm-bindgen-test = "0.3.18"
|
||||
async-std = "1.6.4"
|
||||
serde_json = "1.0.57"
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
use serde_json::value::Value;
|
||||
use wasm_bindgen_test::*;
|
||||
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
async fn get() {
|
||||
let mut response = surf::get("http://httpbin.org/get")
|
||||
.header("custom-header", "header-value")
|
||||
.await
|
||||
.unwrap();
|
||||
let body: Value = response.body_json().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(body["url"], "http://httpbin.org/get");
|
||||
assert_eq!(body["headers"]["Custom-Header"], "header-value");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
async fn post() {
|
||||
let mut response = surf::post("http://httpbin.org/post")
|
||||
.header("custom-header", "header-value")
|
||||
.body(surf::Body::from_string(String::from("body")))
|
||||
.await
|
||||
.unwrap();
|
||||
let body: Value = response.body_json().await.unwrap();
|
||||
assert!(response.status().is_success());
|
||||
assert_eq!(body["url"], "http://httpbin.org/post");
|
||||
assert_eq!(body["data"], "body");
|
||||
assert_eq!(body["headers"]["Custom-Header"], "header-value");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
async fn not_found() {
|
||||
let response = surf::get("http://httpbin.org/status/404").await.unwrap();
|
||||
assert!(response.status().is_client_error());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
async fn server_error() {
|
||||
let response = surf::get("http://httpbin.org/status/500").await.unwrap();
|
||||
assert!(response.status().is_server_error());
|
||||
}
|
Loading…
Reference in New Issue