Skip to content

fix: web socket url generation #3319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/utils/DevServerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class DevServerPlugin {
port = `&port=${options.client.port}`;
} else if (options.webSocketServer.options.port && !isSockJSType) {
port = `&port=${options.webSocketServer.options.port}`;
} else {
} else if (options.port) {
port = `&port=${options.port}`;
} else {
port = '';
}

/** @type {string} */
Expand Down
50 changes: 50 additions & 0 deletions test/e2e/TransportMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,54 @@ describe('transportMode client', () => {
});
});
});

describe('unspecified port', () => {
beforeAll((done) => {
const options = {
host: '0.0.0.0',
hot: false,
client: { transport: 'sockjs' },
webSocketServer: 'sockjs',
};
testServer.startAwaitingCompilation(config, options, done);
});

describe('on browser client', () => {
it('logs correctly', (done) => {
runBrowser().then(({ page, browser }) => {
const res = [];
page.goto(`http://localhost:8080/main`);
page.on('console', ({ _text }) => {
res.push(_text);
});

page.waitForTimeout(initConsoleDelay).then(() => {
testServer.close(() => {
// make sure the client gets the close message
page.waitForTimeout(awaitServerCloseDelay).then(() => {
browser.close().then(() => {
for (let i = res.length - 1; i >= 0; i--) {
if (res[i] === '[webpack-dev-server] Disconnected!') {
break;
} else if (
res[i] === 'close' ||
res[i].includes('net::ERR_CONNECTION_REFUSED') ||
// this indicates a WebSocket Error object that was logged
res[i].includes('JSHandle@object')
) {
// remove additional logging for the now failing connection,
// since this could be a variable number of error messages
res.splice(i, 1);
}
}
expect(res).toMatchSnapshot();
done();
});
});
});
});
});
});
});
});
});
8 changes: 8 additions & 0 deletions test/e2e/__snapshots__/TransportMode.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ Array [
]
`;

exports[`transportMode client unspecified port on browser client logs correctly 1`] = `
Array [
"Hey.",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] Disconnected!",
]
`;

exports[`transportMode client ws on browser client logs correctly 1`] = `
Array [
"Hey.",
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/__snapshots__/TransportMode.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ Array [
]
`;

exports[`transportMode client unspecified port on browser client logs correctly 1`] = `
Array [
"Hey.",
"[webpack-dev-server] Live Reloading enabled.",
"[webpack-dev-server] Disconnected!",
]
`;

exports[`transportMode client ws on browser client logs correctly 1`] = `
Array [
"Hey.",
Expand Down