refactor: update api
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
registry,
|
||||
createInitialState,
|
||||
start,
|
||||
TicTacToeState,
|
||||
WinnerType,
|
||||
PlayerType
|
||||
@@ -12,7 +13,7 @@ import { MutableSignal } from '@/utils/mutable-signal';
|
||||
|
||||
function createTestHost() {
|
||||
const host = createGameHost(
|
||||
{ registry, createInitialState }
|
||||
{ registry, createInitialState, start }
|
||||
);
|
||||
return { host };
|
||||
}
|
||||
@@ -59,7 +60,7 @@ describe('GameHost', () => {
|
||||
const { host } = createTestHost();
|
||||
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
const promptEvent = await promptPromise;
|
||||
expect(promptEvent.schema.name).toBe('play');
|
||||
@@ -81,7 +82,7 @@ describe('GameHost', () => {
|
||||
const { host } = createTestHost();
|
||||
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
const promptEvent = await promptPromise;
|
||||
|
||||
@@ -106,7 +107,7 @@ describe('GameHost', () => {
|
||||
const { host } = createTestHost();
|
||||
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
const promptEvent = await promptPromise;
|
||||
const schema = host.activePromptSchema.value;
|
||||
@@ -131,7 +132,7 @@ describe('GameHost', () => {
|
||||
|
||||
// First setup - make one move
|
||||
let promptPromise = waitForPromptEvent(host);
|
||||
let runPromise = host.context._commands.run('start');
|
||||
let runPromise = host.start();
|
||||
let promptEvent = await promptPromise;
|
||||
|
||||
// Make a move
|
||||
@@ -150,7 +151,7 @@ describe('GameHost', () => {
|
||||
const newPromptPromise = waitForPromptEvent(host);
|
||||
|
||||
// Reset - should reset state and start new game
|
||||
host.start('start');
|
||||
host.start();
|
||||
|
||||
// State should be back to initial
|
||||
expect(host.context._state.value.currentPlayer).toBe('X');
|
||||
@@ -168,12 +169,12 @@ describe('GameHost', () => {
|
||||
const { host } = createTestHost();
|
||||
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
await promptPromise;
|
||||
|
||||
// Setup should cancel the active prompt and reset state
|
||||
host.start('start');
|
||||
host.start();
|
||||
|
||||
// The original runPromise should be rejected due to cancellation
|
||||
try {
|
||||
@@ -192,7 +193,7 @@ describe('GameHost', () => {
|
||||
const { host } = createTestHost();
|
||||
host.dispose();
|
||||
|
||||
expect(() => host.start('start')).toThrow('GameHost is disposed');
|
||||
expect(() => host.start()).toThrow('GameHost is disposed');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -208,7 +209,7 @@ describe('GameHost', () => {
|
||||
const { host } = createTestHost();
|
||||
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
await promptPromise;
|
||||
|
||||
@@ -245,7 +246,7 @@ describe('GameHost', () => {
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
|
||||
// Initial setup via reset
|
||||
host.start('start');
|
||||
host.start();
|
||||
expect(setupCount).toBe(1);
|
||||
|
||||
// State should be running
|
||||
@@ -294,7 +295,7 @@ describe('GameHost', () => {
|
||||
|
||||
// Make a move
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
const promptEvent = await promptPromise;
|
||||
promptEvent.tryCommit({ name: 'play', params: ['X', 1, 1], options: {}, flags: {} });
|
||||
@@ -320,7 +321,7 @@ describe('GameHost', () => {
|
||||
|
||||
// Start a command that triggers prompt
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
await promptPromise;
|
||||
|
||||
@@ -369,7 +370,7 @@ describe('GameHost', () => {
|
||||
});
|
||||
|
||||
// Start setup command (runs game loop until completion)
|
||||
const setupPromise = host.context._commands.run('start');
|
||||
const setupPromise = host.start();
|
||||
|
||||
for (let i = 0; i < moves.length; i++) {
|
||||
// Wait until the next prompt event arrives
|
||||
@@ -415,7 +416,7 @@ describe('GameHost', () => {
|
||||
const { host } = createTestHost();
|
||||
|
||||
const promptPromise = waitForPromptEvent(host);
|
||||
const runPromise = host.context._commands.run('start');
|
||||
const runPromise = host.start();
|
||||
|
||||
const promptEvent = await promptPromise;
|
||||
expect(promptEvent.currentPlayer).toBe('X');
|
||||
|
||||
Reference in New Issue
Block a user