Skip to content

Testing

Test against the real platform from your own machine, without running any of it: the store preview and dev keys work for draft games, for the members of their creator only. For automated tests in Node, the SDK has a fake store.

The store preview (recommended)

On your game's page in the console, open Preview and enter the address your game runs at, for example http://localhost:5173. The store frames it exactly as it frames a published game: the same sandbox, the same messages, real play tokens in preview mode. Your code needs no special mode and holds no secret.

The self-check next to the frame reports:

  • whether the address is https (or localhost, which is fine for testing);
  • whether your game said ready within 10 seconds, and the likely reasons when it did not;
  • the SDK version it reported;
  • whether a play token was delivered, and whether a model call finished;
  • any blocked events, such as running out of credits.

Safari

Browsers let an https page frame http://localhost, except Safari. Use another browser, or serve your game locally over https.

Dev keys

For quick starts and automated tests, open the page on its own on localhost and pass a dev key. Create one on your game's page (Dev keys tab); the full key is shown once.

const playium = await Playium.init({
  devKey: import.meta.env.DEV ? import.meta.env.VITE_PLAYIUM_DEV_KEY : undefined,
});

Inside the store the key is ignored; on any other address init() rejects with dev_key_not_allowed.

  • A key works for one draft game, and only from a page on http://localhost or http://127.0.0.1 (any port).
  • It lives 1 to 30 days and can be revoked at any time; at most 5 keys are alive per game.
  • It sits in client code, so keep it out of your repository and out of builds you publish.

In Node, without a browser

@playium/sdk/testing (or playium-testing.mjs next to playium.mjs) is a fake store and gateway for your automated tests. install() puts a fake framed window and a fake fetch on globalThis, so your game's own code, which calls Playium.init() with no options, runs unchanged under Node's test runner, Vitest or Jest. It runs the SDK's real code; only the store and the network are fake, and nothing is charged.

game.test.js
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createFakeStore } from '@playium/sdk/testing';
import { startGame } from '../src/game.js'; // your code, which calls Playium.init()

test('a refused call shows the store prompt and keeps the game', async (t) => {
  const store = createFakeStore({ reply: (request) => 'Who is there?', lang: 'ja' }).install();
  t.after(() => store.uninstall());

  const game = await startGame();
  store.refuseNext('insufficient_credits');
  await game.knock();

  assert.deepEqual(store.received, ['ready', 'blocked', 'model-call-finished']);
  store.unblock('insufficient_credits'); // what the store sends once the player added credits
});
Fake storeWhat it does
createFakeStore({ reply, player, mode, access, lang, standalone, silent })reply(request) answers each model call with text (streamed word by word when asked), a refusal { status, code } or a Response; standalone opens the page on its own; silent never answers.
received, messages, chatRequests, saves, tokensWhat the game told the store, the model calls as sent, the cloud saves, the tokens handed out.
refuseNext(code), failNextToken(code)Refuses the next model call, or the next token request (init() then rejects with code).
unblock(reason), pushToken(access?)Sends unblocked, or a new token unasked.

It cannot show you your game in the store's frame: use the store preview for that.

Who pays for test calls

You do, with the credits of the account you sign in with, the same credits a player spends. A dev key is charged to the member who created it, so a leaked key can only spend that member's credits. A round of testing usually costs a credit or two.

Next: What your game must allow