From 18bf369fcdce63b1e1653c53f7277c2860f75609 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Wed, 18 Aug 2021 21:04:06 +0300 Subject: [PATCH] test: fix stability (#3676) --- .../bonjour-option.test.js.snap.webpack4 | 3 +-- .../bonjour-option.test.js.snap.webpack5 | 3 +-- .../http2-option.test.js.snap.webpack4 | 3 +-- .../http2-option.test.js.snap.webpack5 | 3 +-- .../https-option.test.js.snap.webpack4 | 9 +++---- .../https-option.test.js.snap.webpack5 | 9 +++---- test/helpers/test-bin.js | 3 +++ test/server/setupExitSignals-option.test.js | 24 +++++++++++++------ 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 index 690b3c2c75..bb6c172a07 100644 --- a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack4 @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"bonjour" CLI option should work using "--bonjour and --https" 1`] = ` -" [webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ diff --git a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 index 690b3c2c75..bb6c172a07 100644 --- a/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/bonjour-option.test.js.snap.webpack5 @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"bonjour" CLI option should work using "--bonjour and --https" 1`] = ` -" [webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ diff --git a/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 b/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 index faa7d61b75..7d9985a08f 100644 --- a/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/http2-option.test.js.snap.webpack4 @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"http2" CLI option should work using "--http2" 1`] = ` -" [webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ diff --git a/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 b/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 index faa7d61b75..7d9985a08f 100644 --- a/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/http2-option.test.js.snap.webpack5 @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"http2" CLI option should work using "--http2" 1`] = ` -" [webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ diff --git a/test/cli/__snapshots__/https-option.test.js.snap.webpack4 b/test/cli/__snapshots__/https-option.test.js.snap.webpack4 index 37274d84f4..294b181331 100644 --- a/test/cli/__snapshots__/https-option.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/https-option.test.js.snap.webpack4 @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"https" CLI option should work using "--https" 1`] = ` -" [webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ @@ -27,8 +26,7 @@ exports[`"https" CLI option should work using "--https-key --https-pfx

[webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ @@ -45,8 +43,7 @@ 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] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ diff --git a/test/cli/__snapshots__/https-option.test.js.snap.webpack5 b/test/cli/__snapshots__/https-option.test.js.snap.webpack5 index 37274d84f4..294b181331 100644 --- a/test/cli/__snapshots__/https-option.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/https-option.test.js.snap.webpack5 @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`"https" CLI option should work using "--https" 1`] = ` -" [webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ @@ -27,8 +26,7 @@ exports[`"https" CLI option should work using "--https-key --https-pfx

[webpack-dev-server] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ @@ -45,8 +43,7 @@ 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] Generating SSL Certificate... - [webpack-dev-server] SSL certificate: /node_modules/.cache/webpack-dev-server/server.pem +" [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://:/ diff --git a/test/helpers/test-bin.js b/test/helpers/test-bin.js index 7f6cceeb8c..9b68584aa4 100644 --- a/test/helpers/test-bin.js +++ b/test/helpers/test-bin.js @@ -90,6 +90,9 @@ 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) diff --git a/test/server/setupExitSignals-option.test.js b/test/server/setupExitSignals-option.test.js index 999a14f319..68f8dcafc2 100644 --- a/test/server/setupExitSignals-option.test.js +++ b/test/server/setupExitSignals-option.test.js @@ -7,6 +7,7 @@ const port = require("../ports-map")["setup-exit-signals-option"]; describe("setupExitSignals option", () => { let server; + let doExit; let exitSpy; let stopCallbackSpy; let stdinResumeSpy; @@ -26,7 +27,11 @@ describe("setupExitSignals option", () => { await server.start(); - exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {}); + doExit = false; + + exitSpy = jest.spyOn(process, "exit").mockImplementation(() => { + doExit = true; + }); stdinResumeSpy = jest .spyOn(process.stdin, "resume") .mockImplementation(() => {}); @@ -44,14 +49,19 @@ describe("setupExitSignals option", () => { await server.stop(); }); - it.each(signals)("should close and exit on %s", (signal, done) => { + it.each(signals)("should close and exit on %s", async (signal) => { process.emit(signal); - setTimeout(() => { - expect(stopCallbackSpy.mock.calls.length).toEqual(1); - expect(exitSpy.mock.calls.length).toEqual(1); + await new Promise((resolve) => { + const interval = setInterval(() => { + if (doExit) { + expect(stopCallbackSpy.mock.calls.length).toEqual(1); - done(); - }, 1000); + clearInterval(interval); + + resolve(); + } + }, 100); + }); }); });