Skip to content

Commit 7405bb6

Browse files
test: update schema
1 parent 81a4f7a commit 7405bb6

20 files changed

+467
-425
lines changed

lib/Server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const compress = require('compression');
1616
const serveIndex = require('serve-index');
1717
const webpack = require('webpack');
1818
const webpackDevMiddleware = require('webpack-dev-middleware');
19-
const getFilenameFromUrl =
20-
require('webpack-dev-middleware/dist/utils/getFilenameFromUrl').default;
19+
const getFilenameFromUrl = require('webpack-dev-middleware/dist/utils/getFilenameFromUrl')
20+
.default;
2121
const { validate } = require('schema-utils');
2222
const DevServerPlugin = require('./utils/DevServerPlugin');
2323
const normalizeOptions = require('./utils/normalizeOptions');
@@ -580,7 +580,7 @@ class Server {
580580

581581
if (!headers) {
582582
this.logger.warn(
583-
'transportMode.server implementation must pass headers to the callback of onConnection(f) ' +
583+
'webSocketServer implementation must pass headers to the callback of onConnection(f) ' +
584584
'via f(connection, headers) in order for clients to pass a headers security check'
585585
);
586586
}

lib/utils/getSocketClientPath.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ function getSocketClientPath(options) {
44
let ClientImplementation;
55
let clientImplementationFound = true;
66

7-
const clientTransport =
8-
options.client.transport || options.webSocketServer.type;
7+
const isKnownWebSocketServerImplementation =
8+
typeof options.webSocketServer.type === 'string' &&
9+
(options.webSocketServer.type === 'ws' ||
10+
options.webSocketServer.type === 'sockjs');
11+
12+
let clientTransport;
13+
14+
if (typeof options.client.transport !== 'undefined') {
15+
clientTransport = options.client.transport;
16+
} else if (isKnownWebSocketServerImplementation) {
17+
clientTransport = options.webSocketServer.type;
18+
}
919

1020
switch (typeof clientTransport) {
1121
case 'string':
@@ -29,9 +39,11 @@ function getSocketClientPath(options) {
2939

3040
if (!clientImplementationFound) {
3141
throw new Error(
32-
"client.transport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to " +
33-
'a JS file which exports a class extending BaseClient (webpack-dev-server/client-src/clients/BaseClient.js) ' +
34-
'via require.resolve(...)'
42+
`${
43+
!isKnownWebSocketServerImplementation
44+
? 'When you use custom web socket implementation you must explicitly specify client.transport. '
45+
: ''
46+
}client.transport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file which exports a class extending BaseClient (webpack-dev-server/client-src/clients/BaseClient.js) via require.resolve(...)`
3547
);
3648
}
3749

test/e2e/Socket-injection.test.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ const port = require('../ports-map').SocketInjection;
1212
const config = require('../fixtures/client-config/webpack.config');
1313
const { beforeBrowserCloseDelay } = require('../helpers/puppeteer-constants');
1414

15-
const transportModeWSValidOptions = [{}, { client: { trannsport: 'ws' } }];
15+
const transportModeWSValidOptions = [
16+
{},
17+
{ webSocketServer: 'ws' },
18+
{ webSocketServer: { type: 'ws' } },
19+
];
1620

1721
describe('ws websocket client injection', () => {
1822
for (const wsOption of transportModeWSValidOptions) {
@@ -271,9 +275,7 @@ describe('sockjs websocket client injection', () => {
271275
beforeAll((done) => {
272276
const options = {
273277
port,
274-
client: {
275-
transport: 'sockjs',
276-
},
278+
webSocketServer: 'sockjs',
277279
};
278280
server = testServer.start(config, options, done);
279281
req = request(`http://localhost:${port}`);
@@ -291,9 +293,7 @@ describe('sockjs websocket client injection', () => {
291293
const options = {
292294
port,
293295
liveReload: true,
294-
client: {
295-
transport: 'sockjs',
296-
},
296+
webSocketServer: 'sockjs',
297297
};
298298
server = testServer.start(config, options, done);
299299
req = request(`http://localhost:${port}`);
@@ -311,9 +311,7 @@ describe('sockjs websocket client injection', () => {
311311
const options = {
312312
port,
313313
liveReload: false,
314-
client: {
315-
transport: 'sockjs',
316-
},
314+
webSocketServer: 'sockjs',
317315
};
318316
server = testServer.start(config, options, done);
319317
req = request(`http://localhost:${port}`);
@@ -331,9 +329,7 @@ describe('sockjs websocket client injection', () => {
331329
const options = {
332330
port,
333331
hot: true,
334-
client: {
335-
transport: 'sockjs',
336-
},
332+
webSocketServer: 'sockjs',
337333
};
338334
server = testServer.start(config, options, done);
339335
req = request(`http://localhost:${port}`);
@@ -352,9 +348,7 @@ describe('sockjs websocket client injection', () => {
352348
port,
353349
hot: true,
354350
liveReload: false,
355-
client: {
356-
transport: 'sockjs',
357-
},
351+
webSocketServer: 'sockjs',
358352
};
359353
server = testServer.start(config, options, done);
360354
req = request(`http://localhost:${port}`);
@@ -373,9 +367,7 @@ describe('sockjs websocket client injection', () => {
373367
port,
374368
hot: false,
375369
liveReload: true,
376-
client: {
377-
transport: 'sockjs',
378-
},
370+
webSocketServer: 'sockjs',
379371
};
380372
server = testServer.start(config, options, done);
381373
req = request(`http://localhost:${port}`);
@@ -394,9 +386,7 @@ describe('sockjs websocket client injection', () => {
394386
port,
395387
hot: false,
396388
liveReload: false,
397-
client: {
398-
transport: 'sockjs',
399-
},
389+
webSocketServer: 'sockjs',
400390
};
401391
server = testServer.start(config, options, done);
402392
req = request(`http://localhost:${port}`);

test/e2e/TransportMode.test.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,28 @@ describe('transportMode client', () => {
1515
title: 'sockjs',
1616
options: {
1717
hot: false,
18-
client: {
19-
transport: 'sockjs',
20-
},
18+
client: { transport: 'sockjs' },
19+
webSocketServer: 'sockjs',
2120
},
2221
},
2322
{
2423
title: 'ws',
24+
options: {
25+
hot: false,
26+
client: { transport: 'ws' },
27+
webSocketServer: 'ws',
28+
},
29+
},
30+
{
31+
title: 'custom client',
2532
options: {
2633
hot: false,
2734
client: {
28-
transport: 'ws',
35+
transport: require.resolve(
36+
'../fixtures/custom-client/CustomSockJSClient'
37+
),
2938
},
39+
webSocketServer: 'sockjs',
3040
},
3141
},
3242
];

test/fixtures/dev-server/client-custom-path-config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ module.exports = {
88
stats: 'detailed',
99
entry: resolve(__dirname, './foo.js'),
1010
devServer: {
11-
client: {
12-
transport: 'sockjs',
13-
path: '/custom/path',
11+
webSocketServer: {
12+
type: 'ws',
13+
options: {
14+
path: '/custom/path',
15+
},
1416
},
1517
},
1618
plugins: [ExitOnDonePlugin],

test/fixtures/dev-server/client-default-path-config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ module.exports = {
88
stats: 'detailed',
99
entry: resolve(__dirname, './foo.js'),
1010
devServer: {
11-
client: {
12-
transport: 'sockjs',
13-
path: '/custom/path',
11+
webSocketServer: {
12+
type: 'ws',
13+
options: {
14+
path: '/ws',
15+
},
1416
},
1517
},
1618
plugins: [ExitOnDonePlugin],

test/fixtures/dev-server/default-config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ module.exports = {
88
stats: 'detailed',
99
entry: resolve(__dirname, './foo.js'),
1010
devServer: {
11-
client: {
12-
transport: 'sockjs',
13-
path: '/custom/path',
14-
},
11+
webSocketServer: 'ws',
1512
},
1613
plugins: [ExitOnDonePlugin],
1714
};

test/fixtures/dev-server/empty-entry.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ module.exports = {
77
stats: { orphanModules: true, preset: 'detailed' },
88
entry: {},
99
devServer: {
10-
client: {
11-
transport: 'sockjs',
12-
},
10+
webSocketServer: 'ws',
1311
},
1412
plugins: [ExitOnDonePlugin],
1513
};

test/fixtures/dev-server/multi-entry.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module.exports = {
1212
bar: resolve(__dirname, './bar.js'),
1313
},
1414
devServer: {
15-
client: {
16-
transport: 'sockjs',
17-
},
15+
webSocketServer: 'ws',
1816
},
1917
plugins: [ExitOnDonePlugin],
2018
};

test/fixtures/dev-server/target-config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ module.exports = {
1414
workerChunkLoading: false,
1515
},
1616
devServer: {
17-
client: {
18-
transport: 'sockjs',
19-
path: '/custom/path',
20-
},
17+
webSocketServer: 'ws',
2118
},
2219
plugins: [ExitOnDonePlugin],
2320
};

test/helpers/test-server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function startFullSetup(config, options, done) {
4949

5050
function startAwaitingCompilationFullSetup(config, options, done) {
5151
let readyCount = 0;
52+
5253
const ready = () => {
5354
readyCount += 1;
5455
if (readyCount === 2) {

test/ports-map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const portsList = {
2929
'open-option': 1,
3030
'port-option': 1,
3131
'proxy-option': 4,
32-
'transportMode-option': 1,
32+
'webSocketServer-option': 1,
3333
'client-option': 1,
3434
'stats-option': 1,
3535
ProvidePlugin: 1,

0 commit comments

Comments
 (0)