Skip to content

Commit 5e943c4

Browse files
test: fix
1 parent f989b56 commit 5e943c4

File tree

5 files changed

+35
-127
lines changed

5 files changed

+35
-127
lines changed

client-src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,5 @@ const createSocketURL = (parsedURL) => {
721721
const socketURL = createSocketURL(parsedResourceQuery);
722722

723723
socket(socketURL, onSocketMessage, options.reconnect);
724+
725+
export { getCurrentScriptSource, parseURL, createSocketURL };

lib/Server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ class Server {
404404
let host;
405405

406406
const networks = Object.values(os.networkInterfaces())
407+
// eslint-disable-next-line no-shadow
407408
.flatMap((networks) => networks ?? [])
408409
.filter((network) => {
409410
if (!network || !network.address) {

test/client/utils/createSocketURL.test.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"use strict";
66

77
describe("'createSocketURL' function ", () => {
8+
global.__webpack_hash__ = "hash";
9+
810
const samples = [
9-
// __resourceQuery, location and socket URL
11+
// // __resourceQuery, location and socket URL
1012
[
1113
"?hostname=example.com&pathname=/ws",
1214
"http://example.com",
@@ -103,16 +105,20 @@ describe("'createSocketURL' function ", () => {
103105
];
104106

105107
samples.forEach(([__resourceQuery, location, expected]) => {
106-
jest.doMock(
107-
"../../../client-src/utils/getCurrentScriptSource",
108-
() => () => new URL("./entry.js", location).toString(),
109-
);
108+
test(`should return '${expected}' socket URL when '__resourceQuery' is '${__resourceQuery}' and 'self.location' is '${location}'`, () => {
109+
global.__resourceQuery = __resourceQuery;
110110

111-
const createSocketURL =
112-
require("../../../client-src/utils/createSocketURL").default;
113-
const parseURL = require("../../../client-src/utils/parseURL").default;
111+
if (__resourceQuery === null) {
112+
Object.defineProperty(document, "currentScript", {
113+
value: document.createElement("script"),
114+
configurable: true,
115+
});
116+
}
117+
118+
const client = require("../../../client-src/index");
119+
const createSocketURL = client.createSocketURL;
120+
const parseURL = client.parseURL;
114121

115-
test(`should return '${expected}' socket URL when '__resourceQuery' is '${__resourceQuery}' and 'self.location' is '${location}'`, () => {
116122
const selfLocation = new URL(location);
117123

118124
delete window.location;
@@ -121,6 +127,13 @@ describe("'createSocketURL' function ", () => {
121127

122128
const parsedURL = parseURL(__resourceQuery);
123129

130+
if (__resourceQuery === null) {
131+
Object.defineProperty(document, "currentScript", {
132+
value: null,
133+
configurable: true,
134+
});
135+
}
136+
124137
expect(createSocketURL(parsedURL)).toBe(expected);
125138
});
126139

test/client/utils/getCurrentScriptSource.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
"use strict";
66

7-
const getCurrentScriptSource =
8-
require("../../../client-src/utils/getCurrentScriptSource").default;
9-
107
describe("'getCurrentScriptSource' function", () => {
8+
let getCurrentScriptSource;
9+
10+
beforeEach(() => {
11+
global.__webpack_hash__ = "mock-hash";
12+
global.__resourceQuery = "?protocol=ws&hostname=0.0.0.0";
13+
14+
getCurrentScriptSource =
15+
require("../../../client-src/index").getCurrentScriptSource;
16+
});
17+
1118
afterEach(() => {
1219
Object.defineProperty(document, "currentScript", {
1320
// eslint-disable-next-line no-undefined

test/client/utils/reloadApp.test.js

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)