Skip to content

Commit 0df1f0c

Browse files
committed
fix(client): fix tests for createSocketUrl
1 parent a391b18 commit 0df1f0c

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

client-src/default/utils/createSocketUrl.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ function createSocketUrl(resourceQuery) {
1111

1212
if (typeof resourceQuery === 'string' && resourceQuery !== '') {
1313
// If this bundle is inlined, use the resource query to get the correct url.
14+
// strip leading `?` from query string
1415
urlParts = url.parse(resourceQuery.substr(1));
1516
} else {
1617
// Else, get the url from the <script> this file was called with.
17-
let scriptHost = getCurrentScriptSource();
18-
19-
if (scriptHost) {
20-
// eslint-disable-next-line no-useless-escape
21-
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
22-
}
18+
const scriptHost = getCurrentScriptSource();
2319
urlParts = url.parse(scriptHost || '/', false, true);
2420
}
2521

test/client/utils/__snapshots__/createSocketUrl.test.js.snap

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,34 @@ exports[`createSocketUrl should return the url when __resourceQuery is ?test 1`]
44

55
exports[`createSocketUrl should return the url when __resourceQuery is http://0.0.0.0 1`] = `"http://localhost/sockjs-node"`;
66

7-
exports[`createSocketUrl should return the url when __resourceQuery is http://user:pass@[::]:8080 1`] = `"ttp:user:pass@localhost:8080/sockjs-node"`;
7+
exports[`createSocketUrl should return the url when __resourceQuery is http://user:pass@[::]:8080 1`] = `"http://user:pass@localhost:8080/sockjs-node"`;
88

9-
exports[`createSocketUrl should return the url when __resourceQuery is http://user:password@localhost/ 1`] = `"ttp:user:password@localhost/sockjs-node"`;
9+
exports[`createSocketUrl should return the url when __resourceQuery is http://user:password@localhost/ 1`] = `"http://user:password@localhost/sockjs-node"`;
1010

11-
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com 1`] = `"ttps:example.com/sockjs-node"`;
11+
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com 1`] = `"https://example.com/sockjs-node"`;
1212

13-
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path 1`] = `"ttps:example.com/sockjs-node"`;
13+
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path 1`] = `"https://example.com/sockjs-node"`;
1414

15-
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path/foo.js 1`] = `"ttps:example.com/sockjs-node"`;
15+
exports[`createSocketUrl should return the url when __resourceQuery is https://example.com/path/foo.js 1`] = `"https://example.com/sockjs-node"`;
1616

17-
exports[`createSocketUrl should return the url when __resourceQuery is https://localhost:123 1`] = `"ttps:localhost:123/sockjs-node"`;
17+
exports[`createSocketUrl should return the url when __resourceQuery is https://localhost:123 1`] = `"https://localhost:123/sockjs-node"`;
1818

1919
exports[`createSocketUrl should return the url when __resourceQuery is undefined 1`] = `"/sockjs-node"`;
2020

2121
exports[`createSocketUrl should return the url when the current script source is ?test 1`] = `"/sockjs-node"`;
2222

23-
exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http:/sockjs-node"`;
23+
exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http://localhost/sockjs-node"`;
2424

25-
exports[`createSocketUrl should return the url when the current script source is http://user:pass@[::]:8080 1`] = `"http:/sockjs-node"`;
25+
exports[`createSocketUrl should return the url when the current script source is http://user:pass@[::]:8080 1`] = `"http://user:pass@localhost:8080/sockjs-node"`;
2626

2727
exports[`createSocketUrl should return the url when the current script source is http://user:password@localhost/ 1`] = `"http://user:password@localhost/sockjs-node"`;
2828

29-
exports[`createSocketUrl should return the url when the current script source is https://example.com 1`] = `"https:/sockjs-node"`;
29+
exports[`createSocketUrl should return the url when the current script source is https://example.com 1`] = `"https://example.com/sockjs-node"`;
3030

3131
exports[`createSocketUrl should return the url when the current script source is https://example.com/path 1`] = `"https://example.com/sockjs-node"`;
3232

3333
exports[`createSocketUrl should return the url when the current script source is https://example.com/path/foo.js 1`] = `"https://example.com/sockjs-node"`;
3434

35-
exports[`createSocketUrl should return the url when the current script source is https://localhost:123 1`] = `"https:/sockjs-node"`;
35+
exports[`createSocketUrl should return the url when the current script source is https://localhost:123 1`] = `"https://localhost:123/sockjs-node"`;
3636

3737
exports[`createSocketUrl should return the url when the current script source is undefined 1`] = `"/sockjs-node"`;

test/client/utils/createSocketUrl.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('createSocketUrl', () => {
2626
const createSocketUrl = require('../../../client-src/default/utils/createSocketUrl');
2727

2828
test(`should return the url when __resourceQuery is ${url}`, () => {
29-
expect(createSocketUrl(url)).toMatchSnapshot();
29+
const query = url ? url.querystring : url;
30+
expect(createSocketUrl(query)).toMatchSnapshot();
3031
});
3132

3233
test(`should return the url when the current script source is ${url}`, () => {

0 commit comments

Comments
 (0)