forked from webpack/webpack-dev-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e tests for
setupExitSignals
option (webpack#4130)
Co-authored-by: Alexander Akait <[email protected]>
- Loading branch information
1 parent
afe4975
commit 0dd1ee6
Showing
4 changed files
with
164 additions
and
76 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
test/e2e/__snapshots__/setup-exit-signals.test.js.snap.webpack4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGINT: console messages 1`] = ` | ||
Array [ | ||
"[HMR] Waiting for update signal from WDS...", | ||
"Hey.", | ||
"[webpack-dev-server] Hot Module Replacement enabled.", | ||
"[webpack-dev-server] Live Reloading enabled.", | ||
] | ||
`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGINT: page errors 1`] = `Array []`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGINT: response status 1`] = `200`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGTERM: console messages 1`] = ` | ||
Array [ | ||
"[HMR] Waiting for update signal from WDS...", | ||
"Hey.", | ||
"[webpack-dev-server] Hot Module Replacement enabled.", | ||
"[webpack-dev-server] Live Reloading enabled.", | ||
] | ||
`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGTERM: page errors 1`] = `Array []`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGTERM: response status 1`] = `200`; |
27 changes: 27 additions & 0 deletions
27
test/e2e/__snapshots__/setup-exit-signals.test.js.snap.webpack5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGINT: console messages 1`] = ` | ||
Array [ | ||
"[HMR] Waiting for update signal from WDS...", | ||
"Hey.", | ||
"[webpack-dev-server] Hot Module Replacement enabled.", | ||
"[webpack-dev-server] Live Reloading enabled.", | ||
] | ||
`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGINT: page errors 1`] = `Array []`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGINT: response status 1`] = `200`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGTERM: console messages 1`] = ` | ||
Array [ | ||
"[HMR] Waiting for update signal from WDS...", | ||
"Hey.", | ||
"[webpack-dev-server] Hot Module Replacement enabled.", | ||
"[webpack-dev-server] Live Reloading enabled.", | ||
] | ||
`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGTERM: page errors 1`] = `Array []`; | ||
|
||
exports[`setupExitSignals option should handle 'SIGINT' and 'SIGTERM' signals should close and exit on SIGTERM: response status 1`] = `200`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
"use strict"; | ||
|
||
const webpack = require("webpack"); | ||
const Server = require("../../lib/Server"); | ||
const config = require("../fixtures/simple-config/webpack.config"); | ||
const runBrowser = require("../helpers/run-browser"); | ||
const port = require("../ports-map")["setup-exit-signals-option"]; | ||
|
||
describe("setupExitSignals option", () => { | ||
describe("should handle 'SIGINT' and 'SIGTERM' signals", () => { | ||
let compiler; | ||
let server; | ||
let page; | ||
let browser; | ||
let pageErrors; | ||
let consoleMessages; | ||
let doExit; | ||
let exitSpy; | ||
let stopCallbackSpy; | ||
let stdinResumeSpy; | ||
let closeCallbackSpy; | ||
|
||
const signals = ["SIGINT", "SIGTERM"]; | ||
|
||
beforeEach(async () => { | ||
compiler = webpack(config); | ||
|
||
server = new Server( | ||
{ | ||
setupExitSignals: true, | ||
port, | ||
}, | ||
compiler | ||
); | ||
|
||
await server.start(); | ||
|
||
({ page, browser } = await runBrowser()); | ||
|
||
pageErrors = []; | ||
consoleMessages = []; | ||
doExit = false; | ||
|
||
exitSpy = jest.spyOn(process, "exit").mockImplementation(() => { | ||
doExit = true; | ||
}); | ||
|
||
stdinResumeSpy = jest | ||
.spyOn(process.stdin, "resume") | ||
.mockImplementation(() => {}); | ||
|
||
stopCallbackSpy = jest.spyOn(server, "stopCallback"); | ||
|
||
if (server.compiler.close) { | ||
closeCallbackSpy = jest.spyOn(server.compiler, "close"); | ||
} | ||
}); | ||
|
||
afterEach(async () => { | ||
exitSpy.mockReset(); | ||
stdinResumeSpy.mockReset(); | ||
signals.forEach((signal) => { | ||
process.removeAllListeners(signal); | ||
}); | ||
process.stdin.removeAllListeners("end"); | ||
await browser.close(); | ||
await server.stop(); | ||
}); | ||
|
||
it.each(signals)("should close and exit on %s", async (signal) => { | ||
page | ||
.on("console", (message) => { | ||
consoleMessages.push(message); | ||
}) | ||
.on("pageerror", (error) => { | ||
pageErrors.push(error); | ||
}); | ||
|
||
const response = await page.goto(`http://127.0.0.1:${port}/main`, { | ||
waitUntil: "networkidle0", | ||
}); | ||
|
||
expect(response.status()).toMatchSnapshot("response status"); | ||
|
||
process.emit(signal); | ||
|
||
await new Promise((resolve) => { | ||
const interval = setInterval(() => { | ||
if (doExit) { | ||
expect(stopCallbackSpy.mock.calls.length).toEqual(1); | ||
|
||
if (server.compiler.close) { | ||
expect(closeCallbackSpy.mock.calls.length).toEqual(1); | ||
} | ||
|
||
clearInterval(interval); | ||
|
||
resolve(); | ||
} | ||
}, 100); | ||
}); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
|
||
expect(pageErrors).toMatchSnapshot("page errors"); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.