Skip to content

Commit 59e2513

Browse files
authored
Web tests using Vitest and Playwright (#4704)
## Motivation Currently all our testing for the Web client is manual. We'd like to know when PRs break our example apps. ## Proposal This PR sets up conventions for our Web tests that enable us to test in a variety of different environments. Going forward we can add more and more in-depth tests to cover more scenarios, and if we backport this PR we can also use these tests as an automated healthcheck for the deployed Web apps. We unify the Web tests using [Vitest](https://vitest.dev/) with a [Playwright](https://playwright.dev/) backend to run tests in real browsers (currently just Chromium, but we should also test at least on WebKit and Firefox once #4235 is fixed). Add a couple of basic tests for `@linera/client`: getting a wallet from the faucet and initializing the client. ## Test Plan This is the test plan :) ## Release Plan - These changes should be backported to the latest `testnet` branch, then - be released in a new SDK. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 893b55b commit 59e2513

File tree

19 files changed

+1713
-44
lines changed

19 files changed

+1713
-44
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ jobs:
7272
run: |
7373
cargo run --release -p linera-storage-service -- memory --endpoint $LINERA_STORAGE_SERVICE &
7474
- name: Wait for storage service to be ready
75-
run: |
76-
STORAGE_HOST=$(echo "$LINERA_STORAGE_SERVICE" | cut -d: -f1)
77-
STORAGE_PORT=$(echo "$LINERA_STORAGE_SERVICE" | cut -d: -f2)
78-
until nc -z "$STORAGE_HOST" "$STORAGE_PORT"; do sleep 1; done
75+
run: until nc -z ${LINERA_STORAGE_SERVICE/:/ }; do sleep 1; done
7976
- name: Build binaries
8077
run: |
8178
cargo build --features storage-service --bin linera-server --bin linera-proxy --bin linera

.github/workflows/web.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ jobs:
5959
needs: changed-files
6060
if: needs.changed-files.outputs.should-run == 'true'
6161
runs-on: ubuntu-latest
62-
timeout-minutes: 20
62+
timeout-minutes: 30
6363

6464
steps:
65+
# Install dependencies
6566
- uses: actions/checkout@v4
6667
- name: Switch to nightly Rust toolchain
6768
run: |
@@ -80,12 +81,37 @@ jobs:
8081
- name: Install pnpm
8182
uses: pnpm/action-setup@v4
8283
with:
83-
version: 10
84+
version: 10.17
8485

86+
# Setup fixtures
87+
- name: Run the storage-service instance
88+
run: |
89+
cargo run --release -p linera-storage-service -- memory --endpoint $LINERA_STORAGE_SERVICE &
90+
- name: Wait for storage service to be ready
91+
run: until nc -z ${LINERA_STORAGE_SERVICE/:/ }; do sleep 1; done
92+
- name: Build binaries
93+
run: |
94+
cargo build --features storage-service --bin linera-server --bin linera-proxy --bin linera
95+
- name: Run the validators and faucet, wait for faucet to be ready
96+
run: |
97+
FAUCET_PORT=$(echo "$LINERA_FAUCET_URL" | cut -d: -f3)
98+
LOG_FILE="/tmp/linera-net-up.log"
99+
mkdir /tmp/local-linera-net
100+
cargo run --features storage-service --bin linera -- net up --storage service:tcp:$LINERA_STORAGE_SERVICE:table --policy-config testnet --path /tmp/local-linera-net --validators 2 --shards 2 --with-faucet --faucet-port $FAUCET_PORT --faucet-amount 1000 > "$LOG_FILE" 2>&1 &
101+
FAUCET_PID=$!
102+
bash scripts/wait-for-kubernetes-service.sh "$LINERA_FAUCET_URL" "$FAUCET_PID" "$LOG_FILE"
103+
# Create two epochs
104+
# See https://github.com/linera-io/linera-protocol/pull/2835 for details.
105+
LINERA_STORAGE=rocksdb:/tmp/local-linera-net/client_1.db cargo run --bin linera -- storage initialize --genesis /tmp/local-linera-net/genesis.json
106+
LINERA_STORAGE=rocksdb:/tmp/local-linera-net/client_1.db cargo run --bin linera -- resource-control-policy --http-request-timeout-ms 1000
107+
LINERA_STORAGE=rocksdb:/tmp/local-linera-net/client_1.db cargo run --bin linera -- resource-control-policy --http-request-timeout-ms 500
108+
109+
# Run tests
85110
- name: Test the npm packages
86111
run: |
87112
cd web
88113
pnpm install --frozen-lockfile
114+
(cd @linera/client && pnpm exec playwright install)
89115
pnpm -r run ci
90116
- name: Test `linera-views` on the Web
91117
run: |

default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ crane, pkgs, rust-toolchain, libclang, rocksdb, git, system, nix-gitignore }:
1+
{ crane, pkgs, rust-toolchain, libclang, rocksdb, git, system, nix-gitignore, playwright-driver }:
22
((crane.mkLib pkgs).overrideToolchain rust-toolchain).buildPackage {
33
pname = "linera";
44
src = nix-gitignore.gitignoreSource [] (builtins.path {
@@ -38,4 +38,5 @@
3838
RUST_SRC_PATH = rust-toolchain.availableComponents.rust-src;
3939
LIBCLANG_PATH = "${libclang.lib}/lib";
4040
ROCKSDB_LIB_DIR = "${rocksdb}/lib";
41+
PLAYWRIGHT_BROWSERS_PATH = "${playwright-driver.browsers}";
4142
}

examples/counter/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ <h2>Chain history for <code id="chain-id" class="hex">requesting chain…</code>
6464
console.log(linera);
6565
await linera.initialize();
6666
const faucet = await new linera.Faucet(import.meta.env.LINERA_FAUCET_URL);
67-
const mnemonic = ethers.Wallet.createRandom().mnemonic.phrase;
68-
const signer = linera.PrivateKeySigner.fromMnemonic(mnemonic);
67+
const signer = linera.PrivateKeySigner.createRandom();
6968
const wallet = await faucet.createWallet();
7069
const owner = await signer.address();
7170
document.getElementById('owner').innerText = owner;

flake.lock

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

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
export RUST_SRC_PATH="${linera.RUST_SRC_PATH}"
6363
export LIBCLANG_PATH="${linera.LIBCLANG_PATH}"
6464
export ROCKSDB_LIB_DIR="${linera.ROCKSDB_LIB_DIR}"
65+
export PLAYWRIGHT_BROWSERS_PATH="${linera.PLAYWRIGHT_BROWSERS_PATH}"
6566
'';
6667
nativeBuildInputs = [ pkgs.rust-analyzer ];
6768
};

web/@linera/client/docs/assets/hierarchy.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)