Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ jobs:

- run: npm ci
- run: npm run typecheck
- run: npm test
- run: npm run build
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
release:
name: Build & Publish
runs-on: ubuntu-latest
# NPM_TOKEN lives in the 'publish' environment — the job must reference it to
# access that environment's secrets.
environment: publish
permissions:
contents: write
id-token: write # npm provenance
Expand Down Expand Up @@ -44,11 +47,12 @@ jobs:
echo "skip=false" >> "$GITHUB_OUTPUT"
fi

- name: Install & build
- name: Install, test & build
if: steps.check.outputs.skip == 'false'
run: |
npm ci
npm run typecheck
npm test
npm run build

- name: Publish to npm
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ interface WebGUIClient {
webviewMode: 'GUI_SCREEN' | 'HUD_OVERLAY' | 'NONE';
dimension: string; // e.g. "minecraft:overworld"
pos: { x: number; y: number; z: number };
look: { yaw: number; pitch: number }; // head rotation, degrees
health: number; // current HP (0–maxHealth)
maxHealth: number; // max HP
food: number; // hunger level (0–20)
xpLevel: number; // experience level
gamemode?: 'survival' | 'creative' | 'adventure' | 'spectator';
server?: {
address?: string; // server address
ping?: number; // ping in ms
Expand Down Expand Up @@ -137,6 +143,8 @@ import type {
WebGUIClient,
WebGUINamespace,
WebviewMode,
Gamemode,
Look,
PostToGamePayload,
Vec3,
ServerInfo,
Expand Down
24 changes: 24 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Testing

Unit tests for the `@webgui/react` library, run with
[Vitest](https://vitest.dev) in a jsdom environment.

```bash
npm test # run once
npm run test:watch
```

## What's covered (`test/`)

| File | Covers |
|------|--------|
| `utils.test.ts` | `isInMod`, `isReady` |
| `store.test.ts` | Client store: pre-injected value, `webgui:client` events, subscribe/unsubscribe |
| `entityStore.test.ts` | Entity store: injection, `webgui:entity` events, clearing to `null` |
| `hooks.test.tsx` | All hooks — `useWebGUIClient`, `useWebGUIEntity`, `useWebGUISelector` (incl. memoization + custom `equalFn`), `usePostToGame`, `useCloseGui`, `useWebGUIToken`, `useWebGUIEvent` |

`test/helpers.ts` provides `installWebgui()` (a spy-backed fake `window.webgui`)
and event emitters that mimic the mod's injected runtime, so the hooks are
exercised exactly as they would be inside Minecraft.

CI runs `npm test` in `.github/workflows/ci.yml`.
Loading
Loading