Skip to content
Docs pages

Developers · Guides

Testing

Run your game in standalone mode, mirror the production layout on your machine, run it on the portal, and use test hooks, the conformance game and a Playwright smoke test.

On this page

Thanks to the SDK's standalone mode you can test almost all of your integration without the portal. What only the portal provides (anti-cheat rules, the ad cooldown, server-side storage) is tested on the staging portal.

Standalone mode

Open the game directly, outside the portal iframe, and the SDK runs in standalone mode:

  • The player is local-<id>, kept in localStorage (key wsg:local-id).
  • The leaderboard lives in localStorage under wsg:<gameId>:lb; storage under wsg:<gameId>:storage:<key>. Delete these keys in DevTools to start over.
  • Fake ads wait 1 second and return shown: true; rewarded ads always come with rewarded: true.
  • Switching tabs still emits visibility and pause/resume.
  • There are no server anti-cheat rules, ad cooldown or event limits.

Initialize with debug: true to see [WSG] logs in the console (ignored calls, invalid track names, scores submitted outside gameplay…). Add ?lang=en to the URL to test languages, or your own parameters (?level=3) and read them with WSG.getEntryParams().

Running locally with the production layout

On the games origin, the SDK lives at /sdk/v1/wsg-sdk.js and your game at /<slug>/<version>/. Recreate exactly that layout on your machine to catch absolute-path bugs early:

Bash
mkdir -p play-local/sdk/v1 play-local/tap-rush/1.0.0
curl -o play-local/sdk/v1/wsg-sdk.js https://games.leonogames.com/sdk/v1/wsg-sdk.js
cp -R dist/. play-local/tap-rush/1.0.0/
python3 -m http.server 8080 --directory play-local
# open http://localhost:8080/tap-rush/1.0.0/

Any static server works (npx serve play-local, nginx…) as long as it serves the play-local folder at its root. When your game works here, it will work under https://games.leonogames.com.

Tip

While developing with your own dev server (Vite, webpack), you can temporarily point the script tag at the full URL https://games.leonogames.com/sdk/v1/wsg-sdk.js. Remember to switch back to /sdk/v1/wsg-sdk.js before building your submission.

Running on the portal

External studios: send your build to the operations team to have it deployed to the staging environment. Once it is on the games origin you can open it directly at https://games.leonogames.com/<slug>/<version>/index.html (it runs in standalone mode); once the game is opened to players, its page is at https://leonogames.com/games/<slug>.

Portal test mode: open the game page with ?wsg_test=1, for example https://leonogames.com/games/<slug>?wsg_test=1. The portal forwards this parameter to the iframe URL, so the kill() test hook works on the portal and WSG.getEntryParams() contains wsg_test: '1'.

What to check on the portal:

  • WSG.environment is portal; the loading overlay disappears exactly when you call loadingFinished().
  • Scores are accepted (check the reason when one is rejected); the leaderboard tab below the game frame updates after a submission.
  • Two interstitials in a row: the second returns cooldown. Press Esc while a rewarded ad runs: dismissed, no reward.
  • Switch tabs: the portal shows its "Paused" overlay and your game receives pause, then resume. Call WSG.leaderboard.show(): your game receives pause when the dialog opens and resume when it closes.
  • Open https://leonogames.com/games/<slug>?ref=share&score=42: WSG.getEntryParams() contains ref and score.
  • Reload the page and play again: your WSG.storage data is still there.

Internal teams with the repository can run the whole system locally:

Bash
pnpm install
pnpm db:migrate && pnpm db:seed     # needs Postgres and Redis running
pnpm sync:sdk                       # build the SDK for the games-server
pnpm dev                            # api :4100, web :3000, games-server :4000
pnpm wsg publish games/my-game      # another terminal; reads WSG_ADMIN_TOKEN... from the repo root .env
# open http://localhost:3000/games/my-game

Test hooks

Test hooks are an object attached to window.__WSG_TEST__ so automated tools (Playwright, the portal's test pipeline) can drive your game without clicking on the canvas. They are required for games in the Leono Games repository (the template ships with them) and recommended for external studios, because they help the operations team review your game faster.

TypeScript
interface WsgTestHooks {
  ready: true;
  getState(): {
    scene: 'boot' | 'preload' | 'menu' | 'game' | 'gameover' | string;
    score: number;
    alive: boolean;
    [k: string]: unknown;
  };
  start(): void; // from the menu (or game over) into gameplay
  input(action: 'tap' | 'left' | 'right' | 'up' | 'down' | 'pause', opts?: { x?: number; y?: number }): void;
  setSeed(seed: number): void; // deterministic RNG, call before start()
  setTimeScale(scale: number): void; // speed the game up for faster tests, e.g. 5
  kill(): void; // force game over immediately
}
  • Attach the hooks once the menu is ready (after loadingFinished()), with ready: true.
  • getState().scene is the current screen name in lowercase; you may add fields of your own.
  • kill() may only take effect when WSG.environment !== 'portal' or the URL has ?wsg_test=1, so nobody can force a game over on the real portal.

Here is how to add hooks to the Tap Rush game from Quick start. First make two small edits in game.js: add let random = Math.random; and use random() instead of Math.random() in moveTarget(); add timeScale: 1 to state and change the countdown line to state.timeLeft -= dt * state.timeScale;. Then add the code below and call installTestHooks() at the end of boot():

JavaScriptgame.js (additions)
function mulberry32(seed) {
  let a = seed >>> 0;
  return function () {
    a = (a + 0x6d2b79f5) >>> 0;
    let t = a;
    t = Math.imul(t ^ (t >>> 15), t | 1);
    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

function installTestHooks() {
  window.__WSG_TEST__ = {
    ready: true,
    getState: () => ({
      scene: state.phase === 'playing' ? 'game' : state.phase === 'over' ? 'gameover' : 'menu',
      score: state.score,
      alive: state.phase === 'playing',
      timeLeft: state.timeLeft,
    }),
    start: () => {
      if (state.phase !== 'playing' && !state.busy) startRound();
    },
    input: (action) => {
      if (action === 'tap' && state.phase === 'playing' && !state.paused) {
        state.score += 1;
        moveTarget();
      }
    },
    setSeed: (seed) => {
      random = mulberry32(seed);
    },
    setTimeScale: (scale) => {
      state.timeScale = scale;
    },
    kill: () => {
      const testMode = new URLSearchParams(location.search).get('wsg_test') === '1';
      if (WSG.environment === 'portal' && !testMode) return; // never force game over on the real portal
      if (state.phase === 'playing') state.timeLeft = 0;
    },
  };
}

The conformance game

_conformance is a plain HTML and JavaScript page, with no build step, that calls every SDK API in order and displays each step's result (one box per step with a data-testid named after the function and a data-status of ok or fail), while counting the pause, resume, audio, visibility and authchange events. It has a button to run each API by hand, and ?autorun=1 runs a full pass when opened directly.

The steps, in order: init → loadingStart → loadingProgress(50) → loadingFinished → gameplayStart → track('conformance_ping') → storage.set({ k: 1 }) → storage.get('k') → leaderboard.submit(<1..1000>) → leaderboard.top → leaderboard.me → gameplayStop → ads.interstitial → a second ads.interstitial (expected to return cooldown on the portal) → ads.rewarded → share → player.getToken.

Use it as a reference implementation when comparing your game's behavior: on the portal at https://leonogames.com/games/_conformance (if it is released in that environment), or directly at https://games.leonogames.com/_conformance/<version>/?autorun=1 (the current version is shown on the game page). Its source lives in games/_conformance in the repository.

Smoke testing with Playwright

The portal's standard smoke test: open the game, wait for the hooks, play a round through the hooks, force a game over, take a screenshot and make sure there were no console errors. It runs against the play-local folder from running locally.

TypeScriptplaywright.config.ts
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './e2e',
  use: { baseURL: 'http://localhost:8080' },
  projects: [
    { name: 'desktop', use: { ...devices['Desktop Chrome'] } },
    { name: 'mobile', use: { ...devices['Pixel 7'] } },
  ],
  webServer: {
    command: 'python3 -m http.server 8080 --directory play-local',
    url: 'http://localhost:8080/sdk/v1/wsg-sdk.js',
    reuseExistingServer: true,
  },
});
TypeScripte2e/smoke.spec.ts
import { expect, test } from '@playwright/test';

declare global {
  interface Window {
    __WSG_TEST__?: {
      ready: true;
      getState(): { scene: string; score: number; alive: boolean; [k: string]: unknown };
      start(): void;
      input(action: 'tap' | 'left' | 'right' | 'up' | 'down' | 'pause', opts?: { x?: number; y?: number }): void;
      setSeed(seed: number): void;
      setTimeScale(scale: number): void;
      kill(): void;
    };
  }
}

test('smoke: menu → game → gameover, no console errors', async ({ page }, testInfo) => {
  const errors: string[] = [];
  page.on('console', (msg) => {
    if (msg.type() === 'error') errors.push(msg.text());
  });
  page.on('pageerror', (err) => errors.push(String(err)));

  await page.goto('/tap-rush/1.0.0/?wsg_test=1');
  await page.waitForFunction(() => window.__WSG_TEST__?.ready === true);
  expect(await page.evaluate(() => window.__WSG_TEST__!.getState().scene)).toBe('menu');

  await page.evaluate(() => {
    window.__WSG_TEST__!.setSeed(42);
    window.__WSG_TEST__!.start();
  });
  await page.waitForFunction(() => window.__WSG_TEST__!.getState().scene === 'game');

  for (let i = 0; i < 16; i++) {
    await page.evaluate(() => window.__WSG_TEST__!.input('tap'));
    await page.waitForTimeout(300);
    const s = await page.evaluate(() => window.__WSG_TEST__!.getState());
    expect(s.alive || s.scene === 'gameover').toBe(true);
  }

  await page.evaluate(() => window.__WSG_TEST__!.kill());
  await page.waitForFunction(() => window.__WSG_TEST__!.getState().scene === 'gameover');
  const final = await page.evaluate(() => window.__WSG_TEST__!.getState());
  expect(final.score).toBeGreaterThanOrEqual(0);
  await page.screenshot({ path: `e2e/__screenshots__/${testInfo.project.name}-gameover.png` });
  expect(errors).toEqual([]);
});
Bash
npm install -D @playwright/test
npx playwright install chromium
npx playwright test