Skip to content

Commit 992be8e

Browse files
test: refactor
1 parent 42914b9 commit 992be8e

File tree

3 files changed

+82
-78
lines changed

3 files changed

+82
-78
lines changed

test/server/client-option.test.js

-4
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ describe('client option', () => {
216216
];
217217

218218
describe('passed to server', () => {
219-
beforeAll(() => {
220-
jest.unmock('../../lib/utils/getSocketClientPath');
221-
});
222-
223219
clientModes.forEach((data) => {
224220
it(`${data.title} ${
225221
data.shouldThrow ? 'should throw' : 'should not throw'

test/server/utils/DevServerPlugin.test.js

+82
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,86 @@ describe('DevServerPlugin util', () => {
265265

266266
expect(typeof entries === 'function').toBe(true);
267267
});
268+
269+
// 'npm run prepare' must be done for this test to pass
270+
const sockjsClientPath = require.resolve(
271+
'../../../client/clients/SockJSClient'
272+
);
273+
274+
describe('getWebsocketTransport', () => {
275+
it("should work with client.transport: 'sockjs'", () => {
276+
let result;
277+
278+
expect(() => {
279+
const devServerPlugin = new DevServerPlugin({
280+
client: {
281+
transport: 'sockjs',
282+
},
283+
webSocketServer: 'sockjs',
284+
});
285+
286+
result = devServerPlugin.getWebsocketTransport();
287+
}).not.toThrow();
288+
289+
expect(result).toEqual(sockjsClientPath);
290+
});
291+
292+
it('should work with client.transport: SockJSClient full path', () => {
293+
let result;
294+
295+
expect(() => {
296+
const devServerPlugin = new DevServerPlugin({
297+
client: {
298+
transport: sockjsClientPath,
299+
},
300+
webSocketServer: 'sockjs',
301+
});
302+
303+
result = devServerPlugin.getWebsocketTransport();
304+
}).not.toThrow();
305+
306+
expect(result).toEqual(sockjsClientPath);
307+
});
308+
309+
it('should throw with client.transport: bad path', () => {
310+
expect(() => {
311+
const devServerPlugin = new DevServerPlugin({
312+
client: {
313+
transport: '/bad/path/to/implementation',
314+
},
315+
webSocketServer: 'sockjs',
316+
});
317+
318+
devServerPlugin.getWebsocketTransport();
319+
}).toThrow(/client.transport must be a string/);
320+
});
321+
322+
it('should throw with transportMode.client: bad type', () => {
323+
expect(() => {
324+
const devServerPlugin = new DevServerPlugin({
325+
client: {
326+
transport: 1,
327+
},
328+
webSocketServer: 'sockjs',
329+
});
330+
331+
devServerPlugin.getWebsocketTransport();
332+
}).toThrow(/client.transport must be a string/);
333+
});
334+
335+
it('should throw with client.transport: unimplemented client', () => {
336+
expect(() => {
337+
const devServerPlugin = new DevServerPlugin({
338+
client: {
339+
transport: 'foo',
340+
},
341+
webSocketServer: 'sockjs',
342+
});
343+
344+
devServerPlugin.getWebsocketTransport();
345+
}).toThrow(
346+
'When you use custom web socket implementation you must explicitly specify client.transport'
347+
);
348+
});
349+
});
268350
});

test/server/utils/getSocketClientPath.test.js

-74
This file was deleted.

0 commit comments

Comments
 (0)