Skip to content

Commit abe7610

Browse files
committed
test: more cases for webSocketURL
1 parent 2b53b00 commit abe7610

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

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

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,143 @@ for (const webSocketServerType of webSocketServerTypes) {
454454
});
455455
});
456456

457+
describe('should work when "port" option is "auto"', () => {
458+
beforeAll((done) => {
459+
const options = {
460+
webSocketServer: webSocketServerType,
461+
port: 'auto',
462+
host: '0.0.0.0',
463+
client: {
464+
webSocketURL: {
465+
port: port2,
466+
},
467+
},
468+
};
469+
testServer.startAwaitingCompilation(config, options, done);
470+
});
471+
472+
afterAll(testServer.close);
473+
474+
describe('browser client', () => {
475+
it('should work', (done) => {
476+
runBrowser().then(({ page, browser }) => {
477+
waitForTest(browser, page, /ws/, (websocketUrl) => {
478+
expect(websocketUrl).toContain(
479+
`${websocketUrlProtocol}://localhost:${port2}/ws`
480+
);
481+
482+
done();
483+
});
484+
485+
page.goto(`http://localhost:8080/main`);
486+
});
487+
});
488+
});
489+
});
490+
491+
describe('should work when "host" option is IPv4', () => {
492+
beforeAll((done) => {
493+
const options = {
494+
webSocketServer: webSocketServerType,
495+
port: port3,
496+
host: internalIp.v4.sync(),
497+
client: {
498+
webSocketURL: {
499+
port: port2,
500+
},
501+
},
502+
};
503+
testServer.startAwaitingCompilation(config, options, done);
504+
});
505+
506+
afterAll(testServer.close);
507+
508+
describe('browser client', () => {
509+
it('should work', (done) => {
510+
runBrowser().then(({ page, browser }) => {
511+
waitForTest(browser, page, /ws/, (websocketUrl) => {
512+
expect(websocketUrl).toContain(
513+
`${websocketUrlProtocol}://${internalIp.v4.sync()}:${port2}/ws`
514+
);
515+
516+
done();
517+
});
518+
519+
page.goto(`http://${internalIp.v4.sync()}:${port3}/main`);
520+
});
521+
});
522+
});
523+
});
524+
525+
describe('should work when "host" option is "local-ipv4" preset', () => {
526+
beforeAll((done) => {
527+
const options = {
528+
webSocketServer: webSocketServerType,
529+
port: port3,
530+
host: 'local-ipv4',
531+
client: {
532+
webSocketURL: {
533+
port: port2,
534+
},
535+
},
536+
};
537+
testServer.startAwaitingCompilation(config, options, done);
538+
});
539+
540+
afterAll(testServer.close);
541+
542+
describe('browser client', () => {
543+
it('should work', (done) => {
544+
runBrowser().then(({ page, browser }) => {
545+
waitForTest(browser, page, /ws/, (websocketUrl) => {
546+
expect(websocketUrl).toContain(
547+
`${websocketUrlProtocol}://${internalIp.v4.sync()}:${port2}/ws`
548+
);
549+
550+
done();
551+
});
552+
553+
page.goto(`http://${internalIp.v4.sync()}:${port3}/main`);
554+
});
555+
});
556+
});
557+
});
558+
559+
describe('should work with the "client.webSocketURL.port" option as "0"', () => {
560+
beforeAll((done) => {
561+
const options = {
562+
webSocketServer: webSocketServerType,
563+
port: port2,
564+
host: '0.0.0.0',
565+
client: {
566+
webSocketURL: {
567+
port: 0,
568+
},
569+
},
570+
};
571+
572+
testServer.startAwaitingCompilation(config, options, done);
573+
});
574+
575+
afterAll(testServer.close);
576+
577+
describe('browser client', () => {
578+
it('should work', (done) => {
579+
runBrowser().then(({ page, browser }) => {
580+
waitForTest(browser, page, /ws/, (websocketUrl) => {
581+
expect(websocketUrl).toContain(
582+
`${websocketUrlProtocol}://localhost:${port2}/ws`
583+
);
584+
585+
done();
586+
});
587+
588+
page.goto(`http://localhost:${port2}/main`);
589+
});
590+
});
591+
});
592+
});
593+
457594
describe('should work with "client.webSocketURL.port" and "client.webSocketURL.path" options', () => {
458595
beforeAll((done) => {
459596
const options = {

0 commit comments

Comments
 (0)