Skip to content

Commit 0074ab4

Browse files
committed
test: more cases for webSocketURL
1 parent 7af0f8d commit 0074ab4

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

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

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,144 @@ 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 with the "port" option is 80', () => {
492+
beforeAll((done) => {
493+
const options = {
494+
webSocketServer: webSocketServerType,
495+
port: 80,
496+
host: '0.0.0.0',
497+
client: {
498+
webSocketURL: {
499+
port: port2,
500+
},
501+
},
502+
};
503+
504+
testServer.startAwaitingCompilation(config, options, done);
505+
});
506+
507+
afterAll(testServer.close);
508+
509+
describe('browser client', () => {
510+
it('should work', (done) => {
511+
runBrowser().then(({ page, browser }) => {
512+
waitForTest(browser, page, /ws/, (websocketUrl) => {
513+
expect(websocketUrl).toContain(
514+
`${websocketUrlProtocol}://localhost:${port2}/ws`
515+
);
516+
517+
done();
518+
});
519+
520+
page.goto(`http://localhost:80/main`);
521+
});
522+
});
523+
});
524+
});
525+
526+
describe('should work when "host" option is IPv4', () => {
527+
beforeAll((done) => {
528+
const options = {
529+
webSocketServer: webSocketServerType,
530+
port: port3,
531+
host: internalIp.v4.sync(),
532+
client: {
533+
webSocketURL: {
534+
port: port2,
535+
},
536+
},
537+
};
538+
testServer.startAwaitingCompilation(config, options, done);
539+
});
540+
541+
afterAll(testServer.close);
542+
543+
describe('browser client', () => {
544+
it('should work', (done) => {
545+
runBrowser().then(({ page, browser }) => {
546+
waitForTest(browser, page, /ws/, (websocketUrl) => {
547+
expect(websocketUrl).toContain(
548+
`${websocketUrlProtocol}://${internalIp.v4.sync()}:${port2}/ws`
549+
);
550+
551+
done();
552+
});
553+
554+
page.goto(`http://${internalIp.v4.sync()}:${port3}/main`);
555+
});
556+
});
557+
});
558+
});
559+
560+
describe('should work with the "client.webSocketURL.port" option is 0', () => {
561+
beforeAll((done) => {
562+
const options = {
563+
webSocketServer: webSocketServerType,
564+
port: port2,
565+
host: '0.0.0.0',
566+
client: {
567+
webSocketURL: {
568+
port: 0,
569+
},
570+
},
571+
};
572+
573+
testServer.startAwaitingCompilation(config, options, done);
574+
});
575+
576+
afterAll(testServer.close);
577+
578+
describe('browser client', () => {
579+
it('should work', (done) => {
580+
runBrowser().then(({ page, browser }) => {
581+
waitForTest(browser, page, /ws/, (websocketUrl) => {
582+
expect(websocketUrl).toContain(
583+
`${websocketUrlProtocol}://localhost:${port2}/ws`
584+
);
585+
586+
done();
587+
});
588+
589+
page.goto(`http://localhost:${port2}/main`);
590+
});
591+
});
592+
});
593+
});
594+
457595
describe('should work with "client.webSocketURL.port" and "client.webSocketURL.path" options', () => {
458596
beforeAll((done) => {
459597
const options = {

0 commit comments

Comments
 (0)