From f2d87fb2dc3f9545dd9203beda8bf9ac056c70f6 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Wed, 18 Aug 2021 16:50:31 +0300 Subject: [PATCH] fix: improve https CLI output (#3673) --- lib/Server.js | 14 ++++++++------ .../bonjour-option.test.js.snap.webpack4 | 4 +++- .../bonjour-option.test.js.snap.webpack5 | 4 +++- .../http2-option.test.js.snap.webpack4 | 4 +++- .../http2-option.test.js.snap.webpack5 | 4 +++- .../https-option.test.js.snap.webpack4 | 12 +++++++++--- .../https-option.test.js.snap.webpack5 | 12 +++++++++--- test/cli/bonjour-option.test.js | 8 ++++++++ test/cli/http2-option.test.js | 8 ++++++++ test/cli/https-option.test.js | 8 ++++++++ test/helpers/test-bin.js | 3 --- 11 files changed, 62 insertions(+), 19 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 35e8d8973c..45b259f514 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -329,7 +329,7 @@ class Server { const del = require("del"); this.logger.info( - "SSL Certificate is more than 30 days old. Removing." + "SSL Certificate is more than 30 days old. Removing..." ); del.sync([certificatePath], { force: true }); @@ -339,7 +339,7 @@ class Server { } if (!certificateExists) { - this.logger.info("Generating SSL Certificate"); + this.logger.info("Generating SSL Certificate..."); const selfsigned = require("selfsigned"); const attributes = [{ name: "commonName", value: "localhost" }]; @@ -348,10 +348,10 @@ class Server { days: 30, keySize: 2048, extensions: [ - // { - // name: 'basicConstraints', - // cA: true, - // }, + { + name: "basicConstraints", + cA: true, + }, { name: "keyUsage", keyCertSign: true, @@ -412,6 +412,8 @@ class Server { } fakeCert = fs.readFileSync(certificatePath); + + this.logger.info(`SSL certificate: ${certificatePath}`); } options.https.key = options.https.key || fakeCert; diff --git a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 index 361be393ee..690b3c2c75 100644 --- a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"bonjour" CLI option should work using "--bonjour and --https" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ diff --git a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 index 361be393ee..690b3c2c75 100644 --- a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"bonjour" CLI option should work using "--bonjour and --https" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ diff --git a/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 b/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 index 975f36d8b0..faa7d61b75 100644 --- a/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"http2" CLI option should work using "--http2" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ diff --git a/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 b/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 index 975f36d8b0..faa7d61b75 100644 --- a/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"http2" CLI option should work using "--http2" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ diff --git a/test/cli/__snapshots__/https-option.test.js.snap.webpack4 b/test/cli/__snapshots__/https-option.test.js.snap.webpack4 index 9579affe6d..37274d84f4 100644 --- a/test/cli/__snapshots__/https-option.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/https-option.test.js.snap.webpack4 @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"https" CLI option should work using "--https" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ @@ -25,7 +27,9 @@ exports[`"https" CLI option should work using "--https-key --https-pfx

[webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ @@ -41,7 +45,9 @@ exports[`"https" CLI option should work using "--no-https" 1`] = ` `; exports[`"https" CLI option should work using "--no-https-request-cert" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ diff --git a/test/cli/__snapshots__/https-option.test.js.snap.webpack5 b/test/cli/__snapshots__/https-option.test.js.snap.webpack5 index 9579affe6d..37274d84f4 100644 --- a/test/cli/__snapshots__/https-option.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/https-option.test.js.snap.webpack5 @@ -1,7 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"https" CLI option should work using "--https" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ @@ -25,7 +27,9 @@ exports[`"https" CLI option should work using "--https-key --https-pfx

[webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ @@ -41,7 +45,9 @@ exports[`"https" CLI option should work using "--no-https" 1`] = ` `; exports[`"https" CLI option should work using "--no-https-request-cert" 1`] = ` -" [webpack-dev-server] Project is running at: +" [webpack-dev-server] Generating SSL Certificate... + [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem + [webpack-dev-server] Project is running at: [webpack-dev-server] Loopback: https://localhost:/ [webpack-dev-server] On Your Network (IPv4): https://:/ [webpack-dev-server] On Your Network (IPv6): https://[]:/ diff --git a/test/cli/bonjour-option.test.js b/test/cli/bonjour-option.test.js index 9e123320fa..537b58b23c 100644 --- a/test/cli/bonjour-option.test.js +++ b/test/cli/bonjour-option.test.js @@ -1,9 +1,17 @@ "use strict"; +const del = require("del"); +const Server = require("../../lib/Server"); const { testBin, normalizeStderr } = require("../helpers/test-bin"); const port = require("../ports-map")["cli-bonjour"]; +const defaultCertificateDir = Server.findCacheDir(); + describe('"bonjour" CLI option', () => { + beforeEach(async () => { + await del([defaultCertificateDir]); + }); + it('should work using "--bonjour"', async () => { const { exitCode, stderr } = await testBin(["--port", port, "--bonjour"]); diff --git a/test/cli/http2-option.test.js b/test/cli/http2-option.test.js index 3f7f354d9b..8274c6ace4 100644 --- a/test/cli/http2-option.test.js +++ b/test/cli/http2-option.test.js @@ -1,9 +1,17 @@ "use strict"; +const del = require("del"); +const Server = require("../../lib/Server"); const { testBin, normalizeStderr } = require("../helpers/test-bin"); const port = require("../ports-map")["cli-http2"]; +const defaultCertificateDir = Server.findCacheDir(); + describe('"http2" CLI option', () => { + beforeEach(async () => { + await del([defaultCertificateDir]); + }); + it('should work using "--http2"', async () => { const { exitCode, stderr } = await testBin(["--port", port, "--http2"]); diff --git a/test/cli/https-option.test.js b/test/cli/https-option.test.js index 06870f0b84..957d10e94e 100644 --- a/test/cli/https-option.test.js +++ b/test/cli/https-option.test.js @@ -1,6 +1,8 @@ "use strict"; const path = require("path"); +const del = require("del"); +const Server = require("../../lib/Server"); const { testBin, normalizeStderr } = require("../helpers/test-bin"); const port = require("../ports-map")["cli-https"]; @@ -9,7 +11,13 @@ const httpsCertificateDirectory = path.resolve( "../fixtures/https-certificate" ); +const defaultCertificateDir = Server.findCacheDir(); + describe('"https" CLI option', () => { + beforeEach(async () => { + await del([defaultCertificateDir]); + }); + it('should work using "--https"', async () => { const { exitCode, stderr } = await testBin(["--port", port, "--https"]); diff --git a/test/helpers/test-bin.js b/test/helpers/test-bin.js index 9b68584aa4..7f6cceeb8c 100644 --- a/test/helpers/test-bin.js +++ b/test/helpers/test-bin.js @@ -90,9 +90,6 @@ const normalizeStderr = (stderr, options = {}) => { if (options.https) { // We have deprecation warning on windows in some cases normalizedStderr = normalizedStderr.split("\n"); - normalizedStderr = normalizedStderr.filter( - (item) => !/Generating SSL Certificate/g.test(item) - ); normalizedStderr = normalizedStderr.filter( (item) => !/DeprecationWarning: The legacy HTTP parser is deprecated/g.test(item)