diff --git a/client-src/default/utils/createSocketUrl.js b/client-src/default/utils/createSocketUrl.js index 971ceaba99..3b7178a04e 100644 --- a/client-src/default/utils/createSocketUrl.js +++ b/client-src/default/utils/createSocketUrl.js @@ -10,7 +10,7 @@ function createSocketUrl(resourceQuery, currentLocation) { if (typeof resourceQuery === 'string' && resourceQuery !== '') { // If this bundle is inlined, use the resource query to get the correct url. - // format is like `?http://0.0.0.0:8096&sockPort=8097&sockHost=localhost` + // format is like `?http://0.0.0.0:8096&port=8097&host=localhost` urlParts = url.parse( resourceQuery // strip leading `?` from query string to get a valid URL @@ -74,23 +74,23 @@ function getSocketUrl(urlParts, loc) { // all of these sock url params are optionally passed in through // resourceQuery, so we need to fall back to the default if // they are not provided - const sockHost = query.sockHost || hostname; - const sockPath = query.sockPath || '/ws'; - let sockPort = query.sockPort || port; + const host = query.host || hostname; + const path = query.path || '/ws'; + let portOption = query.port || port; - if (sockPort === 'location') { - sockPort = loc.port; + if (portOption === 'location') { + portOption = loc.port; } return url.format({ protocol, auth, - hostname: sockHost, - port: sockPort, - // If sockPath is provided it'll be passed in via the resourceQuery as a + hostname: host, + port: portOption, + // If path is provided it'll be passed in via the resourceQuery as a // query param so it has to be parsed out of the querystring in order for the // client to open the socket to the correct location. - pathname: sockPath, + pathname: path, }); } diff --git a/lib/Server.js b/lib/Server.js index 7de7c68e14..56786042ee 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -91,13 +91,6 @@ class Server { this.watchOptions = options.watchOptions || {}; - // Replace leading and trailing slashes to normalize path - this.sockPath = `/${ - this.options.sockPath - ? this.options.sockPath.replace(/^\/|\/$/g, '') - : 'ws' - }`; - if (this.progress) { this.setupProgressPlugin(); } diff --git a/lib/options.json b/lib/options.json index 92586c909c..a6e8de74b9 100644 --- a/lib/options.json +++ b/lib/options.json @@ -22,6 +22,31 @@ "warning" ] }, + "clientOptions": { + "type": "object", + "properties": { + "host": { + "type": "string" + }, + "path": { + "type": "string" + }, + "port": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, "compress": { "type": "boolean" }, @@ -322,25 +347,6 @@ "serverSideRender": { "type": "boolean" }, - "sockHost": { - "type": "string" - }, - "sockPath": { - "type": "string" - }, - "sockPort": { - "anyOf": [ - { - "type": "number" - }, - { - "type": "string" - }, - { - "type": "null" - } - ] - }, "socket": { "type": "string" }, @@ -421,6 +427,7 @@ "allowedHosts": "should be {Array} (https://webpack.js.org/configuration/dev-server/#devserverallowedhosts)", "bonjour": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverbonjour)", "clientLogLevel": "should be {String} and equal to one of the allowed values\n\n [ 'none', 'silent', 'info', 'debug', 'trace', 'error', 'warning', 'warn' ]\n\n (https://webpack.js.org/configuration/dev-server/#devserverclientloglevel)", + "clientOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverclientoptions)", "compress": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devservercompress)", "contentBase": "should be {Number|String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)", "disableHostCheck": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck)", @@ -459,9 +466,6 @@ "contentBasePublicPath": "should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbasepublicpath)", "serveIndex": "should be {Boolean} (https://webpack.js.org/configuration/dev-server/#devserverserveindex)", "serverSideRender": "should be {Boolean} (https://github.com/webpack/webpack-dev-middleware#serversiderender)", - "sockHost": "should be {String|Null} (https://webpack.js.org/configuration/dev-server/#devserversockhost)", - "sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversockpath)", - "sockPort": "should be {Number|String|Null} (https://webpack.js.org/configuration/dev-server/#devserversockport)", "socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserversocket)", "staticOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserverstaticoptions)", "stats": "should be {Object|Boolean} (https://webpack.js.org/configuration/dev-server/#devserverstats-)", diff --git a/lib/servers/SockJSServer.js b/lib/servers/SockJSServer.js index 43acc6ea02..9fa404515a 100644 --- a/lib/servers/SockJSServer.js +++ b/lib/servers/SockJSServer.js @@ -44,7 +44,7 @@ module.exports = class SockJSServer extends BaseServer { }); this.socket.installHandlers(this.server.listeningApp, { - prefix: this.server.sockPath, + prefix: this.server.options.clientOptions.path, }); } diff --git a/lib/servers/WebsocketServer.js b/lib/servers/WebsocketServer.js index 3021f40341..91739f34f4 100644 --- a/lib/servers/WebsocketServer.js +++ b/lib/servers/WebsocketServer.js @@ -11,7 +11,7 @@ module.exports = class WebsocketServer extends BaseServer { super(server); this.wsServer = new ws.Server({ noServer: true, - path: this.server.sockPath, + path: this.server.options.clientOptions.path, }); this.server.listeningApp.on('upgrade', (req, sock, head) => { diff --git a/lib/utils/addEntries.js b/lib/utils/addEntries.js index e8e18a5d09..147f8ff677 100644 --- a/lib/utils/addEntries.js +++ b/lib/utils/addEntries.js @@ -29,15 +29,29 @@ function addEntries(config, options, server) { /** @type {string} */ const domain = createDomain(options, app); /** @type {string} */ - const sockHost = options.sockHost ? `&sockHost=${options.sockHost}` : ''; + const host = + options.clientOptions && options.clientOptions.host + ? `&host=${options.clientOptions.host}` + : ''; /** @type {string} */ - const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : ''; + let path = ''; + // only add the path if it is not default + if ( + options.clientOptions && + options.clientOptions.path && + options.clientOptions.path !== '/ws' + ) { + path = `&path=${options.clientOptions.path}`; + } /** @type {string} */ - const sockPort = options.sockPort ? `&sockPort=${options.sockPort}` : ''; + const port = + options.clientOptions && options.clientOptions.port + ? `&port=${options.clientOptions.port}` + : ''; /** @type {string} */ const clientEntry = `${require.resolve( '../../client/default/' - )}?${domain}${sockHost}${sockPath}${sockPort}`; + )}?${domain}${host}${path}${port}`; /** @type {(string[] | string)} */ let hotEntry; diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index 28af60763a..e19648ed2b 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -31,18 +31,6 @@ function createConfig(config, argv, { port }) { options.socket = argv.socket; } - if (argv.sockHost) { - options.sockHost = argv.sockHost; - } - - if (argv.sockPath) { - options.sockPath = argv.sockPath; - } - - if (argv.sockPort) { - options.sockPort = argv.sockPort; - } - if (argv.liveReload === false) { options.liveReload = false; } diff --git a/lib/utils/normalizeOptions.js b/lib/utils/normalizeOptions.js index 0bf51ca3c2..20747bb8ab 100644 --- a/lib/utils/normalizeOptions.js +++ b/lib/utils/normalizeOptions.js @@ -36,6 +36,16 @@ function normalizeOptions(compiler, options) { if (!options.watchOptions) { options.watchOptions = {}; } + + if (!options.clientOptions) { + options.clientOptions = {}; + } + + options.clientOptions.path = `/${ + options.clientOptions.path + ? options.clientOptions.path.replace(/^\/|\/$/g, '') + : 'ws' + }`; } module.exports = normalizeOptions; diff --git a/test/__snapshots__/Validation.test.js.snap b/test/__snapshots__/Validation.test.js.snap index a16028ec28..e284765874 100644 --- a/test/__snapshots__/Validation.test.js.snap +++ b/test/__snapshots__/Validation.test.js.snap @@ -37,5 +37,5 @@ exports[`Validation validation should fail validation for invalid \`writeToDisk\ exports[`Validation validation should fail validation for no additional properties 1`] = ` "Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema. - configuration has an unknown property 'additional'. These properties are valid: - object { allowedHosts?, bonjour?, clientLogLevel?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, features?, fs?, headers?, historyApiFallback?, host?, hot?, http2?, https?, index?, injectClient?, injectHot?, liveReload?, log?, logLevel?, logTime?, mimeTypes?, noInfo?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, profile?, progress?, proxy?, public?, publicPath?, quiet?, reporter?, requestCert?, serveIndex?, serverSideRender?, sockHost?, sockPath?, sockPort?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, warn?, watchContentBase?, watchOptions?, writeToDisk? }" + object { allowedHosts?, bonjour?, clientLogLevel?, clientOptions?, compress?, contentBasePublicPath?, contentBase?, disableHostCheck?, features?, fs?, headers?, historyApiFallback?, host?, hot?, http2?, https?, index?, injectClient?, injectHot?, liveReload?, log?, logLevel?, logTime?, mimeTypes?, noInfo?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, openPage?, overlay?, port?, profile?, progress?, proxy?, public?, publicPath?, quiet?, reporter?, requestCert?, serveIndex?, serverSideRender?, socket?, staticOptions?, stats?, transportMode?, useLocalIp?, warn?, watchContentBase?, watchOptions?, writeToDisk? }" `; diff --git a/test/cli/cli.test.js b/test/cli/cli.test.js index 58e7afd0f5..757141046e 100644 --- a/test/cli/cli.test.js +++ b/test/cli/cli.test.js @@ -64,17 +64,6 @@ describe('CLI', () => { .catch(done); }); - it('--sockPath', (done) => { - testBin('--sockPath /mysockPath') - .then((output) => { - expect( - /http:\/\/localhost:[0-9]+&sockPath=\/mysockPath/.test(output.stdout) - ).toEqual(true); - done(); - }) - .catch(done); - }); - it('unspecified port', (done) => { testBin('') .then((output) => { diff --git a/test/client/utils/createSocketUrl.test.js b/test/client/utils/createSocketUrl.test.js index 59b565ef11..3c3a1e952f 100644 --- a/test/client/utils/createSocketUrl.test.js +++ b/test/client/utils/createSocketUrl.test.js @@ -74,32 +74,32 @@ describe('createSocketUrl', () => { ['?http://example.com', 'http://something.com', 'http://example.com/ws'], ['?https://example.com', 'http://something.com', 'https://example.com/ws'], [ - '?https://example.com?sockHost=asdf', + '?https://example.com?host=asdf', 'http://something.com', 'https://asdf/ws', ], [ - '?https://example.com?sockPort=34', + '?https://example.com?port=34', 'http://something.com', 'https://example.com:34/ws', ], [ - '?https://example.com?sockPath=xxx', + '?https://example.com?path=xxx', 'http://something.com', 'https://example.com/xxx', ], [ - '?http://0.0.0.0:8096&sockPort=8097', + '?http://0.0.0.0:8096&port=8097', 'http://localhost', 'http://localhost:8097/ws', ], [ - '?http://example.com:8096&sockPort=location', + '?http://example.com:8096&port=location', 'http://something.com', 'http://example.com/ws', ], [ - '?http://0.0.0.0:8096&sockPort=location', + '?http://0.0.0.0:8096&port=location', 'http://localhost:3000', 'http://localhost:3000/ws', ], diff --git a/test/e2e/ClientOptions.test.js b/test/e2e/ClientOptions.test.js index 2a34d49069..ce1c396eb2 100644 --- a/test/e2e/ClientOptions.test.js +++ b/test/e2e/ClientOptions.test.js @@ -111,7 +111,7 @@ describe('ws client proxy', () => { poll: true, }, quiet: true, - public: 'myhost.test', + public: 'myhost', }; testServer.startAwaitingCompilation(config, options, done); }); @@ -141,7 +141,7 @@ describe('ws client proxy', () => { if (msg.type() === 'error' && text.includes('WebSocket connection')) { page.waitFor(beforeBrowserCloseDelay).then(() => { browser.close().then(() => { - expect(text).toContain(`ws://myhost.test:${port2}/ws`); + expect(text).toContain(`ws://myhost:${port2}/ws`); done(); }); }); @@ -153,7 +153,7 @@ describe('ws client proxy', () => { }); }); -describe('sockjs public and sockPath', () => { +describe('sockjs public and client path', () => { beforeAll((done) => { const options = { transportMode: 'sockjs', @@ -163,7 +163,9 @@ describe('sockjs public and sockPath', () => { poll: true, }, public: 'myhost.test', - sockPath: '/foo/test/bar/', + clientOptions: { + path: '/foo/test/bar/', + }, quiet: true, }; testServer.startAwaitingCompilation(config, options, done); @@ -182,7 +184,7 @@ describe('sockjs public and sockPath', () => { page.waitFor(beforeBrowserCloseDelay).then(() => { browser.close().then(() => { expect(requestObj.url()).toContain( - `http://myhost.test:${port2}/foo/test/bar/` + `http://myhost.test:${port2}/foo/test/bar` ); done(); }); @@ -194,7 +196,7 @@ describe('sockjs public and sockPath', () => { }); }); -describe('sockjs sockPath and sockPort', () => { +describe('sockjs client path and port', () => { beforeAll((done) => { const options = { transportMode: 'sockjs', @@ -203,8 +205,10 @@ describe('sockjs sockPath and sockPort', () => { watchOptions: { poll: true, }, - sockPath: '/foo/test/bar/', - sockPort: port3, + clientOptions: { + path: '/foo/test/bar/', + port: port3, + }, quiet: true, }; testServer.startAwaitingCompilation(config, options, done); @@ -236,10 +240,10 @@ describe('sockjs sockPath and sockPort', () => { }); }); -// previously, using sockPort without sockPath had the ability -// to alter the sockPath (based on a bug in client-src/default/index.js) -// so we need to make sure sockPath is not altered in this case -describe('sockjs sockPort, no sockPath', () => { +// previously, using port without path had the ability +// to alter the path (based on a bug in client-src/default/index.js) +// so we need to make sure path is not altered in this case +describe('sockjs client port, no path', () => { beforeAll((done) => { const options = { transportMode: 'sockjs', @@ -248,7 +252,9 @@ describe('sockjs sockPort, no sockPath', () => { watchOptions: { poll: true, }, - sockPort: port3, + clientOptions: { + port: port3, + }, quiet: true, }; testServer.startAwaitingCompilation(config, options, done); @@ -277,7 +283,7 @@ describe('sockjs sockPort, no sockPath', () => { }); }); -describe('sockjs sockHost', () => { +describe('sockjs client host', () => { beforeAll((done) => { const options = { transportMode: 'sockjs', @@ -286,7 +292,9 @@ describe('sockjs sockHost', () => { watchOptions: { poll: true, }, - sockHost: 'myhost.test', + clientOptions: { + host: 'myhost.test', + }, quiet: true, }; testServer.startAwaitingCompilation(config, options, done); @@ -315,7 +323,7 @@ describe('sockjs sockHost', () => { }); }); -describe('ws client sockHost, sockPort, and sockPath', () => { +describe('ws client host, port, and path', () => { beforeAll((done) => { const options = { transportMode: 'ws', @@ -324,9 +332,11 @@ describe('ws client sockHost, sockPort, and sockPath', () => { watchOptions: { poll: true, }, - sockHost: 'myhost.test', - sockPort: port3, - sockPath: '/foo/test/bar/', + clientOptions: { + host: 'myhost', + port: port3, + path: '/foo/test/bar/', + }, quiet: true, }; testServer.startAwaitingCompilation(config, options, done); @@ -344,9 +354,7 @@ describe('ws client sockHost, sockPort, and sockPath', () => { if (msg.type() === 'error' && text.includes('WebSocket connection')) { page.waitFor(beforeBrowserCloseDelay).then(() => { browser.close().then(() => { - expect(text).toContain( - `ws://myhost.test:${port3}/foo/test/bar/` - ); + expect(text).toContain(`ws://myhost:${port3}/foo/test/bar`); done(); }); }); diff --git a/test/options.test.js b/test/options.test.js index 7b548e475c..1103304e5a 100644 --- a/test/options.test.js +++ b/test/options.test.js @@ -145,6 +145,64 @@ describe('options', () => { ], failure: ['whoops!'], }, + clientOptions: { + success: [ + { + clientOptions: {}, + }, + { + clientOptions: { + host: '', + }, + }, + { + clientOptions: { + path: '', + }, + }, + { + clientOptions: { + port: '', + }, + }, + { + clientOptions: { + host: '', + path: '', + port: 8080, + }, + }, + { + clientOptions: { + host: '', + path: '', + port: '', + }, + }, + { + clientOptions: { + host: '', + path: '', + port: null, + }, + }, + ], + failure: [ + 'whoops!', + { + clientOptions: { + unknownOption: true, + }, + }, + { + clientOptions: { + host: true, + path: '', + port: 8080, + }, + }, + ], + }, compress: { success: [true], failure: [''], @@ -353,18 +411,6 @@ describe('options', () => { success: [''], failure: [false], }, - sockHost: { - success: [''], - failure: [false], - }, - sockPath: { - success: [''], - failure: [false], - }, - sockPort: { - success: ['', 0, null], - failure: [false], - }, staticOptions: { success: [{}], failure: [false], diff --git a/test/ports-map.js b/test/ports-map.js index d7d55a3a4d..347546ef2c 100644 --- a/test/ports-map.js +++ b/test/ports-map.js @@ -30,7 +30,7 @@ const portsList = { 'port-option': 1, 'proxy-option': 4, 'transportMode-option': 1, - 'sockPath-option': 1, + 'clientOptions-option': 1, 'stats-option': 1, ProvidePlugin: 1, WebsocketClient: 1, diff --git a/test/server/sockPath-option.test.js b/test/server/clientOptions-option.test.js similarity index 75% rename from test/server/sockPath-option.test.js rename to test/server/clientOptions-option.test.js index c3b1a6fda1..f2eaa6d55b 100644 --- a/test/server/sockPath-option.test.js +++ b/test/server/clientOptions-option.test.js @@ -3,9 +3,9 @@ const request = require('supertest'); const config = require('../fixtures/simple-config/webpack.config'); const testServer = require('../helpers/test-server'); -const port = require('../ports-map')['sockPath-option']; +const port = require('../ports-map')['clientOptions-option']; -describe('sockPath options', () => { +describe('clientOptions option', () => { let server; let req; @@ -29,7 +29,9 @@ describe('sockPath options', () => { }); it('defaults to a path', () => { - expect(!!server.sockPath.match(/\/[a-z0-9\-/]+[^/]$/)).toBeTruthy(); + expect( + server.options.clientOptions.path.match(/\/[a-z0-9\-/]+[^/]$/) + ).toBeTruthy(); }); it('responds with a 200', (done) => { @@ -37,7 +39,7 @@ describe('sockPath options', () => { }); }); - describe('socksPath option', () => { + describe('path option', () => { const path = '/foo/test/bar'; beforeEach((done) => { @@ -45,7 +47,9 @@ describe('sockPath options', () => { config, { transportMode: 'sockjs', - sockPath: '/foo/test/bar/', + clientOptions: { + path: '/foo/test/bar/', + }, port, }, done @@ -54,7 +58,7 @@ describe('sockPath options', () => { }); it('sets the sock path correctly and strips leading and trailing /s', () => { - expect(server.sockPath).toEqual(path); + expect(server.options.clientOptions.path).toEqual(path); }); it('responds with a 200 second', (done) => { diff --git a/test/server/servers/SockJSServer.test.js b/test/server/servers/SockJSServer.test.js index 12a48fff8b..df884ced89 100644 --- a/test/server/servers/SockJSServer.test.js +++ b/test/server/servers/SockJSServer.test.js @@ -21,7 +21,11 @@ describe('SockJSServer', () => { error: () => {}, debug: () => {}, }, - sockPath: '/ws', + options: { + clientOptions: { + path: '/ws', + }, + }, listeningApp, }; diff --git a/test/server/servers/WebsocketServer.test.js b/test/server/servers/WebsocketServer.test.js index 3a4f2560f6..c351f98d45 100644 --- a/test/server/servers/WebsocketServer.test.js +++ b/test/server/servers/WebsocketServer.test.js @@ -22,7 +22,11 @@ describe('WebsocketServer', () => { error: () => {}, debug: () => {}, }, - sockPath: '/ws-server', + options: { + clientOptions: { + path: '/ws-server', + }, + }, listeningApp, heartbeatInterval: 800, }; diff --git a/test/server/transportMode-option.test.js b/test/server/transportMode-option.test.js index ee8cc57700..f0c1ec9a81 100644 --- a/test/server/transportMode-option.test.js +++ b/test/server/transportMode-option.test.js @@ -189,13 +189,12 @@ describe('transportMode', () => { }); describe('as a class (custom "sockjs" implementation)', () => { - let sockPath; + let customServerUsed = false; it('uses supplied server implementation', (done) => { server = testServer.start( config, { port, - sockPath: '/foo/test/bar/', transportMode: { server: class MySockJSServer extends BaseServer { constructor(serv) { @@ -214,10 +213,10 @@ describe('transportMode', () => { }); this.socket.installHandlers(this.server.listeningApp, { - prefix: this.server.sockPath, + prefix: 'ws', }); - sockPath = server.options.sockPath; + customServerUsed = true; } send(connection, message) { @@ -241,7 +240,7 @@ describe('transportMode', () => { }, }, () => { - expect(sockPath).toEqual('/foo/test/bar/'); + expect(customServerUsed).toBeTruthy(); done(); } ); @@ -290,7 +289,7 @@ describe('transportMode', () => { }); this.socket.installHandlers(this.server.listeningApp, { - prefix: this.server.sockPath, + prefix: this.server.options.clientOptions.path, }); } @@ -384,7 +383,7 @@ describe('transportMode', () => { }); this.socket.installHandlers(this.server.listeningApp, { - prefix: this.server.sockPath, + prefix: this.server.options.clientOptions.path, }); } diff --git a/test/server/utils/__snapshots__/createConfig.test.js.snap b/test/server/utils/__snapshots__/createConfig.test.js.snap index 982c8712be..676d30e650 100644 --- a/test/server/utils/__snapshots__/createConfig.test.js.snap +++ b/test/server/utils/__snapshots__/createConfig.test.js.snap @@ -922,48 +922,6 @@ Object { } `; -exports[`createConfig sockHost option 1`] = ` -Object { - "hot": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "sockHost": true, - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - -exports[`createConfig sockPath option 1`] = ` -Object { - "hot": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "sockPath": "path", - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - -exports[`createConfig sockPort option 1`] = ` -Object { - "hot": true, - "noInfo": true, - "port": 8080, - "publicPath": "/", - "sockPort": "port", - "stats": Object { - "cached": false, - "cachedAssets": false, - }, -} -`; - exports[`createConfig socket option (devServer config) 1`] = ` Object { "hot": true, diff --git a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap index d0d7755f81..2ebb9befd9 100644 --- a/test/server/utils/__snapshots__/normalizeOptions.test.js.snap +++ b/test/server/utils/__snapshots__/normalizeOptions.test.js.snap @@ -1,7 +1,54 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`normalizeOptions clientOptions host and port should set correct options 1`] = ` +Object { + "clientOptions": Object { + "host": "my.host", + "path": "/ws", + "port": 9000, + }, + "contentBasePublicPath": "/", + "transportMode": Object { + "client": "ws", + "server": "ws", + }, + "watchOptions": Object {}, +} +`; + +exports[`normalizeOptions clientOptions path should set correct options 1`] = ` +Object { + "clientOptions": Object { + "path": "/custom/path", + }, + "contentBasePublicPath": "/", + "transportMode": Object { + "client": "ws", + "server": "ws", + }, + "watchOptions": Object {}, +} +`; + +exports[`normalizeOptions clientOptions path without leading/ending slashes should set correct options 1`] = ` +Object { + "clientOptions": Object { + "path": "/custom/path", + }, + "contentBasePublicPath": "/", + "transportMode": Object { + "client": "ws", + "server": "ws", + }, + "watchOptions": Object {}, +} +`; + exports[`normalizeOptions contentBase array should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBase": Array [ "/path/to/dist1", "/path/to/dist2", @@ -17,6 +64,9 @@ Object { exports[`normalizeOptions contentBase string should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBase": "/path/to/dist", "contentBasePublicPath": "/", "transportMode": Object { @@ -29,6 +79,9 @@ Object { exports[`normalizeOptions contentBasePublicPath string should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/content-base-public-path", "transportMode": Object { "client": "ws", @@ -40,6 +93,9 @@ Object { exports[`normalizeOptions no options should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "ws", @@ -51,6 +107,9 @@ Object { exports[`normalizeOptions transportMode custom client path should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "/path/to/custom/client/", @@ -62,6 +121,9 @@ Object { exports[`normalizeOptions transportMode custom server class should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "ws", @@ -73,6 +135,9 @@ Object { exports[`normalizeOptions transportMode custom server path should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "ws", @@ -84,6 +149,9 @@ Object { exports[`normalizeOptions transportMode sockjs string should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "sockjs", @@ -95,6 +163,9 @@ Object { exports[`normalizeOptions transportMode ws object should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "ws", @@ -106,6 +177,9 @@ Object { exports[`normalizeOptions transportMode ws string should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "ws", @@ -117,6 +191,9 @@ Object { exports[`normalizeOptions watchOptions should set correct options 1`] = ` Object { + "clientOptions": Object { + "path": "/ws", + }, "contentBasePublicPath": "/", "transportMode": Object { "client": "ws", diff --git a/test/server/utils/addEntries.test.js b/test/server/utils/addEntries.test.js index caffc50a39..6e2475ef89 100644 --- a/test/server/utils/addEntries.test.js +++ b/test/server/utils/addEntries.test.js @@ -438,4 +438,44 @@ describe('addEntries util', () => { expect(normalize(nodeWebpackOptions.entry[1])).toEqual('./foo.js'); }); + + it('does not use clientOptions.path when default', () => { + const webpackOptions = Object.assign({}, config); + const devServerOptions = { + clientOptions: { + path: '/ws', + }, + }; + + addEntries(webpackOptions, devServerOptions); + expect(webpackOptions.entry[0]).not.toContain('&path=/ws'); + }); + + it('uses custom clientOptions.path', () => { + const webpackOptions = Object.assign({}, config); + const devServerOptions = { + clientOptions: { + path: '/custom/path', + }, + }; + + addEntries(webpackOptions, devServerOptions); + expect(webpackOptions.entry[0]).toContain('&path=/custom/path'); + }); + + it('uses custom clientOptions', () => { + const webpackOptions = Object.assign({}, config); + const devServerOptions = { + clientOptions: { + host: 'my.host', + port: 8080, + path: '/custom/path', + }, + }; + + addEntries(webpackOptions, devServerOptions); + expect(webpackOptions.entry[0]).toContain( + '&host=my.host&path=/custom/path&port=8080' + ); + }); }); diff --git a/test/server/utils/createConfig.test.js b/test/server/utils/createConfig.test.js index d23fab737b..129d130e62 100644 --- a/test/server/utils/createConfig.test.js +++ b/test/server/utils/createConfig.test.js @@ -838,42 +838,6 @@ describe('createConfig', () => { expect(config).toMatchSnapshot(); }); - it('sockHost option', () => { - const config = createConfig( - webpackConfig, - Object.assign({}, argv, { - sockHost: true, - }), - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - - it('sockPath option', () => { - const config = createConfig( - webpackConfig, - Object.assign({}, argv, { - sockPath: 'path', - }), - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - - it('sockPort option', () => { - const config = createConfig( - webpackConfig, - Object.assign({}, argv, { - sockPort: 'port', - }), - { port: 8080 } - ); - - expect(config).toMatchSnapshot(); - }); - it('liveReload option', () => { const config = createConfig( webpackConfig, diff --git a/test/server/utils/normalizeOptions.test.js b/test/server/utils/normalizeOptions.test.js index 950b1975e2..f5dd5f44aa 100644 --- a/test/server/utils/normalizeOptions.test.js +++ b/test/server/utils/normalizeOptions.test.js @@ -102,6 +102,37 @@ describe('normalizeOptions', () => { }, optionsResults: null, }, + { + title: 'clientOptions host and port', + multiCompiler: false, + options: { + clientOptions: { + host: 'my.host', + port: 9000, + }, + }, + optionsResults: null, + }, + { + title: 'clientOptions path', + multiCompiler: false, + options: { + clientOptions: { + path: '/custom/path/', + }, + }, + optionsResults: null, + }, + { + title: 'clientOptions path without leading/ending slashes', + multiCompiler: false, + options: { + clientOptions: { + path: 'custom/path', + }, + }, + optionsResults: null, + }, ]; cases.forEach((data) => {