Skip to content

Commit

Permalink
adds framework for browser testing
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Aug 9, 2024
1 parent 720e3b0 commit a322f91
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 64 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,40 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
# 👇 Build steps

- name: install wasm-pack
uses: jetli/[email protected]
with:
version: latest

- name: build pkg
run: wasm-pack build --target web
run: wasm-pack build --target web --no-opt

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
cache: 'npm'
cache-dependency-path: './docs/package-lock.json'

- name: Install dependencies
working-directory: ./docs
run: npm install --frozen-lockfile --non-interactive

- name: Build
working-directory: ./docs
run: npm run build

# 👆 Build steps
- name: Setup Pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
# 👇 Specify build output path
path: ./docs/build

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
53 changes: 0 additions & 53 deletions .github/workflows/tests.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .github/workflows/web-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Web Tests

on:
pull_request:
push:
branches: main

jobs:
wasm-pack-test:
runs-on: ubuntu-latest
name: fmt-clippy
steps:
- name: Checkout
uses: actions/checkout@v3

- name: install wasm-pack
uses: jetli/[email protected]
with:
version: latest

- name: Install Just
uses: extractions/setup-just@v2

- name: Run tests
run: just test-web
54 changes: 54 additions & 0 deletions Cargo.lock

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

12 changes: 4 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ wasm-opt = ["-O4", "-O4"]
[dependencies]
wasm-bindgen = "0.2.84"
js-sys = "0.3.69"

zcash_keys = { git = "https://github.com/zcash/librustzcash", rev = "5a4a3e06dcd2cf5bdf79a7cd48709b58693c65f0", features = ["transparent-inputs", "orchard", "sapling", "unstable"] }
zcash_primitives = { git = "https://github.com/zcash/librustzcash", rev = "5a4a3e06dcd2cf5bdf79a7cd48709b58693c65f0" }

getrandom = { version = "0.2", features = ["js"] }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying.
console_error_panic_hook = { version = "0.1.7", optional = true }
thiserror = "1.0.63"
console_error_panic_hook = { version = "0.1.7", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.42"

[build-dependencies]
tonic-build = { version = "0.11", default-features = false, features = [
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

build:
wasm-pack build -t web --release

test-web:
WASM_BINDGEN_TEST_TIMEOUT=99999 wasm-pack test --release --headless --chrome
2 changes: 1 addition & 1 deletion src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use zcash_primitives::zip32::AccountId;
use crate::error::Error;

#[wasm_bindgen]
struct Account {
pub struct Account {
usk: UnifiedSpendingKey,
}

Expand Down
10 changes: 10 additions & 0 deletions tests/web_accounts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use wasm_bindgen_test::*;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

use webzjs::account::Account;

#[wasm_bindgen_test]
fn test_account_from_seed() {
let seed = [0; 32];
let a = Account::from_seed(&seed, 0).unwrap();
}
16 changes: 16 additions & 0 deletions webdriver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"moz:firefoxOptions": {
"prefs": {
"media.navigator.streams.fake": true,
"media.navigator.permission.disabled": true
},
"args": []
},
"goog:chromeOptions": {
"args": [
"--use-fake-device-for-media-stream",
"--use-fake-ui-for-media-stream",
"--disable-timeouts-for-profiling"
]
}
}

0 comments on commit a322f91

Please sign in to comment.