boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
10k stars 706 forks source link

vanilla Client assumes that arguments have been preprocessed by GetOpts #356

Closed nicolodavis closed 5 years ago

nicolodavis commented 5 years ago

https://github.com/nicolodavis/boardgame.io/blob/master/src/client/client.js#L219

This prevents it from being used directly with local multiplayer (useful in unit tests).

nicolodavis commented 5 years ago

A unit test (after fixing the above) currently looks like this:

  const client = Client({
    game: Game({
      moves: {
        A: (G, ctx, arg) => ({ arg }),
      },
    }),
    multiplayer: { local: true },
  });

  await client.updatePlayerID('0');
  await client.connect();

  expect(client.getState().G).toEqual({});
  client.moves.A(42);
  expect(client.getState().G).toEqual({ arg: 42 });

Perhaps we should bundle in a test-friendly client that is able to switch players more seamlessly without needing to call connect each time.

nicolodavis commented 5 years ago

Fixed (https://github.com/nicolodavis/boardgame.io/commit/9d11d6201770a2cb5b523fb77690c5021d2ce7d1).