本文へスキップ

API リファレンス ​

ts
import { afterEach, beforeEach, describe, expect, play, sleep, test } from "keiko";

テスト ​

test(name, fn, { timeout? })テスト。fn はたいてい async です。デフォルトのタイムアウトは実時間で 30 000 ms
test.only(name, fn)フォーカスしたテストだけを実行
test.skip(name, fn?)登録はするが実行しない
test.todo(name)レポートに載るリマインダー
test.sweep(name, grid, fn, options?)パラメータ値の組み合わせごとに 1 テスト。fn(game, values)
test.deterministic(name, script, options?)script(game) を 2 回プレイし、全ステップを比較。{ sameSeed: true } で Math.random を同じに保つ
describe(name, fn)テストをグループ化。describe.only と describe.skip は中のすべてに適用されます
beforeEach(fn) / afterEach(fn)ファイルまたは describe 内の各テストの前後に実行。beforeEach は外側が先、afterEach は内側が先で、失敗後も実行されます
sleep(ms)ゲームの実行中でも、実時間で待つ

play(options?) ​

Promise<Playtest<S>> を返します。S は game.state の型です。

オプションデフォルト
page"index.html"起動するページ
params{ "group.key": value }。最初のステップの前に設定
ready最初の読み込み完了(debuff:シーンがアクティブ)(game) => boolean。待つ間、Keiko はフレームをプレイします
timeout10000スクリプトの読み込み、続いて ready までの実時間の上限(ms)。指定しない場合、実行中の最初のゲームには読み込みに 60000 が与えられます。Vite による依存関係の事前バンドルも待つためです
seed1Math.random のシード
fps60仮想時計のフレームレート
webgltrue(debuff:false)WebGL コンテキストを提供する
viewport{ width: 960, height: 540 }ウィンドウサイズ

Playtest<S> ​

読み取り: state、scene、tick、time、get(path)、param(path)、params()、window、stepSeconds、driver、engine。engine はフックなしの Phaser 3 と PixiJS 8 で使え、scene、scenes、targets を持ちます(エンジンを参照)。

プレイ(どれも playtest を返します):

wait(duration = 1)プレイする
press(code), release(code)キーを押したままにする、離す
hold(code, duration)押して、待って、離す
tap(code), tap(x, y)1 ステップだけのキーまたはポインターの押下
pointerDown(x, y), pointerMove(x, y), pointerUp()ポインター
set(path, value), set(values)パラメータ
command(name, ...args)コマンドの結果を返す
replay(fileOrScenario)シナリオのステップをプレイする
await settle(timeout?)ゲームのリクエストが終わるまで実時間で待つ
await run(duration, { timeout? })フレームの合間に非同期コードと読み込みを完了させながらプレイする

問いかけ:

戻り値
until(condition, { within?, message? })かかったステップ数。within(デフォルト "10s")以内に成り立たなければ TimeoutError
await tapWhenReady(find, { within?, steady?, timeout? })playtest。find(game) の点({ x, y } またはエンジンのターゲット)が存在し、steady ステップ(デフォルト 10)動かずにいたらタップします。within(デフォルト "10s")以内にそうならなければ TimeoutError
await eventually(condition, { within?, message?, timeout? })かかったステップ数。until と同様ですが、フレームの合間に非同期コードと読み込みを完了させます
during(duration, check, message?)playtest。check が false を返すか例外を投げたステップで InvariantError
trace(pathOrFn, duration)Trace

duration はステップ数(30)か時間("0.5s"、"250ms")です。

Trace<T> ​

values、start、first、last、length、at(i)、min()、max()、range()、stepOf(valueOrPredicate)、every(fn)、some(fn)、changes()、timeAt(step)、イテレート可能。

expect(value) ​

toBe、toEqual、toBeAbove、toBeBelow、toBeAtLeast、toBeAtMost、toBeBetween、toBeCloseTo(target, tolerance = 0.001)、toBeTruthy、toBeFalsy、toBeDefined、toBeUndefined、toContain、toHaveLength、toMatch、toThrow(message?)、そして .not。

エラー ​

ExpectationErroractual、expected
GameErrorゲームが例外を投げた:tick、scene、cause
TimeoutErroruntil が時間切れになった
InvariantErrorduring が不変条件の破れを捕まえた
MissingHookErrorゲームが公開していないフックをテストが使った

window.__KEIKO__ ​

state()、scene()、step(n) + stepSeconds、press(code)、release(code)、pointerDown(x, y)、pointerMove(x, y)、pointerUp()、params()、setParam(group, key, value)、command(name, ...args)。すべて任意です。ゲームを公開するを見てください。

CLI ​

text
keiko [files or folders...] [options]

  -t, --filter <text>   Only tests whose name contains this text
      --root <dir>      Project root (default: current folder)
      --json            Machine-readable report
      --debuff          Drive through debuff's dev hooks (default: detected)
      --no-debuff       Drive through __KEIKO__ and the virtual clock
  -h, --help

keiko/runner ​

ts
import { findTests, formatResult, formatSummary, runTests } from "keiko/runner";

const report = await runTests({ root, files?, filter?, vite?, debuff?, onResult? });
// { ok, passed, failed, skipped, todo, durationMs, results, outside }