-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
clientMode-option.test.js
102 lines (92 loc) · 2.58 KB
/
clientMode-option.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
const config = require('../fixtures/simple-config/webpack.config');
const port = require('../ports-map')['clientMode-option'];
describe('clientMode option', () => {
let mockedTestServer;
let testServer;
let getSocketClientPath;
const clientModes = [
{
title: 'as a string ("sockjs")',
clientMode: 'sockjs',
shouldThrow: false,
},
{
title: 'as a path ("sockjs")',
clientMode: require.resolve('../../client-src/clients/SockJSClient'),
shouldThrow: false,
},
{
title: 'as a nonexistent path',
clientMode: '/bad/path/to/implementation',
shouldThrow: true,
},
];
describe('is passed to getSocketClientPath correctly', () => {
beforeEach(() => {
jest.mock('../../lib/utils/getSocketClientPath');
// eslint-disable-next-line global-require
getSocketClientPath = require('../../lib/utils/getSocketClientPath');
});
afterEach((done) => {
jest.resetAllMocks();
jest.resetModules();
mockedTestServer.close(done);
});
clientModes.forEach((data) => {
it(data.title, (done) => {
// eslint-disable-next-line global-require
mockedTestServer = require('../helpers/test-server');
mockedTestServer.start(
config,
{
inline: true,
clientMode: data.clientMode,
port,
},
() => {
expect(getSocketClientPath.mock.calls.length).toEqual(1);
expect(getSocketClientPath.mock.calls[0].length).toEqual(1);
expect(getSocketClientPath.mock.calls[0][0].clientMode).toEqual(
data.clientMode
);
done();
}
);
});
});
});
describe('passed to server', () => {
beforeAll(() => {
jest.unmock('../../lib/utils/getSocketClientPath');
// eslint-disable-next-line global-require
testServer = require('../helpers/test-server');
});
afterEach((done) => {
testServer.close(done);
});
clientModes.forEach((data) => {
it(`${data.title} ${
data.shouldThrow ? 'should throw' : 'should not throw'
}`, (done) => {
const res = () => {
testServer.start(
config,
{
inline: true,
clientMode: data.clientMode,
port,
},
done
);
};
if (data.shouldThrow) {
expect(res).toThrow(/clientMode must be a string/);
done();
} else {
expect(res).not.toThrow();
}
});
});
});
});