Skip to content

Commit f048ea4

Browse files
test: fix
1 parent 9918e64 commit f048ea4

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

client-src/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ const defaultOptions = {
2525
useErrorOverlay: false,
2626
useProgress: false,
2727
};
28-
const parsedResourceQuery = parseURL();
29-
30-
let options = defaultOptions;
28+
const parsedResourceQuery = parseURL(__resourceQuery);
29+
const options = defaultOptions;
3130

3231
// Handle Node.js legacy format and `new URL()`
3332
if (parsedResourceQuery.query) {
34-
options = Object.assign(options, parsedResourceQuery.query);
33+
Object.assign(options, parsedResourceQuery.query);
3534
} else if (parsedResourceQuery.searchParams) {
3635
const paramsToObject = (entries) => {
3736
const result = {};
@@ -43,7 +42,7 @@ if (parsedResourceQuery.query) {
4342
return result;
4443
};
4544

46-
options = Object.assign(
45+
Object.assign(
4746
options,
4847
paramsToObject(parsedResourceQuery.searchParams.entries())
4948
);

client-src/utils/createSocketURL.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ function createSocketURL(parsedURL) {
3232
hostname = self.location.hostname;
3333
}
3434

35-
if (!hostname && protocol === 'file:') {
36-
hostname = 'localhost';
37-
}
38-
3935
// `hostname` can be empty when the script path is relative. In that case, specifying a protocol would result in an invalid URL.
4036
// When https is used in the app, secure websockets are always necessary because the browser doesn't accept non-secure websockets.
4137
if (hostname && isInAddrAny && self.location.protocol === 'https:') {
@@ -70,10 +66,11 @@ function createSocketURL(parsedURL) {
7066
//
7167
// All of these sock url params are optionally passed in through resourceQuery,
7268
// so we need to fall back to the default if they are not provided
73-
const socketURLHostname = (getURLSearchParam('host') || hostname).replace(
74-
/^\[(.*)\]$/,
75-
'$1'
76-
);
69+
const socketURLHostname = (
70+
getURLSearchParam('host') ||
71+
hostname ||
72+
'localhost'
73+
).replace(/^\[(.*)\]$/, '$1');
7774

7875
if (!port || port === '0') {
7976
port = self.location.port;

test/client/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('index', () => {
5353
});
5454

5555
// createSocketUrl
56-
jest.setMock('../../client-src/utils/createSocketUrl.js', () => 'mock-url');
56+
jest.setMock('../../client-src/utils/createSocketURL.js', () => 'mock-url');
5757

5858
// issue: https://github.com/jsdom/jsdom/issues/2112
5959
delete window.location;

test/fixtures/custom-client/CustomSockJSClient.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ const BaseClient = require('../../../client/clients/BaseClient');
99
module.exports = class SockJSClient extends BaseClient {
1010
constructor(url) {
1111
super();
12-
this.sock = new SockJS(url);
12+
13+
this.sock = new SockJS(
14+
url.replace(/^ws:/i, 'http://').replace(/^wss:/i, 'https://')
15+
);
1316
}
1417

1518
static getClientPath(options) {

0 commit comments

Comments
 (0)