Skip to content

Commit

Permalink
test: for HMR warning
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Aug 25, 2021
1 parent 296dc83 commit 03a9189
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions test/server/hot-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,73 @@ describe("hot option", () => {
});
});

describe("simple config with already added HMR plugin", () => {
let loggerWarnSpy;
let getInfrastructureLoggerSpy;
let compiler;

beforeEach(() => {
compiler = webpack({
...config,
devServer: { hot: false },
plugins: [...config.plugins, new webpack.HotModuleReplacementPlugin()],
});

loggerWarnSpy = jest.fn();

getInfrastructureLoggerSpy = jest
.spyOn(compiler, "getInfrastructureLogger")
.mockImplementation(() => {
return {
warn: loggerWarnSpy,
info: () => {},
log: () => {},
};
});
});

afterEach(() => {
getInfrastructureLoggerSpy.mockRestore();
loggerWarnSpy.mockRestore();
});

it("should show warning with hot normalized as true", async () => {
server = new Server({ port }, compiler);

await server.start();

expect(loggerWarnSpy).toHaveBeenCalledWith(
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
);

await server.stop();
});

it(`should show warning with "hot: true"`, async () => {
server = new Server({ port, hot: true }, compiler);

await server.start();

expect(loggerWarnSpy).toHaveBeenCalledWith(
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
);

await server.stop();
});

it(`should show warning with "hot: false"`, async () => {
server = new Server({ port, hot: false }, compiler);

await server.start();

expect(loggerWarnSpy).not.toHaveBeenCalledWith(
`"hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.`
);

await server.stop();
});
});

describe("multi compiler hot config HMR plugin", () => {
it("should register the HMR plugin before compilation is complete", async () => {
let pluginFound = false;
Expand Down

0 comments on commit 03a9189

Please sign in to comment.