Skip to content

Commit 69a3b3e

Browse files
test: fix
1 parent 5e943c4 commit 69a3b3e

File tree

2 files changed

+11
-51
lines changed

2 files changed

+11
-51
lines changed

test/client/__snapshots__/index.test.js.snap.webpack5

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ exports[`index should run onSocketMessage.error 1`] = `"error!!"`;
1616

1717
exports[`index should run onSocketMessage.ok 1`] = `"Ok"`;
1818

19-
exports[`index should run onSocketMessage.ok 2`] = `
20-
{
21-
"hot": false,
22-
"liveReload": false,
23-
"logging": "info",
24-
"overlay": false,
25-
"progress": false,
26-
"reconnect": 10,
27-
}
28-
`;
29-
3019
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] 1`] = `"Progress"`;
3120

3221
exports[`index should run onSocketMessage.progress and onSocketMessage['progress-update'] 2`] = `"12% - mock-msg."`;
@@ -66,7 +55,7 @@ exports[`index should run onSocketMessage['still-ok'] 2`] = `"StillOk"`;
6655

6756
exports[`index should set arguments into socket function 1`] = `
6857
[
69-
"mock-url",
58+
"ws://localhost/ws",
7059
{
7160
"close": [Function],
7261
"error": [Function],
@@ -85,8 +74,6 @@ exports[`index should set arguments into socket function 1`] = `
8574
"still-ok": [Function],
8675
"warnings": [Function],
8776
},
88-
10,
77+
undefined,
8978
]
9079
`;
91-
92-
exports[`index should update log level if options is passed 1`] = `"info"`;

test/client/index.test.js

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ describe("index", () => {
88
let log;
99
let socket;
1010
let overlay;
11-
let reloadApp;
1211
let sendMessage;
1312
let onSocketMessage;
1413
const locationValue = self.location;
1514
const resourceQueryValue = global.__resourceQuery;
1615

1716
beforeEach(() => {
18-
global.__resourceQuery = "foo";
17+
global.__resourceQuery = "?mock-url";
1918
global.__webpack_hash__ = "mock-hash";
2019

2120
// log
@@ -51,25 +50,10 @@ describe("index", () => {
5150
const { createOverlay } = require("../../client-src/overlay");
5251
overlay = createOverlay();
5352

54-
// reloadApp
55-
jest.setMock("../../client-src/utils/reloadApp.js", jest.fn());
56-
reloadApp = require("../../client-src/utils/reloadApp");
57-
5853
// sendMessage
5954
jest.setMock("../../client-src/utils/sendMessage.js", jest.fn());
6055
sendMessage = require("../../client-src/utils/sendMessage");
6156

62-
// getUrlOptions
63-
jest.setMock("../../client-src/utils/parseURL.js", () => {
64-
return {
65-
logging: "info",
66-
reconnect: 10,
67-
};
68-
});
69-
70-
// createSocketUrl
71-
jest.setMock("../../client-src/utils/createSocketURL.js", () => "mock-url");
72-
7357
// issue: https://github.com/jsdom/jsdom/issues/2112
7458
delete window.location;
7559

@@ -93,7 +77,7 @@ describe("index", () => {
9377
test("should run onSocketMessage['still-ok']", () => {
9478
onSocketMessage["still-ok"]();
9579

96-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
80+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
9781
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();
9882
expect(overlay.send).not.toBeCalledWith({ type: "DISMISS" });
9983

@@ -111,7 +95,6 @@ describe("index", () => {
11195
percent: "12",
11296
});
11397

114-
expect(log.log.info).not.toBeCalled();
11598
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();
11699

117100
onSocketMessage.progress(true);
@@ -120,7 +103,7 @@ describe("index", () => {
120103
percent: "12",
121104
});
122105

123-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
106+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
124107
});
125108

126109
test("should run onSocketMessage.progress and onSocketMessage['progress-update'] and log plugin name", () => {
@@ -131,7 +114,6 @@ describe("index", () => {
131114
pluginName: "mock-plugin",
132115
});
133116

134-
expect(log.log.info).not.toBeCalled();
135117
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();
136118

137119
onSocketMessage.progress(true);
@@ -141,7 +123,7 @@ describe("index", () => {
141123
pluginName: "mock-plugin",
142124
});
143125

144-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
126+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
145127
});
146128

147129
test("should run onSocketMessage.ok", () => {
@@ -154,23 +136,21 @@ describe("index", () => {
154136

155137
const res = onSocketMessage.ok();
156138

157-
expect(reloadApp).toBeCalled();
158-
expect(reloadApp.mock.calls[0][0]).toMatchSnapshot();
159139
// eslint-disable-next-line no-undefined
160140
expect(res).toEqual(undefined);
161141
});
162142

163143
test("should run onSocketMessage['static-changed']", () => {
164144
onSocketMessage["static-changed"]();
165145

166-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
146+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
167147
expect(self.location.reload).toBeCalled();
168148
});
169149

170150
test("should run onSocketMessage['static-changed'](file)", () => {
171151
onSocketMessage["static-changed"]("/static/assets/index.html");
172152

173-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
153+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
174154
expect(self.location.reload).toBeCalled();
175155
});
176156

@@ -201,7 +181,6 @@ describe("index", () => {
201181
)}`;
202182
overlay.send.mockReset();
203183
socket.mockReset();
204-
jest.unmock("../../client-src/utils/parseURL.js");
205184
require("../../client-src");
206185
onSocketMessage = socket.mock.calls[0][1];
207186

@@ -224,7 +203,6 @@ describe("index", () => {
224203
)}`;
225204
overlay.send.mockReset();
226205
socket.mockReset();
227-
jest.unmock("../../client-src/utils/parseURL.js");
228206
require("../../client-src");
229207
onSocketMessage = socket.mock.calls[0][1];
230208

@@ -243,7 +221,6 @@ describe("index", () => {
243221
jest.isolateModules(() => {
244222
// Use simple boolean
245223
global.__resourceQuery = "?overlay=true";
246-
jest.unmock("../../client-src/utils/parseURL.js");
247224
socket.mockReset();
248225
overlay.send.mockReset();
249226
require("../../client-src");
@@ -276,7 +253,7 @@ describe("index", () => {
276253
test("should run onSocketMessage.close", () => {
277254
onSocketMessage.close();
278255

279-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
256+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
280257
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();
281258
});
282259

@@ -285,7 +262,7 @@ describe("index", () => {
285262
onSocketMessage.hot();
286263
onSocketMessage.close();
287264

288-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
265+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
289266
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();
290267
});
291268

@@ -294,11 +271,7 @@ describe("index", () => {
294271
onSocketMessage.liveReload();
295272
onSocketMessage.close();
296273

297-
expect(log.log.info.mock.calls[0][0]).toMatchSnapshot();
274+
expect(log.log.info.mock.calls[1][0]).toMatchSnapshot();
298275
expect(sendMessage.mock.calls[0][0]).toMatchSnapshot();
299276
});
300-
301-
test("should update log level if options is passed", () => {
302-
expect(log.setLogLevel.mock.calls[0][0]).toMatchSnapshot();
303-
});
304277
});

0 commit comments

Comments
 (0)