Skip to content

Commit c3ef1b7

Browse files
test: fix
1 parent d9b9d98 commit c3ef1b7

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

lib/Server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ class Server {
769769
// eslint-disable-next-line no-shadow
770770
.then((port) => {
771771
this.port = port;
772+
772773
return this.server.listen(port, this.hostname, (error) => {
773774
if (this.options.hot || this.options.liveReload) {
774775
this.createSocketServer();

test/e2e/ClientOptions.test.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { beforeBrowserCloseDelay } = require('../helpers/puppeteer-constants');
1212
describe('sockjs client proxy', () => {
1313
function startProxy(port, cb) {
1414
const proxy = express();
15+
1516
proxy.use(
1617
'/',
1718
createProxyMiddleware({
@@ -21,6 +22,7 @@ describe('sockjs client proxy', () => {
2122
logLevel: 'warn',
2223
})
2324
);
25+
2426
return proxy.listen(port, cb);
2527
}
2628

@@ -33,6 +35,7 @@ describe('sockjs client proxy', () => {
3335
firewall: false,
3436
hot: true,
3537
};
38+
3639
testServer.startAwaitingCompilation(config, options, done);
3740
});
3841

@@ -54,11 +57,13 @@ describe('sockjs client proxy', () => {
5457

5558
it('responds with a 200 on proxy port', (done) => {
5659
const req = request(`http://localhost:${port2}`);
60+
5761
req.get('/ws').expect(200, 'Welcome to SockJS!\n', done);
5862
});
5963

6064
it('responds with a 200 on non-proxy port', (done) => {
6165
const req = request(`http://localhost:${port1}`);
66+
6267
req.get('/ws').expect(200, 'Welcome to SockJS!\n', done);
6368
});
6469

@@ -70,12 +75,14 @@ describe('sockjs client proxy', () => {
7075
page.waitForTimeout(beforeBrowserCloseDelay).then(() => {
7176
browser.close().then(() => {
7277
expect(requestObj.url()).toContain(
73-
`http://localhost:${port2}/ws`
78+
`http://localhost:${port1}/ws`
7479
);
80+
7581
done();
7682
});
7783
});
7884
});
85+
7986
page.goto(`http://localhost:${port2}/main`);
8087
});
8188
});
@@ -85,6 +92,7 @@ describe('sockjs client proxy', () => {
8592
describe('ws client proxy', () => {
8693
function startProxy(port, cb) {
8794
const proxy = express();
95+
8896
proxy.use(
8997
'/',
9098
createProxyMiddleware({
@@ -93,6 +101,7 @@ describe('ws client proxy', () => {
93101
changeOrigin: true,
94102
})
95103
);
104+
96105
return proxy.listen(port, cb);
97106
}
98107

@@ -106,6 +115,7 @@ describe('ws client proxy', () => {
106115
hot: true,
107116
public: 'myhost',
108117
};
118+
109119
testServer.startAwaitingCompilation(config, options, done);
110120
});
111121

@@ -132,14 +142,17 @@ describe('ws client proxy', () => {
132142
it('requests websocket through the proxy with proper port number', (done) => {
133143
runBrowser().then(({ page, browser }) => {
134144
const client = page._client;
145+
135146
client.on('Network.webSocketCreated', (evt) => {
136147
page.waitForTimeout(beforeBrowserCloseDelay).then(() => {
137148
browser.close().then(() => {
138-
expect(evt.url).toContain(`ws://myhost:${port2}/ws`);
149+
expect(evt.url).toContain(`ws://myhost:${port1}/ws`);
150+
139151
done();
140152
});
141153
});
142154
});
155+
143156
page.goto(`http://localhost:${port2}/main`);
144157
});
145158
});
@@ -157,6 +170,7 @@ describe('sockjs public and client path', () => {
157170
path: '/foo/test/bar/',
158171
},
159172
};
173+
160174
testServer.startAwaitingCompilation(config, options, done);
161175
});
162176

@@ -175,10 +189,12 @@ describe('sockjs public and client path', () => {
175189
expect(requestObj.url()).toContain(
176190
`http://myhost.test:${port2}/foo/test/bar`
177191
);
192+
178193
done();
179194
});
180195
});
181196
});
197+
182198
page.goto(`http://localhost:${port2}/main`);
183199
});
184200
});
@@ -196,6 +212,7 @@ describe('sockjs client path and port', () => {
196212
port: port3,
197213
},
198214
};
215+
199216
testServer.startAwaitingCompilation(config, options, done);
200217
});
201218

@@ -214,6 +231,7 @@ describe('sockjs client path and port', () => {
214231
expect(requestObj.url()).toContain(
215232
`http://localhost:${port3}/foo/test/bar`
216233
);
234+
217235
done();
218236
});
219237
});
@@ -238,6 +256,7 @@ describe('sockjs client port, no path', () => {
238256
port: port3,
239257
},
240258
};
259+
241260
testServer.startAwaitingCompilation(config, options, done);
242261
});
243262

@@ -254,10 +273,12 @@ describe('sockjs client port, no path', () => {
254273
expect(requestObj.url()).toContain(
255274
`http://localhost:${port3}/ws`
256275
);
276+
257277
done();
258278
});
259279
});
260280
});
281+
261282
page.goto(`http://localhost:${port2}/main`);
262283
});
263284
});
@@ -290,10 +311,12 @@ describe('sockjs client host', () => {
290311
expect(requestObj.url()).toContain(
291312
`http://myhost.test:${port2}/ws`
292313
);
314+
293315
done();
294316
});
295317
});
296318
});
319+
297320
page.goto(`http://localhost:${port2}/main`);
298321
});
299322
});
@@ -312,6 +335,7 @@ describe('ws client host, port, and path', () => {
312335
path: '/foo/test/bar/',
313336
},
314337
};
338+
315339
testServer.startAwaitingCompilation(config, options, done);
316340
});
317341

@@ -325,10 +349,12 @@ describe('ws client host, port, and path', () => {
325349
it('uses correct host, port, and path', (done) => {
326350
runBrowser().then(({ page, browser }) => {
327351
const client = page._client;
352+
328353
client.on('Network.webSocketCreated', (evt) => {
329354
page.waitForTimeout(beforeBrowserCloseDelay).then(() => {
330355
browser.close().then(() => {
331356
expect(evt.url).toContain(`ws://myhost:${port3}/foo/test/bar`);
357+
332358
done();
333359
});
334360
});

test/server/__snapshots__/Server.test.js.snap.webpack4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Array [
55
Array [
66
"client",
77
"index.js?http:",
8-
"0.0.0.0",
8+
"0.0.0.0&port=8100",
99
],
1010
Array [
1111
"node_modules",
@@ -24,7 +24,7 @@ Array [
2424
Array [
2525
"client",
2626
"index.js?http:",
27-
"0.0.0.0",
27+
"0.0.0.0&port=8100",
2828
],
2929
Array [
3030
"node_modules",

test/server/__snapshots__/Server.test.js.snap.webpack5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Array [
55
Array [
66
"client",
77
"index.js?http:",
8-
"0.0.0.0",
8+
"0.0.0.0&port=8100",
99
],
1010
Array [
1111
"node_modules",
@@ -24,7 +24,7 @@ Array [
2424
Array [
2525
"client",
2626
"index.js?http:",
27-
"0.0.0.0",
27+
"0.0.0.0&port=8100",
2828
],
2929
Array [
3030
"node_modules",

test/server/utils/findPort.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ describe('findPort', () => {
3131
(p, _, i) =>
3232
p.then(
3333
() =>
34-
new Promise((resolve) => {
34+
new Promise((resolve, reject) => {
3535
const server = http.createServer();
36+
3637
dummyServers.push(server);
37-
server.listen(8080 + i, resolve);
38+
39+
server.listen(8080 + i, () => {
40+
resolve();
41+
});
42+
43+
server.on('error', (error) => {
44+
reject(error);
45+
});
3846
})
3947
),
4048
Promise.resolve()

0 commit comments

Comments
 (0)