From f381ccb88b06bda5de0ae10a74a5451e27d50459 Mon Sep 17 00:00:00 2001 From: eslam Date: Fri, 16 Aug 2019 17:52:59 +0200 Subject: [PATCH 1/9] fix(server): use regex instead of isAbsoluteUrl --- lib/Server.js | 12 +++++++----- lib/utils/createConfig.js | 5 ++--- lib/utils/runOpen.js | 3 +-- test/server/contentBase-option.test.js | 25 ++++++++++++++++++++++++- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 239fe3783c..136f0a8d66 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -23,7 +23,6 @@ const serveIndex = require('serve-index'); const webpack = require('webpack'); const webpackDevMiddleware = require('webpack-dev-middleware'); const validateOptions = require('schema-utils'); -const isAbsoluteUrl = require('is-absolute-url'); const normalizeOptions = require('./utils/normalizeOptions'); const updateCompiler = require('./utils/updateCompiler'); const createLogger = require('./utils/createLogger'); @@ -339,7 +338,7 @@ class Server { contentBase.forEach((item) => { this.app.get('*', express.static(item)); }); - } else if (isAbsoluteUrl(String(contentBase))) { + } else if (/^(https?:)?\/\//.test(contentBase)) { this.log.warn( 'Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' ); @@ -392,7 +391,7 @@ class Server { }); } else if ( typeof contentBase !== 'number' && - !isAbsoluteUrl(String(contentBase)) + !/^(https?:)?\/\//.test(contentBase) ) { this.app.get('*', serveIndex(contentBase)); } @@ -401,11 +400,14 @@ class Server { setupWatchStaticFeature() { const contentBase = this.options.contentBase; - if (isAbsoluteUrl(String(contentBase)) || typeof contentBase === 'number') { + if ( + /^(https?:)?\/\//.test(contentBase) || + typeof contentBase === 'number' + ) { throw new Error('Watching remote files is not supported.'); } else if (Array.isArray(contentBase)) { contentBase.forEach((item) => { - if (isAbsoluteUrl(String(item))) { + if (/^(https?:)?\/\//.test(item) || typeof item === 'number') { throw new Error('Watching remote files is not supported.'); } this._watch(item); diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index 0211561235..242acbf5bc 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -1,7 +1,6 @@ 'use strict'; const path = require('path'); -const isAbsoluteUrl = require('is-absolute-url'); const defaultTo = require('./defaultTo'); function createConfig(config, argv, { port }) { @@ -65,7 +64,7 @@ function createConfig(config, argv, { port }) { (firstWpOpt.output && firstWpOpt.output.publicPath) || ''; if ( - !isAbsoluteUrl(String(options.publicPath)) && + !/^(https?:)?\/\//.test(options.publicPath) && options.publicPath[0] !== '/' ) { options.publicPath = `/${options.publicPath}`; @@ -114,7 +113,7 @@ function createConfig(config, argv, { port }) { options.contentBase = options.contentBase.map((p) => path.resolve(p)); } else if (/^[0-9]$/.test(options.contentBase)) { options.contentBase = +options.contentBase; - } else if (!isAbsoluteUrl(String(options.contentBase))) { + } else if (!/^(https?:)?\/\//.test(options.contentBase)) { options.contentBase = path.resolve(options.contentBase); } } diff --git a/lib/utils/runOpen.js b/lib/utils/runOpen.js index a2757ab919..97b73b24b4 100644 --- a/lib/utils/runOpen.js +++ b/lib/utils/runOpen.js @@ -1,7 +1,6 @@ 'use strict'; const open = require('opn'); -const isAbsoluteUrl = require('is-absolute-url'); function runOpen(uri, options, log) { // https://github.com/webpack/webpack-dev-server/issues/1990 @@ -14,7 +13,7 @@ function runOpen(uri, options, log) { } const pageUrl = - options.openPage && isAbsoluteUrl(options.openPage) + options.openPage && /^(https?:)?\/\//.test(options.openPage) ? options.openPage : `${uri}${options.openPage || ''}`; diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index 3d6ab7de58..d7c2d9aecc 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -268,7 +268,7 @@ describe('contentBase option', () => { }); describe('testing single & multiple external paths', () => { - afterAll((done) => { + afterEach((done) => { testServer.close(() => { done(); }); @@ -301,6 +301,29 @@ describe('contentBase option', () => { done(); } }); + it('Should not throw exception (local path with lower case first character)', (done) => { + try { + // eslint-disable-next-line no-unused-vars + server = new Promise((resolve, reject) => { + testServer.start(config, { + contentBase: + contentBasePublic.charAt(0).toLowerCase() + + contentBasePublic.substring(1), + watchContentBase: true, + port: 2222, + }); + resolve(testServer); + }); + + server.then((testServer) => { + testServer.close(() => { + done(); + }); + }); + } catch (e) { + expect(true).toBe(false); + } + }); it('Should throw exception (array)', (done) => { try { // eslint-disable-next-line no-unused-vars From fded1d8fa0aeac25ce73227937056a057189cfed Mon Sep 17 00:00:00 2001 From: eslam Date: Fri, 16 Aug 2019 18:29:11 +0200 Subject: [PATCH 2/9] fix(server): add checkUrl util & unistall is-absolute-url --- lib/Server.js | 15 +++++---------- lib/utils/checkUrl.js | 7 +++++++ lib/utils/createConfig.js | 8 +++----- lib/utils/runOpen.js | 3 ++- 4 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 lib/utils/checkUrl.js diff --git a/lib/Server.js b/lib/Server.js index 136f0a8d66..2a69d75c8e 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -27,6 +27,7 @@ const normalizeOptions = require('./utils/normalizeOptions'); const updateCompiler = require('./utils/updateCompiler'); const createLogger = require('./utils/createLogger'); const getCertificate = require('./utils/getCertificate'); +const checkUrl = require('./utils/checkUrl'); const status = require('./utils/status'); const createDomain = require('./utils/createDomain'); const runBonjour = require('./utils/runBonjour'); @@ -338,7 +339,7 @@ class Server { contentBase.forEach((item) => { this.app.get('*', express.static(item)); }); - } else if (/^(https?:)?\/\//.test(contentBase)) { + } else if (checkUrl(contentBase)) { this.log.warn( 'Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' ); @@ -389,10 +390,7 @@ class Server { contentBase.forEach((item) => { this.app.get('*', serveIndex(item)); }); - } else if ( - typeof contentBase !== 'number' && - !/^(https?:)?\/\//.test(contentBase) - ) { + } else if (typeof contentBase !== 'number' && !checkUrl(contentBase)) { this.app.get('*', serveIndex(contentBase)); } } @@ -400,14 +398,11 @@ class Server { setupWatchStaticFeature() { const contentBase = this.options.contentBase; - if ( - /^(https?:)?\/\//.test(contentBase) || - typeof contentBase === 'number' - ) { + if (checkUrl(contentBase) || typeof contentBase === 'number') { throw new Error('Watching remote files is not supported.'); } else if (Array.isArray(contentBase)) { contentBase.forEach((item) => { - if (/^(https?:)?\/\//.test(item) || typeof item === 'number') { + if (checkUrl(item) || typeof item === 'number') { throw new Error('Watching remote files is not supported.'); } this._watch(item); diff --git a/lib/utils/checkUrl.js b/lib/utils/checkUrl.js new file mode 100644 index 0000000000..e600bb8f0f --- /dev/null +++ b/lib/utils/checkUrl.js @@ -0,0 +1,7 @@ +'use strict'; + +function checkUrl(url) { + return /^(https?:)?\/\//.test(url); +} + +module.exports = checkUrl; diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index 242acbf5bc..bab5a37914 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -2,6 +2,7 @@ const path = require('path'); const defaultTo = require('./defaultTo'); +const checkUrl = require('./checkUrl'); function createConfig(config, argv, { port }) { const firstWpOpt = Array.isArray(config) ? config[0] : config; @@ -63,10 +64,7 @@ function createConfig(config, argv, { port }) { options.publicPath = (firstWpOpt.output && firstWpOpt.output.publicPath) || ''; - if ( - !/^(https?:)?\/\//.test(options.publicPath) && - options.publicPath[0] !== '/' - ) { + if (!checkUrl(options.publicPath) && options.publicPath[0] !== '/') { options.publicPath = `/${options.publicPath}`; } } @@ -113,7 +111,7 @@ function createConfig(config, argv, { port }) { options.contentBase = options.contentBase.map((p) => path.resolve(p)); } else if (/^[0-9]$/.test(options.contentBase)) { options.contentBase = +options.contentBase; - } else if (!/^(https?:)?\/\//.test(options.contentBase)) { + } else if (!checkUrl(options.contentBase)) { options.contentBase = path.resolve(options.contentBase); } } diff --git a/lib/utils/runOpen.js b/lib/utils/runOpen.js index 97b73b24b4..d625e4ee51 100644 --- a/lib/utils/runOpen.js +++ b/lib/utils/runOpen.js @@ -1,6 +1,7 @@ 'use strict'; const open = require('opn'); +const checkUrl = require('./checkUrl'); function runOpen(uri, options, log) { // https://github.com/webpack/webpack-dev-server/issues/1990 @@ -13,7 +14,7 @@ function runOpen(uri, options, log) { } const pageUrl = - options.openPage && /^(https?:)?\/\//.test(options.openPage) + options.openPage && checkUrl(options.openPage) ? options.openPage : `${uri}${options.openPage || ''}`; From 8a827e81ebc26c30def667bf053e2891174acf88 Mon Sep 17 00:00:00 2001 From: eslam Date: Wed, 21 Aug 2019 14:06:21 +0200 Subject: [PATCH 3/9] test(server): add tests only --- lib/Server.js | 13 ++++++++----- lib/utils/checkUrl.js | 7 ------- lib/utils/createConfig.js | 9 ++++++--- lib/utils/runOpen.js | 4 ++-- 4 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 lib/utils/checkUrl.js diff --git a/lib/Server.js b/lib/Server.js index 2a69d75c8e..a403f4bbac 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -23,11 +23,11 @@ const serveIndex = require('serve-index'); const webpack = require('webpack'); const webpackDevMiddleware = require('webpack-dev-middleware'); const validateOptions = require('schema-utils'); +const isAbsoluteUrl = require('is-absolute-url'); const normalizeOptions = require('./utils/normalizeOptions'); const updateCompiler = require('./utils/updateCompiler'); const createLogger = require('./utils/createLogger'); const getCertificate = require('./utils/getCertificate'); -const checkUrl = require('./utils/checkUrl'); const status = require('./utils/status'); const createDomain = require('./utils/createDomain'); const runBonjour = require('./utils/runBonjour'); @@ -339,7 +339,7 @@ class Server { contentBase.forEach((item) => { this.app.get('*', express.static(item)); }); - } else if (checkUrl(contentBase)) { + } else if (isAbsoluteUrl(String(contentBase))) { this.log.warn( 'Using a URL as contentBase is deprecated and will be removed in the next major version. Please use the proxy option instead.' ); @@ -390,7 +390,10 @@ class Server { contentBase.forEach((item) => { this.app.get('*', serveIndex(item)); }); - } else if (typeof contentBase !== 'number' && !checkUrl(contentBase)) { + } else if ( + typeof contentBase !== 'number' && + !isAbsoluteUrl(String(contentBase)) + ) { this.app.get('*', serveIndex(contentBase)); } } @@ -398,11 +401,11 @@ class Server { setupWatchStaticFeature() { const contentBase = this.options.contentBase; - if (checkUrl(contentBase) || typeof contentBase === 'number') { + if (isAbsoluteUrl(String(contentBase)) || typeof contentBase === 'number') { throw new Error('Watching remote files is not supported.'); } else if (Array.isArray(contentBase)) { contentBase.forEach((item) => { - if (checkUrl(item) || typeof item === 'number') { + if (isAbsoluteUrl(String(item)) || typeof item === 'number') { throw new Error('Watching remote files is not supported.'); } this._watch(item); diff --git a/lib/utils/checkUrl.js b/lib/utils/checkUrl.js deleted file mode 100644 index e600bb8f0f..0000000000 --- a/lib/utils/checkUrl.js +++ /dev/null @@ -1,7 +0,0 @@ -'use strict'; - -function checkUrl(url) { - return /^(https?:)?\/\//.test(url); -} - -module.exports = checkUrl; diff --git a/lib/utils/createConfig.js b/lib/utils/createConfig.js index bab5a37914..0211561235 100644 --- a/lib/utils/createConfig.js +++ b/lib/utils/createConfig.js @@ -1,8 +1,8 @@ 'use strict'; const path = require('path'); +const isAbsoluteUrl = require('is-absolute-url'); const defaultTo = require('./defaultTo'); -const checkUrl = require('./checkUrl'); function createConfig(config, argv, { port }) { const firstWpOpt = Array.isArray(config) ? config[0] : config; @@ -64,7 +64,10 @@ function createConfig(config, argv, { port }) { options.publicPath = (firstWpOpt.output && firstWpOpt.output.publicPath) || ''; - if (!checkUrl(options.publicPath) && options.publicPath[0] !== '/') { + if ( + !isAbsoluteUrl(String(options.publicPath)) && + options.publicPath[0] !== '/' + ) { options.publicPath = `/${options.publicPath}`; } } @@ -111,7 +114,7 @@ function createConfig(config, argv, { port }) { options.contentBase = options.contentBase.map((p) => path.resolve(p)); } else if (/^[0-9]$/.test(options.contentBase)) { options.contentBase = +options.contentBase; - } else if (!checkUrl(options.contentBase)) { + } else if (!isAbsoluteUrl(String(options.contentBase))) { options.contentBase = path.resolve(options.contentBase); } } diff --git a/lib/utils/runOpen.js b/lib/utils/runOpen.js index d625e4ee51..2df2e83da2 100644 --- a/lib/utils/runOpen.js +++ b/lib/utils/runOpen.js @@ -1,7 +1,7 @@ 'use strict'; const open = require('opn'); -const checkUrl = require('./checkUrl'); +const isAbsoluteUrl = require('is-absolute-url'); function runOpen(uri, options, log) { // https://github.com/webpack/webpack-dev-server/issues/1990 @@ -14,7 +14,7 @@ function runOpen(uri, options, log) { } const pageUrl = - options.openPage && checkUrl(options.openPage) + options.openPage && isAbsoluteUrl(String(options.openPage)) ? options.openPage : `${uri}${options.openPage || ''}`; From cdb65eded499c99c1417dc7ad6c78de52cd86c93 Mon Sep 17 00:00:00 2001 From: eslam Date: Wed, 21 Aug 2019 14:39:51 +0200 Subject: [PATCH 4/9] test(server): add more test cases --- lib/utils/runOpen.js | 2 +- test/server/contentBase-option.test.js | 43 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/utils/runOpen.js b/lib/utils/runOpen.js index 2df2e83da2..a2757ab919 100644 --- a/lib/utils/runOpen.js +++ b/lib/utils/runOpen.js @@ -14,7 +14,7 @@ function runOpen(uri, options, log) { } const pageUrl = - options.openPage && isAbsoluteUrl(String(options.openPage)) + options.openPage && isAbsoluteUrl(options.openPage) ? options.openPage : `${uri}${options.openPage || ''}`; diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index d7c2d9aecc..8ac4d7384a 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -324,6 +324,49 @@ describe('contentBase option', () => { expect(true).toBe(false); } }); + it("Should not throw exception (local path with lower case first character & has '-')", (done) => { + try { + // eslint-disable-next-line no-unused-vars + server = new Promise((resolve, reject) => { + testServer.start(config, { + contentBase: 'c:absolutepath\tocontent-base', + watchContentBase: true, + port: 2223, + }); + resolve(testServer); + }); + + server.then((testServer) => { + testServer.close(() => { + done(); + }); + }); + } catch (e) { + expect(true).toBe(false); + } + }); + it("Should not throw exception (local path with upper case first character & has '-')", (done) => { + try { + // eslint-disable-next-line no-unused-vars + server = new Promise((resolve, reject) => { + testServer.start(config, { + contentBase: 'C:absolutepath\tocontent-base', + watchContentBase: true, + port: 2223, + }); + resolve(testServer); + }); + + server.then((testServer) => { + testServer.close(() => { + done(); + }); + }); + } catch (e) { + expect(true).toBe(false); + } + }); + it('Should throw exception (array)', (done) => { try { // eslint-disable-next-line no-unused-vars From c972787e46b1ad34d606ae8b025046d61eb23a61 Mon Sep 17 00:00:00 2001 From: eslam Date: Wed, 21 Aug 2019 14:45:21 +0200 Subject: [PATCH 5/9] test: correct tests' values --- test/server/contentBase-option.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index 8ac4d7384a..e5579c4ec5 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -329,7 +329,7 @@ describe('contentBase option', () => { // eslint-disable-next-line no-unused-vars server = new Promise((resolve, reject) => { testServer.start(config, { - contentBase: 'c:absolutepath\tocontent-base', + contentBase: 'c:\\absolute\\path\\to\\content-base', watchContentBase: true, port: 2223, }); @@ -350,7 +350,7 @@ describe('contentBase option', () => { // eslint-disable-next-line no-unused-vars server = new Promise((resolve, reject) => { testServer.start(config, { - contentBase: 'C:absolutepath\tocontent-base', + contentBase: 'C:\\absolute\\path\\to\\content-base', watchContentBase: true, port: 2223, }); From 1396a98f7635a69dc1f2444d23d8ac7d330903c3 Mon Sep 17 00:00:00 2001 From: eslam Date: Wed, 21 Aug 2019 14:52:06 +0200 Subject: [PATCH 6/9] test: use different port --- test/server/contentBase-option.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index e5579c4ec5..fe120e58fa 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -352,7 +352,7 @@ describe('contentBase option', () => { testServer.start(config, { contentBase: 'C:\\absolute\\path\\to\\content-base', watchContentBase: true, - port: 2223, + port: 2224, }); resolve(testServer); }); From 75630c5e304eac95501b864f87a89766829353a2 Mon Sep 17 00:00:00 2001 From: eslam Date: Wed, 21 Aug 2019 15:16:27 +0200 Subject: [PATCH 7/9] test: use port variable --- test/server/contentBase-option.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index fe120e58fa..722fda5e4e 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -310,7 +310,7 @@ describe('contentBase option', () => { contentBasePublic.charAt(0).toLowerCase() + contentBasePublic.substring(1), watchContentBase: true, - port: 2222, + port: port+1, }); resolve(testServer); }); @@ -331,7 +331,7 @@ describe('contentBase option', () => { testServer.start(config, { contentBase: 'c:\\absolute\\path\\to\\content-base', watchContentBase: true, - port: 2223, + port: port+2, }); resolve(testServer); }); @@ -352,7 +352,7 @@ describe('contentBase option', () => { testServer.start(config, { contentBase: 'C:\\absolute\\path\\to\\content-base', watchContentBase: true, - port: 2224, + port: port+3, }); resolve(testServer); }); From 4a6fea486779853971c8617feb2358ceb804b6b2 Mon Sep 17 00:00:00 2001 From: eslam Date: Wed, 21 Aug 2019 15:28:13 +0200 Subject: [PATCH 8/9] test: fix lint issue --- test/server/contentBase-option.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index 722fda5e4e..78d8c997dc 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -310,13 +310,13 @@ describe('contentBase option', () => { contentBasePublic.charAt(0).toLowerCase() + contentBasePublic.substring(1), watchContentBase: true, - port: port+1, + port: port + 1, }); resolve(testServer); }); - server.then((testServer) => { - testServer.close(() => { + server.then((resolvedServer) => { + resolvedServer.close(() => { done(); }); }); @@ -331,13 +331,13 @@ describe('contentBase option', () => { testServer.start(config, { contentBase: 'c:\\absolute\\path\\to\\content-base', watchContentBase: true, - port: port+2, + port: port + 2, }); resolve(testServer); }); - server.then((testServer) => { - testServer.close(() => { + server.then((resolvedServer) => { + resolvedServer.close(() => { done(); }); }); @@ -352,13 +352,13 @@ describe('contentBase option', () => { testServer.start(config, { contentBase: 'C:\\absolute\\path\\to\\content-base', watchContentBase: true, - port: port+3, + port: port + 3, }); resolve(testServer); }); - server.then((testServer) => { - testServer.close(() => { + server.then((resolvedServer) => { + resolvedServer.close(() => { done(); }); }); From b415ede42370cb60d5f700db0a845d700b4b524b Mon Sep 17 00:00:00 2001 From: eslam Date: Wed, 21 Aug 2019 15:33:02 +0200 Subject: [PATCH 9/9] test: use testServer.start without promises --- test/server/contentBase-option.test.js | 88 +++++++++----------------- 1 file changed, 29 insertions(+), 59 deletions(-) diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index 78d8c997dc..13acc53165 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -302,69 +302,39 @@ describe('contentBase option', () => { } }); it('Should not throw exception (local path with lower case first character)', (done) => { - try { - // eslint-disable-next-line no-unused-vars - server = new Promise((resolve, reject) => { - testServer.start(config, { - contentBase: - contentBasePublic.charAt(0).toLowerCase() + - contentBasePublic.substring(1), - watchContentBase: true, - port: port + 1, - }); - resolve(testServer); - }); - - server.then((resolvedServer) => { - resolvedServer.close(() => { - done(); - }); - }); - } catch (e) { - expect(true).toBe(false); - } + testServer.start( + config, + { + contentBase: + contentBasePublic.charAt(0).toLowerCase() + + contentBasePublic.substring(1), + watchContentBase: true, + port, + }, + done + ); }); it("Should not throw exception (local path with lower case first character & has '-')", (done) => { - try { - // eslint-disable-next-line no-unused-vars - server = new Promise((resolve, reject) => { - testServer.start(config, { - contentBase: 'c:\\absolute\\path\\to\\content-base', - watchContentBase: true, - port: port + 2, - }); - resolve(testServer); - }); - - server.then((resolvedServer) => { - resolvedServer.close(() => { - done(); - }); - }); - } catch (e) { - expect(true).toBe(false); - } + testServer.start( + config, + { + contentBase: 'c:\\absolute\\path\\to\\content-base', + watchContentBase: true, + port, + }, + done + ); }); it("Should not throw exception (local path with upper case first character & has '-')", (done) => { - try { - // eslint-disable-next-line no-unused-vars - server = new Promise((resolve, reject) => { - testServer.start(config, { - contentBase: 'C:\\absolute\\path\\to\\content-base', - watchContentBase: true, - port: port + 3, - }); - resolve(testServer); - }); - - server.then((resolvedServer) => { - resolvedServer.close(() => { - done(); - }); - }); - } catch (e) { - expect(true).toBe(false); - } + testServer.start( + config, + { + contentBase: 'C:\\absolute\\path\\to\\content-base', + watchContentBase: true, + port, + }, + done + ); }); it('Should throw exception (array)', (done) => {