Skip to content

Commit 0787620

Browse files
committed
test: add tests for ws & update results
1 parent 3449175 commit 0787620

File tree

4 files changed

+570
-221
lines changed

4 files changed

+570
-221
lines changed

test/e2e/ClientOptions.test.js

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ describe('Client console.log', () => {
364364
host: '0.0.0.0',
365365
quiet: true,
366366
};
367+
const transportModes = [
368+
{},
369+
{ transportMode: 'sockjs' },
370+
{ transportMode: 'ws' },
371+
];
367372
const cases = [
368373
{
369374
title: 'hot disabled',
@@ -389,6 +394,13 @@ describe('Client console.log', () => {
389394
liveReload: true,
390395
},
391396
},
397+
{
398+
title: 'liveReload & hot are disabled',
399+
options: {
400+
liveReload: false,
401+
hot: false,
402+
},
403+
},
392404
// TODO: make clientLogLevel work as expected for HMR logs
393405
{
394406
title: 'clientLogLevel is silent',
@@ -398,48 +410,54 @@ describe('Client console.log', () => {
398410
},
399411
];
400412

401-
cases.forEach(({ title, options }) => {
402-
it(title, (done) => {
403-
const res = [];
404-
const testOptions = Object.assign({}, baseOptions, options);
405-
406-
// TODO: use async/await when Node.js v6 support is dropped
407-
Promise.resolve()
408-
.then(() => {
409-
return new Promise((resolve) => {
410-
testServer.startAwaitingCompilation(config, testOptions, resolve);
411-
});
412-
})
413-
.then(() => {
414-
// make sure the previous Promise is not passing along strange arguments to runBrowser
415-
return runBrowser();
416-
})
417-
.then(({ page, browser }) => {
418-
return new Promise((resolve) => {
419-
page.goto(`http://localhost:${port2}/main`);
420-
page.on('console', ({ _text }) => {
421-
res.push(_text);
413+
transportModes.forEach((mode) => {
414+
cases.forEach(({ title, options }) => {
415+
title += ` (${
416+
Object.keys(mode).length ? mode.transportMode : 'default'
417+
})`;
418+
options = { ...mode, ...options };
419+
it(title, (done) => {
420+
const res = [];
421+
const testOptions = Object.assign({}, baseOptions, options);
422+
423+
// TODO: use async/await when Node.js v6 support is dropped
424+
Promise.resolve()
425+
.then(() => {
426+
return new Promise((resolve) => {
427+
testServer.startAwaitingCompilation(config, testOptions, resolve);
422428
});
423-
// wait for load before closing the browser
424-
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
425-
page.waitFor(beforeBrowserCloseDelay).then(() => {
426-
browser.close().then(() => {
427-
resolve();
429+
})
430+
.then(() => {
431+
// make sure the previous Promise is not passing along strange arguments to runBrowser
432+
return runBrowser();
433+
})
434+
.then(({ page, browser }) => {
435+
return new Promise((resolve) => {
436+
page.goto(`http://localhost:${port2}/main`);
437+
page.on('console', ({ _text }) => {
438+
res.push(_text);
439+
});
440+
// wait for load before closing the browser
441+
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
442+
page.waitFor(beforeBrowserCloseDelay).then(() => {
443+
browser.close().then(() => {
444+
resolve();
445+
});
428446
});
429447
});
430448
});
449+
})
450+
.then(() => {
451+
return new Promise((resolve) => {
452+
testServer.close(resolve);
453+
});
454+
})
455+
.then(() => {
456+
// Order doesn't matter, maybe we should improve that in future
457+
expect(res.sort()).toMatchSnapshot();
458+
done();
431459
});
432-
})
433-
.then(() => {
434-
return new Promise((resolve) => {
435-
testServer.close(resolve);
436-
});
437-
})
438-
.then(() => {
439-
// Order doesn't matter, maybe we should improve that in future
440-
expect(res.sort()).toMatchSnapshot();
441-
done();
442-
});
460+
});
443461
});
444462
});
445463
});

test/e2e/__snapshots__/ClientOptions.test.js.snap

Lines changed: 112 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Client console.log clientLogLevel is silent 1`] = `
3+
exports[`Client console.log clientLogLevel is silent (default) 1`] = `
44
Array [
55
"Hey.",
66
"[HMR] Waiting for update signal from WDS...",
77
]
88
`;
99

10-
exports[`Client console.log hot disabled 1`] = `
10+
exports[`Client console.log clientLogLevel is silent (sockjs) 1`] = `
11+
Array [
12+
"Hey.",
13+
"[HMR] Waiting for update signal from WDS...",
14+
]
15+
`;
16+
17+
exports[`Client console.log clientLogLevel is silent (ws) 1`] = `
18+
Array [
19+
"Hey.",
20+
"[HMR] Waiting for update signal from WDS...",
21+
]
22+
`;
23+
24+
exports[`Client console.log hot disabled (default) 1`] = `
25+
Array [
26+
"Hey.",
27+
"[WDS] Live Reloading enabled.",
28+
]
29+
`;
30+
31+
exports[`Client console.log hot disabled (sockjs) 1`] = `
32+
Array [
33+
"Hey.",
34+
"[WDS] Live Reloading enabled.",
35+
]
36+
`;
37+
38+
exports[`Client console.log hot disabled (ws) 1`] = `
1139
Array [
1240
"Hey.",
1341
"[WDS] Live Reloading enabled.",
1442
]
1543
`;
1644

17-
exports[`Client console.log hot enabled 1`] = `
45+
exports[`Client console.log hot enabled (default) 1`] = `
1846
Array [
1947
"Hey.",
2048
"[HMR] Waiting for update signal from WDS...",
@@ -23,16 +51,94 @@ Array [
2351
]
2452
`;
2553

26-
exports[`Client console.log liveReload disabled 1`] = `
54+
exports[`Client console.log hot enabled (sockjs) 1`] = `
2755
Array [
2856
"Hey.",
29-
"Failed to load resource: the server responded with a status of 404 (Not Found)",
57+
"[HMR] Waiting for update signal from WDS...",
58+
"[WDS] Hot Module Replacement enabled.",
59+
"[WDS] Live Reloading enabled.",
60+
]
61+
`;
62+
63+
exports[`Client console.log hot enabled (ws) 1`] = `
64+
Array [
65+
"Hey.",
66+
"[HMR] Waiting for update signal from WDS...",
67+
"[WDS] Hot Module Replacement enabled.",
68+
"[WDS] Live Reloading enabled.",
69+
]
70+
`;
71+
72+
exports[`Client console.log liveReload & hot are disabled (default) 1`] = `
73+
Array [
74+
"Hey.",
75+
"WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404",
76+
"WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404",
3077
"[WDS] Hot Module Replacement & Live Reloading are disabled!",
78+
]
79+
`;
80+
81+
exports[`Client console.log liveReload & hot are disabled (sockjs) 1`] = `
82+
Array [
83+
"Failed to load resource: the server responded with a status of 404 (Not Found)",
3184
"Failed to load resource: the server responded with a status of 404 (Not Found)",
85+
"Hey.",
86+
"[WDS] Hot Module Replacement & Live Reloading are disabled!",
87+
]
88+
`;
89+
90+
exports[`Client console.log liveReload & hot are disabled (ws) 1`] = `
91+
Array [
92+
"Hey.",
93+
"WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404",
94+
"WebSocket connection to 'ws://localhost:8096/ws' failed: Error during WebSocket handshake: Unexpected response code: 404",
95+
"[WDS] Hot Module Replacement & Live Reloading are disabled!",
96+
]
97+
`;
98+
99+
exports[`Client console.log liveReload disabled (default) 1`] = `
100+
Array [
101+
"Hey.",
102+
"[HMR] Waiting for update signal from WDS...",
103+
"[WDS] Hot Module Replacement enabled.",
104+
]
105+
`;
106+
107+
exports[`Client console.log liveReload disabled (sockjs) 1`] = `
108+
Array [
109+
"Hey.",
110+
"[HMR] Waiting for update signal from WDS...",
111+
"[WDS] Hot Module Replacement enabled.",
112+
]
113+
`;
114+
115+
exports[`Client console.log liveReload disabled (ws) 1`] = `
116+
Array [
117+
"Hey.",
118+
"[HMR] Waiting for update signal from WDS...",
119+
"[WDS] Hot Module Replacement enabled.",
120+
]
121+
`;
122+
123+
exports[`Client console.log liveReload enabled (default) 1`] = `
124+
Array [
125+
"Hey.",
126+
"[HMR] Waiting for update signal from WDS...",
127+
"[WDS] Hot Module Replacement enabled.",
128+
"[WDS] Live Reloading enabled.",
129+
]
130+
`;
131+
132+
exports[`Client console.log liveReload enabled (sockjs) 1`] = `
133+
Array [
134+
"Hey.",
135+
"[HMR] Waiting for update signal from WDS...",
136+
"[WDS] Hot Module Replacement enabled.",
137+
"[WDS] Live Reloading enabled.",
32138
]
33139
`;
34140

35-
exports[`Client console.log liveReload enabled 1`] = `
141+
exports[`Client console.log liveReload enabled (ws) 1`] = `
36142
Array [
37143
"Hey.",
38144
"[HMR] Waiting for update signal from WDS...",

0 commit comments

Comments
 (0)