Skip to content

Commit d28f6af

Browse files
committed
refactor: code
1 parent 8fc6816 commit d28f6af

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/Server.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const os = require("os");
44
const path = require("path");
55
const url = require("url");
6+
const util = require("util");
67
const fs = require("graceful-fs");
78
const ipaddr = require("ipaddr.js");
89
const internalIp = require("internal-ip");
@@ -18,12 +19,15 @@ if (!process.env.WEBPACK_SERVE) {
1819
class Server {
1920
constructor(options = {}, compiler) {
2021
// TODO: remove this after plugin support is published
22+
23+
const showDeprecationWarning = util.deprecate(
24+
() => {},
25+
"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument.",
26+
"DEP_WEBPACK_DEV_SERVER_API"
27+
);
28+
2129
if (options.hooks) {
22-
process.emitWarning(
23-
"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument.",
24-
"DeprecationWarning",
25-
"DEP_WEBPACK_DEV_SERVER_API"
26-
);
30+
showDeprecationWarning();
2731
[options, compiler] = [compiler, options];
2832
}
2933

test/server/Server.test.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,13 @@ describe("Server", () => {
9393
// TODO: remove this after plugin support is published
9494
it("should create and run server with old parameters order and log deprecation warning", (done) => {
9595
const compiler = webpack(config);
96-
const processSpy = jest.spyOn(process, "emitWarning");
96+
const util = require("util");
97+
const utilSpy = jest.spyOn(util, "deprecate");
9798

9899
const server = new Server(compiler, baseDevConfig);
99100

100-
expect(processSpy).toHaveBeenCalledWith(
101-
"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument.",
102-
"DeprecationWarning",
103-
"DEP_WEBPACK_DEV_SERVER_API"
101+
expect(utilSpy.mock.calls[0][1]).toBe(
102+
"Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument."
104103
);
105104

106105
compiler.hooks.done.tap("webpack-dev-server", () => {
@@ -117,7 +116,7 @@ describe("Server", () => {
117116
getEntries(server);
118117
});
119118

120-
processSpy.mockRestore();
119+
utilSpy.mockRestore();
121120
});
122121
});
123122

0 commit comments

Comments
 (0)