Skip to content

Commit 03a9189

Browse files
committed
test: for HMR warning
1 parent 296dc83 commit 03a9189

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/server/hot-option.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,73 @@ describe("hot option", () => {
166166
});
167167
});
168168

169+
describe("simple config with already added HMR plugin", () => {
170+
let loggerWarnSpy;
171+
let getInfrastructureLoggerSpy;
172+
let compiler;
173+
174+
beforeEach(() => {
175+
compiler = webpack({
176+
...config,
177+
devServer: { hot: false },
178+
plugins: [...config.plugins, new webpack.HotModuleReplacementPlugin()],
179+
});
180+
181+
loggerWarnSpy = jest.fn();
182+
183+
getInfrastructureLoggerSpy = jest
184+
.spyOn(compiler, "getInfrastructureLogger")
185+
.mockImplementation(() => {
186+
return {
187+
warn: loggerWarnSpy,
188+
info: () => {},
189+
log: () => {},
190+
};
191+
});
192+
});
193+
194+
afterEach(() => {
195+
getInfrastructureLoggerSpy.mockRestore();
196+
loggerWarnSpy.mockRestore();
197+
});
198+
199+
it("should show warning with hot normalized as true", async () => {
200+
server = new Server({ port }, compiler);
201+
202+
await server.start();
203+
204+
expect(loggerWarnSpy).toHaveBeenCalledWith(
205+
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
206+
);
207+
208+
await server.stop();
209+
});
210+
211+
it(`should show warning with "hot: true"`, async () => {
212+
server = new Server({ port, hot: true }, compiler);
213+
214+
await server.start();
215+
216+
expect(loggerWarnSpy).toHaveBeenCalledWith(
217+
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
218+
);
219+
220+
await server.stop();
221+
});
222+
223+
it(`should show warning with "hot: false"`, async () => {
224+
server = new Server({ port, hot: false }, compiler);
225+
226+
await server.start();
227+
228+
expect(loggerWarnSpy).not.toHaveBeenCalledWith(
229+
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
230+
);
231+
232+
await server.stop();
233+
});
234+
});
235+
169236
describe("multi compiler hot config HMR plugin", () => {
170237
it("should register the HMR plugin before compilation is complete", async () => {
171238
let pluginFound = false;

0 commit comments

Comments
 (0)