From 01054e8e2db4c60f23aa65d7bcf3d15a732f00b8 Mon Sep 17 00:00:00 2001 From: Chang Wang Date: Sun, 21 Jan 2018 20:15:22 -0500 Subject: [PATCH 01/15] explicit sockPath --- client-src/default/index.js | 4 ++-- lib/Server.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/client-src/default/index.js b/client-src/default/index.js index db102fd7f6..7ff108f272 100644 --- a/client-src/default/index.js +++ b/client-src/default/index.js @@ -2,7 +2,7 @@ /* global __resourceQuery WorkerGlobalScope self */ /* eslint prefer-destructuring: off */ - +const qs = require('querystring'); const url = require('url'); const stripAnsi = require('strip-ansi'); const log = require('loglevel').getLogger('webpack-dev-server'); @@ -196,7 +196,7 @@ const socketUrl = url.format({ auth: urlParts.auth, hostname, port: urlParts.port, - pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : urlParts.path + pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : (qs.parse(urlParts.path).sockPath || urlParts.path) }); socket(socketUrl, onSocketMsg); diff --git a/lib/Server.js b/lib/Server.js index df60ccff74..f6f24731a0 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -85,6 +85,7 @@ function Server (compiler, options = {}, _log) { this.watchOptions = options.watchOptions || {}; this.contentBaseWatchers = []; + this.sockPath = `/${options.sockPath ? options.sockPath.replace(/\/$/, '') : 'sockjs-node'}`; // Listening for events const invalidPlugin = () => { @@ -763,7 +764,7 @@ Server.prototype.listen = function (port, hostname, fn) { }); socket.installHandlers(this.listeningApp, { - prefix: '/sockjs-node' + prefix: this.sockPath }); if (fn) { From 27fb6a59c923e9a7e7dcf66c2c14a800e86f5c36 Mon Sep 17 00:00:00 2001 From: Chang Wang Date: Sun, 21 Jan 2018 21:20:25 -0500 Subject: [PATCH 02/15] add sockPath to options --- lib/options.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/options.json b/lib/options.json index fd60b5aaa0..5d0fb1fd00 100644 --- a/lib/options.json +++ b/lib/options.json @@ -51,6 +51,9 @@ "socket": { "type": "string" }, + "sockPath": { + "type": "string" + }, "watchOptions": { "type": "object" }, @@ -321,6 +324,7 @@ "filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserver-filename-)", "port": "should be {String|Number} (https://webpack.js.org/configuration/dev-server/#devserver-port)", "socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-socket)", + "sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-sockPath)", "watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-watchoptions)", "writeToDisk": "should be {Boolean|Function} (https://github.com/webpack/webpack-dev-middleware#writetodisk)", "headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-headers-)", From 4bbc1f627199a2c50f46820ae3810bbb75061a4b Mon Sep 17 00:00:00 2001 From: Chang Wang Date: Sun, 21 Jan 2018 21:50:04 -0500 Subject: [PATCH 03/15] fix: remove leading and trailing slashes for sockPath --- lib/Server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Server.js b/lib/Server.js index f6f24731a0..e114d4213f 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -85,7 +85,7 @@ function Server (compiler, options = {}, _log) { this.watchOptions = options.watchOptions || {}; this.contentBaseWatchers = []; - this.sockPath = `/${options.sockPath ? options.sockPath.replace(/\/$/, '') : 'sockjs-node'}`; + this.sockPath = `/${options.sockPath ? options.sockPath.replace(/^\/|\/$/, '') : 'sockjs-node'}`; // Listening for events const invalidPlugin = () => { From e6ab166a559ac2907cda4468593b0f3429170d34 Mon Sep 17 00:00:00 2001 From: Chang Wang Date: Sun, 21 Jan 2018 21:50:35 -0500 Subject: [PATCH 04/15] add sockPath to auto-added entry points in /bin --- lib/utils/addEntries.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils/addEntries.js b/lib/utils/addEntries.js index d74412c9fb..1854a76f16 100644 --- a/lib/utils/addEntries.js +++ b/lib/utils/addEntries.js @@ -20,6 +20,7 @@ function addEntries (config, options, server) { }; const domain = createDomain(options, app); + const sockPath = devServerOptions.sockPath ? `&sockPath=${devServerOptions.sockPath}` : ''; const entries = [ `${require.resolve('../../client/')}?${domain}` ]; if (options.hotOnly) { From d52103b99fc6476883a6339591782970362c38ec Mon Sep 17 00:00:00 2001 From: Chang Wang Date: Sun, 21 Jan 2018 21:52:29 -0500 Subject: [PATCH 05/15] =?UTF-8?q?add=20examples=20referencing=20kellyrmill?= =?UTF-8?q?igan=E2=80=99s=20pull/911?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/node-api-sock-path/README.md | 15 +++++++++++ examples/node-api-sock-path/app.js | 7 ++++++ examples/node-api-sock-path/index.html | 9 +++++++ examples/node-api-sock-path/server.js | 25 +++++++++++++++++++ examples/node-api-sock-path/webpack.config.js | 8 ++++++ 5 files changed, 64 insertions(+) create mode 100644 examples/node-api-sock-path/README.md create mode 100644 examples/node-api-sock-path/app.js create mode 100644 examples/node-api-sock-path/index.html create mode 100644 examples/node-api-sock-path/server.js create mode 100644 examples/node-api-sock-path/webpack.config.js diff --git a/examples/node-api-sock-path/README.md b/examples/node-api-sock-path/README.md new file mode 100644 index 0000000000..48e44e1ed0 --- /dev/null +++ b/examples/node-api-sock-path/README.md @@ -0,0 +1,15 @@ +# Node.js API - Simple + +```shell +node server.js +``` + +Starts a simple webpack-dev-server setup via the Node API. Open `http://localhost:8080/` to go the app. + +## What should happen + +In the app you should see "It's working." + +In `app.js`, uncomment the code that results in an error and save. This error should be visible in the CLI and devtools. + +Then, in `app.js`, uncomment the code that results in a warning. This warning should be visible in the CLI and devtools. \ No newline at end of file diff --git a/examples/node-api-sock-path/app.js b/examples/node-api-sock-path/app.js new file mode 100644 index 0000000000..5894efcf2b --- /dev/null +++ b/examples/node-api-sock-path/app.js @@ -0,0 +1,7 @@ +document.write('It\'s working under a subapp'); + +// This results in a warning: +if (!window) require(`./${window}parseable.js`); + +// This results in an error: +// if(!window) require("test"); diff --git a/examples/node-api-sock-path/index.html b/examples/node-api-sock-path/index.html new file mode 100644 index 0000000000..1f527bff03 --- /dev/null +++ b/examples/node-api-sock-path/index.html @@ -0,0 +1,9 @@ + + + + + + +

Example: Node.js API - Simple

+ + \ No newline at end of file diff --git a/examples/node-api-sock-path/server.js b/examples/node-api-sock-path/server.js new file mode 100644 index 0000000000..501f048fcc --- /dev/null +++ b/examples/node-api-sock-path/server.js @@ -0,0 +1,25 @@ +'use strict'; + +const path = require('path'); +const Webpack = require('webpack'); +const WebpackDevServer = require('../../lib/Server'); +const webpackConfig = require('./webpack.config'); + +const compiler = Webpack(webpackConfig); +const server = new WebpackDevServer(compiler, { + stats: { + colors: true + }, + contentBase: path.resolve(__dirname), + watchContentBase: true, + sockPath: '/subapp/sockjs-node', + publicPath: '/subapp/', + historyApiFallback: { + disableDotRule: true, + index: '/subapp/' + } +}); + +server.listen(8080, '127.0.0.1', () => { + console.log('Starting server on http://localhost:8080'); +}); diff --git a/examples/node-api-sock-path/webpack.config.js b/examples/node-api-sock-path/webpack.config.js new file mode 100644 index 0000000000..7e24357dc8 --- /dev/null +++ b/examples/node-api-sock-path/webpack.config.js @@ -0,0 +1,8 @@ +module.exports = { + context: __dirname, + entry: ['./app.js', '../../client/index.js?http://localhost:8080/&sockPath=subapp/sockjs-node'], + output: { + filename: 'bundle.js', + publicPath: '/subapp/' + } +}; From 4a07096f6fd37f30f6eb43fa12072449111fc080 Mon Sep 17 00:00:00 2001 From: Chang Wang Date: Sun, 21 Jan 2018 22:31:35 -0500 Subject: [PATCH 06/15] fix test --- examples/node-api-sock-path/app.js | 8 ++------ examples/node-api-sock-path/webpack.config.js | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/node-api-sock-path/app.js b/examples/node-api-sock-path/app.js index 5894efcf2b..ccd81d08ca 100644 --- a/examples/node-api-sock-path/app.js +++ b/examples/node-api-sock-path/app.js @@ -1,7 +1,3 @@ -document.write('It\'s working under a subapp'); - -// This results in a warning: -if (!window) require(`./${window}parseable.js`); +'use strict'; -// This results in an error: -// if(!window) require("test"); +document.write('It\'s working under a subapp'); diff --git a/examples/node-api-sock-path/webpack.config.js b/examples/node-api-sock-path/webpack.config.js index 7e24357dc8..1292359194 100644 --- a/examples/node-api-sock-path/webpack.config.js +++ b/examples/node-api-sock-path/webpack.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { context: __dirname, entry: ['./app.js', '../../client/index.js?http://localhost:8080/&sockPath=subapp/sockjs-node'], From 40781564dcf93f5355215bceabf1001008ed2e2e Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Mon, 29 Oct 2018 17:09:00 -0400 Subject: [PATCH 07/15] fix lint errors + correct messed up rebase --- client-src/default/index.js | 4 ++-- lib/utils/addEntries.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client-src/default/index.js b/client-src/default/index.js index 7ff108f272..5d0ee9d7a3 100644 --- a/client-src/default/index.js +++ b/client-src/default/index.js @@ -2,7 +2,7 @@ /* global __resourceQuery WorkerGlobalScope self */ /* eslint prefer-destructuring: off */ -const qs = require('querystring'); +const querystring = require('querystring'); const url = require('url'); const stripAnsi = require('strip-ansi'); const log = require('loglevel').getLogger('webpack-dev-server'); @@ -196,7 +196,7 @@ const socketUrl = url.format({ auth: urlParts.auth, hostname, port: urlParts.port, - pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : (qs.parse(urlParts.path).sockPath || urlParts.path) + pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : (querystring.parse(urlParts.path).sockPath || urlParts.path) }); socket(socketUrl, onSocketMsg); diff --git a/lib/utils/addEntries.js b/lib/utils/addEntries.js index 1854a76f16..eb64565a6f 100644 --- a/lib/utils/addEntries.js +++ b/lib/utils/addEntries.js @@ -20,8 +20,8 @@ function addEntries (config, options, server) { }; const domain = createDomain(options, app); - const sockPath = devServerOptions.sockPath ? `&sockPath=${devServerOptions.sockPath}` : ''; - const entries = [ `${require.resolve('../../client/')}?${domain}` ]; + const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : ''; + const entries = [ `${require.resolve('../../client/')}?${domain}${sockPath}` ]; if (options.hotOnly) { entries.push(require.resolve('webpack/hot/only-dev-server')); From 745908f11a6010ce6bd621f83f0108d3f01b2d25 Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 31 Oct 2018 08:05:40 -0400 Subject: [PATCH 08/15] fix sockjs path formatting --- lib/Server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Server.js b/lib/Server.js index e114d4213f..869bd0b19e 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -85,7 +85,7 @@ function Server (compiler, options = {}, _log) { this.watchOptions = options.watchOptions || {}; this.contentBaseWatchers = []; - this.sockPath = `/${options.sockPath ? options.sockPath.replace(/^\/|\/$/, '') : 'sockjs-node'}`; + this.sockPath = `/${options.sockPath ? options.sockPath.replace(/^\/|\/$/g, '') : 'sockjs-node'}`; // Listening for events const invalidPlugin = () => { From c0faeebf0ed1cd6c51d0c98341df714cc7e7b0b5 Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 31 Oct 2018 08:05:56 -0400 Subject: [PATCH 09/15] remove example --- examples/node-api-sock-path/README.md | 15 ----------- examples/node-api-sock-path/app.js | 3 --- examples/node-api-sock-path/index.html | 9 ------- examples/node-api-sock-path/server.js | 25 ------------------- examples/node-api-sock-path/webpack.config.js | 10 -------- 5 files changed, 62 deletions(-) delete mode 100644 examples/node-api-sock-path/README.md delete mode 100644 examples/node-api-sock-path/app.js delete mode 100644 examples/node-api-sock-path/index.html delete mode 100644 examples/node-api-sock-path/server.js delete mode 100644 examples/node-api-sock-path/webpack.config.js diff --git a/examples/node-api-sock-path/README.md b/examples/node-api-sock-path/README.md deleted file mode 100644 index 48e44e1ed0..0000000000 --- a/examples/node-api-sock-path/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Node.js API - Simple - -```shell -node server.js -``` - -Starts a simple webpack-dev-server setup via the Node API. Open `http://localhost:8080/` to go the app. - -## What should happen - -In the app you should see "It's working." - -In `app.js`, uncomment the code that results in an error and save. This error should be visible in the CLI and devtools. - -Then, in `app.js`, uncomment the code that results in a warning. This warning should be visible in the CLI and devtools. \ No newline at end of file diff --git a/examples/node-api-sock-path/app.js b/examples/node-api-sock-path/app.js deleted file mode 100644 index ccd81d08ca..0000000000 --- a/examples/node-api-sock-path/app.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict'; - -document.write('It\'s working under a subapp'); diff --git a/examples/node-api-sock-path/index.html b/examples/node-api-sock-path/index.html deleted file mode 100644 index 1f527bff03..0000000000 --- a/examples/node-api-sock-path/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - -

Example: Node.js API - Simple

- - \ No newline at end of file diff --git a/examples/node-api-sock-path/server.js b/examples/node-api-sock-path/server.js deleted file mode 100644 index 501f048fcc..0000000000 --- a/examples/node-api-sock-path/server.js +++ /dev/null @@ -1,25 +0,0 @@ -'use strict'; - -const path = require('path'); -const Webpack = require('webpack'); -const WebpackDevServer = require('../../lib/Server'); -const webpackConfig = require('./webpack.config'); - -const compiler = Webpack(webpackConfig); -const server = new WebpackDevServer(compiler, { - stats: { - colors: true - }, - contentBase: path.resolve(__dirname), - watchContentBase: true, - sockPath: '/subapp/sockjs-node', - publicPath: '/subapp/', - historyApiFallback: { - disableDotRule: true, - index: '/subapp/' - } -}); - -server.listen(8080, '127.0.0.1', () => { - console.log('Starting server on http://localhost:8080'); -}); diff --git a/examples/node-api-sock-path/webpack.config.js b/examples/node-api-sock-path/webpack.config.js deleted file mode 100644 index 1292359194..0000000000 --- a/examples/node-api-sock-path/webpack.config.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -module.exports = { - context: __dirname, - entry: ['./app.js', '../../client/index.js?http://localhost:8080/&sockPath=subapp/sockjs-node'], - output: { - filename: 'bundle.js', - publicPath: '/subapp/' - } -}; From bd31f5a36f9c5a80b2e966a53233103911934e00 Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 31 Oct 2018 08:06:35 -0400 Subject: [PATCH 10/15] add sockpath tests --- test/Socket.test.js | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/Socket.test.js diff --git a/test/Socket.test.js b/test/Socket.test.js new file mode 100644 index 0000000000..a0b5db59e3 --- /dev/null +++ b/test/Socket.test.js @@ -0,0 +1,61 @@ +'use strict'; + +const assert = require('assert'); +const request = require('supertest'); +const config = require('./fixtures/simple-config/webpack.config'); +const helper = require('./helper'); + +describe('socket options', () => { + let server; + let req; + + afterEach(helper.close); + + describe('default behavior', () => { + const defaultPath = '/sockjs-node'; + before((done) => { + server = helper.start(config, {}, done); + req = request(server.app); + }); + + it('defaults to a path', () => { + assert.equal(server.sockPath, defaultPath); + }); + + it('responds', (done) => { + req.get(defaultPath) + .expect(200) + .end((err) => { + if (err) { + done(err); + } + done(); + }); + }); + }); + + describe('socksPath option', () => { + const path = '/foo/test/bar'; + before((done) => { + server = helper.start(config, { + sockPath: '/foo/test/bar/' + }, done); + req = request(server.app); + }); + + it('correctly sets the servers sockPath including removal of extraneous slashes', () => { + assert.equal(path, server.sockPath); + }); + + it('responds', (done) => { + req.get(path) + .expect(200) + .end((err) => { + if (err) { + done(err); + } + done(); + }); + }); + }); +}); From e1d41e0800e66d8eecc1271e9be751af21bd2376 Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 31 Oct 2018 10:19:59 -0400 Subject: [PATCH 11/15] fix tests --- test/Socket.test.js | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/test/Socket.test.js b/test/Socket.test.js index a0b5db59e3..a3c2b10147 100644 --- a/test/Socket.test.js +++ b/test/Socket.test.js @@ -1,36 +1,22 @@ 'use strict'; const assert = require('assert'); -const request = require('supertest'); const config = require('./fixtures/simple-config/webpack.config'); const helper = require('./helper'); + describe('socket options', () => { let server; - let req; afterEach(helper.close); describe('default behavior', () => { - const defaultPath = '/sockjs-node'; before((done) => { server = helper.start(config, {}, done); - req = request(server.app); }); it('defaults to a path', () => { - assert.equal(server.sockPath, defaultPath); - }); - - it('responds', (done) => { - req.get(defaultPath) - .expect(200) - .end((err) => { - if (err) { - done(err); - } - done(); - }); + assert.ok(server.sockPath.match(/\/[a-z0-9\-/]+[^/]$/)); }); }); @@ -40,22 +26,10 @@ describe('socket options', () => { server = helper.start(config, { sockPath: '/foo/test/bar/' }, done); - req = request(server.app); }); it('correctly sets the servers sockPath including removal of extraneous slashes', () => { assert.equal(path, server.sockPath); }); - - it('responds', (done) => { - req.get(path) - .expect(200) - .end((err) => { - if (err) { - done(err); - } - done(); - }); - }); }); }); From b2ef4dea1f9f65bffb5f0b325cb2558d9c6b9bfb Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 31 Oct 2018 16:13:04 -0400 Subject: [PATCH 12/15] add real tests for sockPath --- test/Socket.test.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/test/Socket.test.js b/test/Socket.test.js index a3c2b10147..63299d3ffe 100644 --- a/test/Socket.test.js +++ b/test/Socket.test.js @@ -1,35 +1,53 @@ 'use strict'; const assert = require('assert'); +const path = require('path'); +const request = require('request'); const config = require('./fixtures/simple-config/webpack.config'); const helper = require('./helper'); +const requestSucceeds = (done) => (err, res, body) => { + if (err) { + done(err); + } + + assert.equal(res.statusCode, 200); + done(); +} describe('socket options', () => { let server; + let req; afterEach(helper.close); - describe('default behavior', () => { - before((done) => { + beforeEach((done) => { server = helper.start(config, {}, done); }); it('defaults to a path', () => { assert.ok(server.sockPath.match(/\/[a-z0-9\-/]+[^/]$/)); }); + + it('responds with a 200', (done) => { + request(`http://localhost:8080/sockjs-node`, requestSucceeds(done)); + }); }); describe('socksPath option', () => { const path = '/foo/test/bar'; - before((done) => { + beforeEach((done) => { server = helper.start(config, { sockPath: '/foo/test/bar/' }, done); }); - it('correctly sets the servers sockPath including removal of extraneous slashes', () => { - assert.equal(path, server.sockPath); + it('sets the sock path correctly and strips leading and trailing /s', () => { + assert.equal(server.sockPath, path); }); + + it('responds with a 200 second', (done) => { + request(`http://localhost:8080${path}`, requestSucceeds(done)); + }) }); }); From 13275684ae3a4e8758409e43e12484f6b80b3ddb Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 31 Oct 2018 16:47:59 -0400 Subject: [PATCH 13/15] fix lint errors --- package-lock.json | 76 +++++++++++++-------------------------------- package.json | 1 + test/Socket.test.js | 10 +++--- 3 files changed, 27 insertions(+), 60 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8ae788f717..c62ef424b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -587,7 +587,6 @@ "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", "dev": true, - "optional": true, "requires": { "safer-buffer": "~2.1.0" } @@ -677,15 +676,13 @@ "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", - "dev": true, - "optional": true + "dev": true }, "aws4": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==", - "dev": true, - "optional": true + "dev": true }, "babel-cli": { "version": "6.26.0", @@ -1583,7 +1580,6 @@ "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", "dev": true, - "optional": true, "requires": { "tweetnacl": "^0.14.3" } @@ -1919,8 +1915,7 @@ "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "dev": true, - "optional": true + "dev": true }, "center-align": { "version": "0.1.3", @@ -2099,8 +2094,7 @@ "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", - "dev": true, - "optional": true + "dev": true }, "code-point-at": { "version": "1.1.0", @@ -2936,7 +2930,6 @@ "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", "dev": true, - "optional": true, "requires": { "assert-plus": "^1.0.0" } @@ -3293,7 +3286,6 @@ "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", "dev": true, - "optional": true, "requires": { "jsbn": "~0.1.0", "safer-buffer": "^2.1.0" @@ -4243,8 +4235,7 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", - "dev": true, - "optional": true + "dev": true }, "form-data": { "version": "2.3.2", @@ -5003,7 +4994,6 @@ "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", "dev": true, - "optional": true, "requires": { "assert-plus": "^1.0.0" } @@ -5269,15 +5259,13 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", - "dev": true, - "optional": true + "dev": true }, "har-validator": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.0.tgz", "integrity": "sha512-+qnmNjI4OfH2ipQ9VQOw23bBd/ibtfbVdK2fYbY4acTDqKTW/YDp9McimZdDbG8iV9fZizUqQMD5xvriB146TA==", "dev": true, - "optional": true, "requires": { "ajv": "^5.3.0", "har-schema": "^2.0.0" @@ -5288,7 +5276,6 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", "dev": true, - "optional": true, "requires": { "co": "^4.6.0", "fast-deep-equal": "^1.0.0", @@ -5298,17 +5285,15 @@ }, "fast-deep-equal": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", - "dev": true, - "optional": true + "dev": true }, "json-schema-traverse": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", - "dev": true, - "optional": true + "dev": true } } }, @@ -5584,7 +5569,6 @@ "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", "dev": true, - "optional": true, "requires": { "assert-plus": "^1.0.0", "jsprim": "^1.2.2", @@ -6106,8 +6090,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", - "dev": true, - "optional": true + "dev": true }, "is-utf8": { "version": "0.2.1", @@ -6144,8 +6127,7 @@ "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", - "dev": true, - "optional": true + "dev": true }, "istanbul-lib-coverage": { "version": "2.0.1", @@ -6194,8 +6176,7 @@ "version": "0.1.1", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "dev": true, - "optional": true + "dev": true }, "jsesc": { "version": "1.3.0", @@ -6213,8 +6194,7 @@ "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", - "dev": true, - "optional": true + "dev": true }, "json-schema-traverse": { "version": "0.4.1", @@ -6255,7 +6235,6 @@ "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", "dev": true, - "optional": true, "requires": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", @@ -9127,8 +9106,7 @@ "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -9564,8 +9542,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", - "dev": true, - "optional": true + "dev": true }, "pify": { "version": "3.0.0", @@ -9795,8 +9772,7 @@ "version": "1.1.29", "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.29.tgz", "integrity": "sha512-AeUmQ0oLN02flVHXWh9sSJF7mcdFq0ppid/JkErufc3hGIV/AMa8Fo9VgDo/cT2jFdOWoFvHp90qqBH54W+gjQ==", - "dev": true, - "optional": true + "dev": true }, "public-encrypt": { "version": "4.0.2", @@ -10181,7 +10157,6 @@ "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", "dev": true, - "optional": true, "requires": { "aws-sign2": "~0.7.0", "aws4": "^1.8.0", @@ -10209,8 +10184,7 @@ "version": "6.5.2", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", - "dev": true, - "optional": true + "dev": true } } }, @@ -10923,11 +10897,10 @@ "dev": true }, "sshpk": { - "version": "1.14.2", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.2.tgz", - "integrity": "sha1-xvxhZIo9nE52T9P8306hBeSSupg=", + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.15.2.tgz", + "integrity": "sha512-Ra/OXQtuh0/enyl4ETZAfTaeksa6BXks5ZcjpSUNrjBr0DvrJKX+1fsKDPpT9TBXgHAFsa4510aNVgI8g/+SzA==", "dev": true, - "optional": true, "requires": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", @@ -11402,7 +11375,6 @@ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", "dev": true, - "optional": true, "requires": { "psl": "^1.1.24", "punycode": "^1.4.1" @@ -11412,8 +11384,7 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", - "dev": true, - "optional": true + "dev": true } } }, @@ -11452,7 +11423,6 @@ "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.0.1" } @@ -11461,8 +11431,7 @@ "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "dev": true, - "optional": true + "dev": true }, "type-check": { "version": "0.3.2", @@ -11816,7 +11785,6 @@ "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", "dev": true, - "optional": true, "requires": { "assert-plus": "^1.0.0", "core-util-is": "1.0.2", diff --git a/package.json b/package.json index e3ee55f5e6..31d2d80cce 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "mocha": "^5.2.0", "mocha-sinon": "^2.0.0", "nyc": "^12.0.2", + "request": "^2.88.0", "rimraf": "^2.6.2", "should": "^13.2.0", "sinon": "^6.1.5", diff --git a/test/Socket.test.js b/test/Socket.test.js index 63299d3ffe..ab4b300950 100644 --- a/test/Socket.test.js +++ b/test/Socket.test.js @@ -1,23 +1,21 @@ 'use strict'; const assert = require('assert'); -const path = require('path'); const request = require('request'); const config = require('./fixtures/simple-config/webpack.config'); const helper = require('./helper'); -const requestSucceeds = (done) => (err, res, body) => { +const requestSucceeds = done => (err, res) => { if (err) { done(err); } assert.equal(res.statusCode, 200); done(); -} +}; describe('socket options', () => { let server; - let req; afterEach(helper.close); describe('default behavior', () => { @@ -30,7 +28,7 @@ describe('socket options', () => { }); it('responds with a 200', (done) => { - request(`http://localhost:8080/sockjs-node`, requestSucceeds(done)); + request('http://localhost:8080/sockjs-node', requestSucceeds(done)); }); }); @@ -48,6 +46,6 @@ describe('socket options', () => { it('responds with a 200 second', (done) => { request(`http://localhost:8080${path}`, requestSucceeds(done)); - }) + }); }); }); From a3d320ee3d64677d219ee99eee764fc8ed7457be Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 5 Dec 2018 10:09:54 -0500 Subject: [PATCH 14/15] refactor socket tests to use super test --- package-lock.json | 64 +++++++++++++++++++++++++++++++++------------ package.json | 1 - test/Socket.test.js | 24 ++++++++--------- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0dd538905d..6c303a3f55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -587,6 +587,7 @@ "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", "dev": true, + "optional": true, "requires": { "safer-buffer": "~2.1.0" } @@ -676,13 +677,15 @@ "version": "0.7.0", "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", - "dev": true + "dev": true, + "optional": true }, "aws4": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==", - "dev": true + "dev": true, + "optional": true }, "babel-cli": { "version": "6.26.0", @@ -1580,6 +1583,7 @@ "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", "dev": true, + "optional": true, "requires": { "tweetnacl": "^0.14.3" } @@ -1915,7 +1919,8 @@ "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "dev": true + "dev": true, + "optional": true }, "center-align": { "version": "0.1.3", @@ -2094,7 +2099,8 @@ "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", - "dev": true + "dev": true, + "optional": true }, "code-point-at": { "version": "1.1.0", @@ -2930,6 +2936,7 @@ "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", "dev": true, + "optional": true, "requires": { "assert-plus": "^1.0.0" } @@ -3286,6 +3293,7 @@ "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", "dev": true, + "optional": true, "requires": { "jsbn": "~0.1.0", "safer-buffer": "^2.1.0" @@ -4235,7 +4243,8 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", - "dev": true + "dev": true, + "optional": true }, "form-data": { "version": "2.3.2", @@ -4994,6 +5003,7 @@ "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", "dev": true, + "optional": true, "requires": { "assert-plus": "^1.0.0" } @@ -5259,13 +5269,15 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", - "dev": true + "dev": true, + "optional": true }, "har-validator": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.0.tgz", "integrity": "sha512-+qnmNjI4OfH2ipQ9VQOw23bBd/ibtfbVdK2fYbY4acTDqKTW/YDp9McimZdDbG8iV9fZizUqQMD5xvriB146TA==", "dev": true, + "optional": true, "requires": { "ajv": "^5.3.0", "har-schema": "^2.0.0" @@ -5276,6 +5288,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", "dev": true, + "optional": true, "requires": { "co": "^4.6.0", "fast-deep-equal": "^1.0.0", @@ -5285,15 +5298,17 @@ }, "fast-deep-equal": { "version": "1.1.0", - "resolved": "http://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", - "dev": true + "dev": true, + "optional": true }, "json-schema-traverse": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", - "dev": true + "dev": true, + "optional": true } } }, @@ -5569,6 +5584,7 @@ "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", "dev": true, + "optional": true, "requires": { "assert-plus": "^1.0.0", "jsprim": "^1.2.2", @@ -6090,7 +6106,8 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", - "dev": true + "dev": true, + "optional": true }, "is-utf8": { "version": "0.2.1", @@ -6127,7 +6144,8 @@ "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", - "dev": true + "dev": true, + "optional": true }, "istanbul-lib-coverage": { "version": "2.0.1", @@ -6194,7 +6212,8 @@ "version": "0.2.3", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", - "dev": true + "dev": true, + "optional": true }, "json-schema-traverse": { "version": "0.4.1", @@ -6235,6 +6254,7 @@ "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", "dev": true, + "optional": true, "requires": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", @@ -9106,7 +9126,8 @@ "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -9542,7 +9563,8 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", - "dev": true + "dev": true, + "optional": true }, "pify": { "version": "3.0.0", @@ -9772,7 +9794,8 @@ "version": "1.1.29", "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.29.tgz", "integrity": "sha512-AeUmQ0oLN02flVHXWh9sSJF7mcdFq0ppid/JkErufc3hGIV/AMa8Fo9VgDo/cT2jFdOWoFvHp90qqBH54W+gjQ==", - "dev": true + "dev": true, + "optional": true }, "public-encrypt": { "version": "4.0.2", @@ -10157,6 +10180,7 @@ "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", "dev": true, + "optional": true, "requires": { "aws-sign2": "~0.7.0", "aws4": "^1.8.0", @@ -10184,7 +10208,8 @@ "version": "6.5.2", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==", - "dev": true + "dev": true, + "optional": true } } }, @@ -10919,6 +10944,7 @@ "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.15.2.tgz", "integrity": "sha512-Ra/OXQtuh0/enyl4ETZAfTaeksa6BXks5ZcjpSUNrjBr0DvrJKX+1fsKDPpT9TBXgHAFsa4510aNVgI8g/+SzA==", "dev": true, + "optional": true, "requires": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", @@ -11393,6 +11419,7 @@ "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", "dev": true, + "optional": true, "requires": { "psl": "^1.1.24", "punycode": "^1.4.1" @@ -11402,7 +11429,8 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", - "dev": true + "dev": true, + "optional": true } } }, @@ -11441,6 +11469,7 @@ "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.0.1" } @@ -11803,6 +11832,7 @@ "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", "dev": true, + "optional": true, "requires": { "assert-plus": "^1.0.0", "core-util-is": "1.0.2", diff --git a/package.json b/package.json index 1d90899598..d01a35776d 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,6 @@ "mocha": "^5.2.0", "mocha-sinon": "^2.0.0", "nyc": "^12.0.2", - "request": "^2.88.0", "rimraf": "^2.6.2", "should": "^13.2.0", "sinon": "^6.1.5", diff --git a/test/Socket.test.js b/test/Socket.test.js index ab4b300950..49c4108e4c 100644 --- a/test/Socket.test.js +++ b/test/Socket.test.js @@ -1,26 +1,23 @@ 'use strict'; const assert = require('assert'); -const request = require('request'); +const request = require('supertest'); const config = require('./fixtures/simple-config/webpack.config'); const helper = require('./helper'); -const requestSucceeds = done => (err, res) => { - if (err) { - done(err); - } - - assert.equal(res.statusCode, 200); - done(); -}; - describe('socket options', () => { let server; + let req; - afterEach(helper.close); + afterEach((done) => { + helper.close(done); + req = null; + server = null; + }); describe('default behavior', () => { beforeEach((done) => { server = helper.start(config, {}, done); + req = request('http://localhost:8080'); }); it('defaults to a path', () => { @@ -28,7 +25,7 @@ describe('socket options', () => { }); it('responds with a 200', (done) => { - request('http://localhost:8080/sockjs-node', requestSucceeds(done)); + req.get('/sockjs-node').expect(200, done); }); }); @@ -38,6 +35,7 @@ describe('socket options', () => { server = helper.start(config, { sockPath: '/foo/test/bar/' }, done); + req = request('http://localhost:8080'); }); it('sets the sock path correctly and strips leading and trailing /s', () => { @@ -45,7 +43,7 @@ describe('socket options', () => { }); it('responds with a 200 second', (done) => { - request(`http://localhost:8080${path}`, requestSucceeds(done)); + req.get(path).expect(200, done); }); }); }); From d252f19328ee075d8f9541bc6d5e671a81ea52c8 Mon Sep 17 00:00:00 2001 From: Thomas Crescenzi Date: Wed, 30 Jan 2019 12:06:50 -0500 Subject: [PATCH 15/15] add comments for clarification about sockPath code --- client-src/default/index.js | 3 +++ lib/Server.js | 1 + 2 files changed, 4 insertions(+) diff --git a/client-src/default/index.js b/client-src/default/index.js index 5d0ee9d7a3..27c07880e5 100644 --- a/client-src/default/index.js +++ b/client-src/default/index.js @@ -196,6 +196,9 @@ const socketUrl = url.format({ auth: urlParts.auth, hostname, port: urlParts.port, + // If sockPath 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: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : (querystring.parse(urlParts.path).sockPath || urlParts.path) }); diff --git a/lib/Server.js b/lib/Server.js index 6cc67d3092..5c4cb42203 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -101,6 +101,7 @@ function Server (compiler, options = {}, _log) { this.watchOptions = options.watchOptions || {}; this.contentBaseWatchers = []; + // Replace leading and trailing slashes to normalize path this.sockPath = `/${options.sockPath ? options.sockPath.replace(/^\/|\/$/g, '') : 'sockjs-node'}`; // Listening for events