Skip to content

Commit 1c8757b

Browse files
test: more
1 parent 70a1044 commit 1c8757b

File tree

5 files changed

+126
-48
lines changed

5 files changed

+126
-48
lines changed

client-src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ self.addEventListener('beforeunload', () => {
4444

4545
const onSocketMessage = {
4646
hot() {
47+
if (parsedResourceQuery.hot === 'false') {
48+
return;
49+
}
50+
4751
options.hot = true;
4852

4953
log.info('Hot Module Replacement enabled.');
5054
},
5155
liveReload() {
56+
if (parsedResourceQuery['live-reload'] === 'false') {
57+
return;
58+
}
59+
5260
options.liveReload = true;
5361

5462
log.info('Live Reloading enabled.');

test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack4

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,26 @@ Array [
308308
`;
309309

310310
exports[`hot and live reload should work and refresh content using live reload when live reload enabled and hot disabled (ws): page errors 1`] = `Array []`;
311+
312+
exports[`hot and live reload should work with manual client setup (default): console messages 1`] = `
313+
Array [
314+
"[HMR] Waiting for update signal from WDS...",
315+
"[webpack-dev-server] Hot Module Replacement enabled.",
316+
"[webpack-dev-server] Live Reloading enabled.",
317+
]
318+
`;
319+
320+
exports[`hot and live reload should work with manual client setup (default): page errors 1`] = `Array []`;
321+
322+
exports[`hot and live reload should work with manual client setup and allow to disable hot module replacement (default): console messages 1`] = `
323+
Array [
324+
"[HMR] Waiting for update signal from WDS...",
325+
"[webpack-dev-server] Live Reloading enabled.",
326+
]
327+
`;
328+
329+
exports[`hot and live reload should work with manual client setup and allow to disable hot module replacement (default): page errors 1`] = `Array []`;
330+
331+
exports[`hot and live reload should work with manual client setup and allow to disable live reload (default): console messages 1`] = `Array []`;
332+
333+
exports[`hot and live reload should work with manual client setup and allow to disable live reload (default): page errors 1`] = `Array []`;

test/e2e/__snapshots__/hot-and-live-reload.test.js.snap.webpack5

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,3 +308,26 @@ Array [
308308
`;
309309

310310
exports[`hot and live reload should work and refresh content using live reload when live reload enabled and hot disabled (ws): page errors 1`] = `Array []`;
311+
312+
exports[`hot and live reload should work with manual client setup (default): console messages 1`] = `
313+
Array [
314+
"[HMR] Waiting for update signal from WDS...",
315+
"[webpack-dev-server] Hot Module Replacement enabled.",
316+
"[webpack-dev-server] Live Reloading enabled.",
317+
]
318+
`;
319+
320+
exports[`hot and live reload should work with manual client setup (default): page errors 1`] = `Array []`;
321+
322+
exports[`hot and live reload should work with manual client setup and allow to disable hot module replacement (default): console messages 1`] = `
323+
Array [
324+
"[HMR] Waiting for update signal from WDS...",
325+
"[webpack-dev-server] Live Reloading enabled.",
326+
]
327+
`;
328+
329+
exports[`hot and live reload should work with manual client setup and allow to disable hot module replacement (default): page errors 1`] = `Array []`;
330+
331+
exports[`hot and live reload should work with manual client setup and allow to disable live reload (default): console messages 1`] = `Array []`;
332+
333+
exports[`hot and live reload should work with manual client setup and allow to disable live reload (default): page errors 1`] = `Array []`;

test/e2e/hot-and-live-reload.test.js

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,51 @@ describe('hot and live reload', () => {
215215
hot: true,
216216
},
217217
},
218+
{
219+
title: 'should work with manual client setup',
220+
webpackOptions: {
221+
entry: [
222+
require.resolve('../../client-src/index.js'),
223+
require.resolve('../fixtures/reload-config/foo.js'),
224+
],
225+
},
226+
options: {
227+
client: false,
228+
liveReload: true,
229+
hot: true,
230+
},
231+
},
232+
// TODO we still output logs from webpack, need to improve this
233+
{
234+
title:
235+
'should work with manual client setup and allow to disable hot module replacement',
236+
webpackOptions: {
237+
entry: [
238+
`${require.resolve('../../client-src/index.js')}?hot=false`,
239+
require.resolve('../fixtures/reload-config/foo.js'),
240+
],
241+
},
242+
options: {
243+
client: false,
244+
liveReload: true,
245+
hot: true,
246+
},
247+
},
248+
{
249+
title:
250+
'should work with manual client setup and allow to disable live reload',
251+
webpackOptions: {
252+
entry: [
253+
`${require.resolve('../../client-src/index.js')}?live-reload=false`,
254+
require.resolve('../fixtures/reload-config/foo.js'),
255+
],
256+
},
257+
options: {
258+
client: false,
259+
liveReload: true,
260+
hot: false,
261+
},
262+
},
218263
];
219264

220265
modes.forEach((mode) => {
@@ -229,7 +274,8 @@ describe('hot and live reload', () => {
229274
'body { background-color: rgb(0, 0, 255); }'
230275
);
231276

232-
const compiler = webpack(reloadConfig);
277+
const webpackOptions = { ...reloadConfig, ...mode.webpackOptions };
278+
const compiler = webpack(webpackOptions);
233279
const devServerOptions = {
234280
host: '0.0.0.0',
235281
port,
@@ -407,10 +453,31 @@ describe('hot and live reload', () => {
407453
let doNothing = false;
408454

409455
const query = mode.query || '';
410-
const allowToHotModuleReplacement =
411-
query.indexOf('webpack-dev-server-hot=false') === -1;
412-
const allowToLiveReload =
413-
query.indexOf('webpack-dev-server-live-reload=false') === -1;
456+
let allowToHotModuleReplacement = true;
457+
458+
if (query.indexOf('webpack-dev-server-hot=false') !== -1) {
459+
allowToHotModuleReplacement = false;
460+
}
461+
462+
if (
463+
Array.isArray(webpackOptions.entry) &&
464+
webpackOptions.entry.map((item) => item.includes('hot=false'))
465+
) {
466+
allowToHotModuleReplacement = false;
467+
}
468+
469+
let allowToLiveReload = true;
470+
471+
if (query.indexOf('webpack-dev-server-live-reload=false') !== -1) {
472+
allowToLiveReload = false;
473+
}
474+
475+
if (
476+
Array.isArray(webpackOptions.entry) &&
477+
webpackOptions.entry.map((item) => item.includes('live-reload=false'))
478+
) {
479+
allowToLiveReload = false;
480+
}
414481

415482
if (
416483
allowToHotModuleReplacement &&

test/e2e/web-socket-server-and-transport.test.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -358,49 +358,6 @@ describe('web socket server and transport', () => {
358358
});
359359
});
360360

361-
it.only('should allow to disable default client', async () => {
362-
const compiler = webpack(defaultConfig);
363-
const devServerOptions = {
364-
port,
365-
client: false,
366-
};
367-
const server = new Server(devServerOptions, compiler);
368-
369-
await new Promise((resolve, reject) => {
370-
server.listen(devServerOptions.port, devServerOptions.host, (error) => {
371-
if (error) {
372-
reject(error);
373-
374-
return;
375-
}
376-
377-
resolve();
378-
});
379-
});
380-
381-
const { page, browser } = await runBrowser();
382-
383-
const consoleMessages = [];
384-
385-
page.on('console', (message) => {
386-
consoleMessages.push(message);
387-
});
388-
389-
await page.goto(`http://localhost:${port}/main`, {
390-
waitUntil: 'networkidle0',
391-
});
392-
393-
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot();
394-
395-
await browser.close();
396-
397-
await new Promise((resolve) => {
398-
server.close(() => {
399-
resolve();
400-
});
401-
});
402-
});
403-
404361
it('should use custom web socket server when specify path to class', async () => {
405362
const compiler = webpack(defaultConfig);
406363
const devServerOptions = {

0 commit comments

Comments
 (0)