Skip to content

Commit 20817aa

Browse files
committed
fix(transport): More accurately type TransportOpts
1 parent 7b15179 commit 20817aa

4 files changed

Lines changed: 50 additions & 8 deletions

File tree

src/client/transport/local.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ describe('LocalTransport', () => {
283283
const transport = new WrappedLocalTransport({
284284
master,
285285
transportDataCallback: () => {},
286+
game: ProcessGameConfig({}),
287+
gameKey: {},
286288
});
287289
jest.spyOn(transport, 'requestSync');
288290

src/client/transport/socketio.test.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type * as ioNamespace from 'socket.io-client';
1111
import { makeMove } from '../../core/action-creators';
1212
import type { Master } from '../../master/master';
1313
import type { ChatMessage, State } from '../../types';
14+
import { ProcessGameConfig } from '../../core/game';
1415

1516
jest.mock('../../core/logger', () => ({
1617
info: jest.fn(),
@@ -41,7 +42,11 @@ class MockSocket {
4142
}
4243

4344
test('defaults', () => {
44-
const m = new SocketIOTransport({ transportDataCallback: () => {} });
45+
const m = new SocketIOTransport({
46+
transportDataCallback: () => {},
47+
game: ProcessGameConfig({}),
48+
gameKey: {},
49+
});
4550
expect(typeof (m as any).connectionStatusCallback).toBe('function');
4651
(m as any).connectionStatusCallback();
4752
});
@@ -66,7 +71,12 @@ class TransportAdapter extends SocketIOTransport {
6671

6772
describe('update matchID / playerID / credentials', () => {
6873
const socket = new MockSocket();
69-
const m = new TransportAdapter({ socket, transportDataCallback: () => {} });
74+
const m = new TransportAdapter({
75+
socket,
76+
transportDataCallback: () => {},
77+
game: ProcessGameConfig({}),
78+
gameKey: {},
79+
});
7080

7181
beforeEach(() => (socket.emit = jest.fn()));
7282

@@ -105,6 +115,8 @@ describe('connection status', () => {
105115
matchID: '0',
106116
playerID: '0',
107117
gameName: 'foo',
118+
game: ProcessGameConfig({}),
119+
gameKey: {},
108120
numPlayers: 2,
109121
transportDataCallback: () => {},
110122
});
@@ -133,7 +145,11 @@ describe('connection status', () => {
133145

134146
test('doesn’t crash if syncing before connecting', () => {
135147
const transportDataCallback = jest.fn();
136-
const transport = new SocketIOTransport({ transportDataCallback });
148+
const transport = new SocketIOTransport({
149+
transportDataCallback,
150+
game: ProcessGameConfig({}),
151+
gameKey: {},
152+
});
137153
transport.requestSync();
138154
expect(transportDataCallback).not.toHaveBeenCalled();
139155
});
@@ -145,6 +161,8 @@ describe('multiplayer', () => {
145161
const transport = new TransportAdapter({
146162
socket: mockSocket,
147163
transportDataCallback,
164+
game: ProcessGameConfig({}),
165+
gameKey: {},
148166
});
149167
transport.connect();
150168

@@ -216,6 +234,8 @@ describe('multiplayer delta state', () => {
216234
const transport = new TransportAdapter({
217235
socket: mockSocket,
218236
transportDataCallback,
237+
game: ProcessGameConfig({}),
238+
gameKey: {},
219239
});
220240
transport.connect();
221241

@@ -243,7 +263,12 @@ describe('server option', () => {
243263

244264
test('without protocol', () => {
245265
const server = hostname + ':' + port;
246-
const m = new TransportAdapter({ server, transportDataCallback: () => {} });
266+
const m = new TransportAdapter({
267+
server,
268+
transportDataCallback: () => {},
269+
game: ProcessGameConfig({}),
270+
gameKey: {},
271+
});
247272
m.connect();
248273
expect(m.socket.io.engine.hostname).toEqual(hostname);
249274
expect(m.socket.io.engine.port).toEqual(port);
@@ -255,6 +280,8 @@ describe('server option', () => {
255280
const m = new SocketIOTransport({
256281
server,
257282
transportDataCallback: () => {},
283+
game: ProcessGameConfig({}),
284+
gameKey: {},
258285
});
259286
m.connect();
260287
expect((m.socket.io as any).uri).toEqual(server + '/default');
@@ -265,6 +292,8 @@ describe('server option', () => {
265292
const m = new TransportAdapter({
266293
server: serverWithProtocol,
267294
transportDataCallback: () => {},
295+
game: ProcessGameConfig({}),
296+
gameKey: {},
268297
});
269298
m.connect();
270299
expect(m.socket.io.engine.hostname).toEqual(hostname);
@@ -277,6 +306,8 @@ describe('server option', () => {
277306
const m = new TransportAdapter({
278307
server: serverWithProtocol,
279308
transportDataCallback: () => {},
309+
game: ProcessGameConfig({}),
310+
gameKey: {},
280311
});
281312
m.connect();
282313
expect(m.socket.io.engine.hostname).toEqual(hostname);
@@ -285,7 +316,11 @@ describe('server option', () => {
285316
});
286317

287318
test('no server set', () => {
288-
const m = new TransportAdapter({ transportDataCallback: () => {} });
319+
const m = new TransportAdapter({
320+
transportDataCallback: () => {},
321+
game: ProcessGameConfig({}),
322+
gameKey: {},
323+
});
289324
m.connect();
290325
expect(m.socket.io.engine.hostname).not.toEqual(hostname);
291326
expect(m.socket.io.engine.port).not.toEqual(port);

src/client/transport/transport.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Transport } from './transport';
2+
import { ProcessGameConfig } from '../../core/game';
23

34
describe('Transport', () => {
45
class SimpleTransport extends Transport {
@@ -16,7 +17,11 @@ describe('Transport', () => {
1617
}
1718

1819
test('base class sets up callbacks', () => {
19-
const transport = new SimpleTransport({ transportDataCallback: () => {} });
20+
const transport = new SimpleTransport({
21+
transportDataCallback: () => {},
22+
game: ProcessGameConfig({}),
23+
gameKey: {},
24+
});
2025
expect(transport.get('connectionStatusCallback')()).toBeUndefined();
2126
});
2227
});

src/client/transport/transport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export type ChatCallback = (message: ChatMessage) => void;
2424
export interface TransportOpts {
2525
transportDataCallback: (data: TransportData) => void;
2626
gameName?: string;
27-
gameKey?: Game;
28-
game?: ReturnType<typeof ProcessGameConfig>;
27+
gameKey: Game;
28+
game: ReturnType<typeof ProcessGameConfig>;
2929
playerID?: PlayerID;
3030
matchID?: string;
3131
credentials?: string;

0 commit comments

Comments
 (0)