Skip to content

Commit

Permalink
test: wasm test
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Jan 23, 2024
1 parent 3377e66 commit f3888e9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion libs/client-api-test-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ uuid = "1.6.1"
lazy_static = "1.4.0"
dotenv = "0.15.0"
reqwest = "0.11.23"
gotrue.workspace = true
gotrue.workspace = true

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["console"] }
25 changes: 25 additions & 0 deletions libs/wasm-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

## Run test

before running the test, it requires to install the [chrome driver](https://chromedriver.chromium.org/downloads).
for mac user, you can install it by brew.

```shell
brew install chromedriver
```

then run the test


```shell
wasm-pack test --headless --chrome
```

## Testing in browser

```shell
wasm-pack test --chrome
```

Ref:
[wasm-bindgen-test](https://rustwasm.github.io/wasm-bindgen/wasm-bindgen-test/browsers.html)
3 changes: 3 additions & 0 deletions libs/wasm-test/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ wasm_bindgen_test_configure!(run_in_browser);

// #[cfg(target_arch = "wasm32")]
// mod conn_test;

#[cfg(target_arch = "wasm32")]
mod user_test;
10 changes: 10 additions & 0 deletions libs/wasm-test/tests/user_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use client_api_test_util::{admin_user_client, generate_unique_email, localhost_client};
use wasm_bindgen_test::wasm_bindgen_test;

#[wasm_bindgen_test]
async fn sign_up_success() {
let email = generate_unique_email();
let password = "Hello!123#";
let c = localhost_client();
c.sign_up(&email, password).await.unwrap();
}
5 changes: 4 additions & 1 deletion src/middleware/cors_mw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pub fn default_cors() -> Cors {
.allow_any_origin()
.send_wildcard()
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE"])
.allowed_headers(vec![http::header::ACCEPT])
.allowed_headers(vec![
actix_web::http::header::AUTHORIZATION,
actix_web::http::header::ACCEPT,
])
.allowed_header(http::header::CONTENT_TYPE)
.max_age(3600)
}

0 comments on commit f3888e9

Please sign in to comment.