Skip to content

Commit ef8a227

Browse files
committed
feat: update built-in-routes.test.js
1 parent ab7cf84 commit ef8a227

9 files changed

+80
-74
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"application/javascript; charset=UTF-8"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
200
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"application/javascript; charset=UTF-8"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
200

test/e2e/built-in-routes.test.js

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"use strict";
22

33
const webpack = require("webpack");
4-
const { describe, test, beforeEach, afterEach } = require("@playwright/test");
4+
const { test } = require("../helpers/playwright-test");
55
const { expect } = require("../helpers/playwright-custom-expects");
66
const Server = require("../../lib/Server");
77
const config = require("../fixtures/client-config/webpack.config");
88
const multiConfig = require("../fixtures/multi-public-path-config/webpack.config");
99
const port = require("../ports-map").routes;
1010

11-
describe("Built in routes", () => {
12-
describe("with simple config", () => {
11+
test.describe("Built in routes", () => {
12+
test.describe("with simple config", () => {
1313
let compiler;
1414
let server;
1515
let pageErrors;
1616
let consoleMessages;
1717

18-
beforeEach(async () => {
18+
test.beforeEach(async () => {
1919
compiler = webpack(config);
2020
server = new Server({ port }, compiler);
2121

@@ -25,7 +25,7 @@ describe("Built in routes", () => {
2525
consoleMessages = [];
2626
});
2727

28-
afterEach(async () => {
28+
test.afterEach(async () => {
2929
await server.stop();
3030
});
3131

@@ -45,17 +45,17 @@ describe("Built in routes", () => {
4545
},
4646
);
4747

48-
expect(
49-
response.headers()["content-type"]
50-
).toMatchSnapshotWithArray();
48+
expect(response.headers()["content-type"]).toMatchSnapshotWithArray(
49+
"response headers",
50+
);
5151

52-
expect(response.status()).toMatchSnapshotWithArray();
52+
expect(response.status()).toMatchSnapshotWithArray("response status");
5353

5454
expect(
55-
consoleMessages.map((message) => message.text())
56-
).toMatchSnapshotWithArray();
55+
consoleMessages.map((message) => message.text()),
56+
).toMatchSnapshotWithArray("console messages");
5757

58-
expect(pageErrors).toMatchSnapshotWithArray();
58+
expect(pageErrors).toMatchSnapshotWithArray("page errors");
5959
});
6060

6161
test("should handles HEAD request to sockjs bundle", async ({ page }) => {
@@ -65,11 +65,11 @@ describe("Built in routes", () => {
6565
})
6666
.on("pageerror", (error) => {
6767
pageErrors.push(error);
68-
})
68+
});
6969

7070
await page.route("**/*", (route) => {
71-
route.continue({ method: "HEAD"})
72-
})
71+
route.continue({ method: "HEAD" });
72+
});
7373

7474
const response = await page.goto(
7575
`http://127.0.0.1:${port}/__webpack_dev_server__/sockjs.bundle.js`,
@@ -78,17 +78,17 @@ describe("Built in routes", () => {
7878
},
7979
);
8080

81-
expect(
82-
response.headers()["content-type"]
83-
).toMatchSnapshotWithArray();
81+
expect(response.headers()["content-type"]).toMatchSnapshotWithArray(
82+
"response headers",
83+
);
8484

85-
expect(response.status()).toMatchSnapshotWithArray();
85+
expect(response.status()).toMatchSnapshotWithArray("response status");
8686

8787
expect(
88-
consoleMessages.map((message) => message.text())
89-
).toMatchSnapshotWithArray();
88+
consoleMessages.map((message) => message.text()),
89+
).toMatchSnapshotWithArray("console messages");
9090

91-
expect(pageErrors).toMatchSnapshotWithArray();
91+
expect(pageErrors).toMatchSnapshotWithArray("page errors");
9292
});
9393

9494
test("should handle GET request to invalidate endpoint", async ({
@@ -109,17 +109,15 @@ describe("Built in routes", () => {
109109
},
110110
);
111111

112-
expect(response.headers()["content-type"]).not.toEqual(
113-
"text/html",
114-
);
112+
expect(response.headers()["content-type"]).not.toEqual("text/html");
115113

116-
expect(response.status()).toMatchSnapshotWithArray();
114+
expect(response.status()).toMatchSnapshotWithArray("response status");
117115

118116
expect(
119-
consoleMessages.map((message) => message.text())
120-
).toMatchSnapshotWithArray();
117+
consoleMessages.map((message) => message.text()),
118+
).toMatchSnapshotWithArray("console messages");
121119

122-
expect(pageErrors).toMatchSnapshotWithArray();
120+
expect(pageErrors).toMatchSnapshotWithArray("page errors");
123121
});
124122

125123
test("should handle GET request to directory index and list all middleware directories", async ({
@@ -140,19 +138,19 @@ describe("Built in routes", () => {
140138
},
141139
);
142140

143-
expect(
144-
response.headers()["content-type"]
145-
).toMatchSnapshotWithArray();
141+
expect(response.headers()["content-type"]).toMatchSnapshotWithArray(
142+
"response headers",
143+
);
146144

147-
expect(response.status()).toMatchSnapshotWithArray();
145+
expect(response.status()).toMatchSnapshotWithArray("response status");
148146

149-
expect(await response.text()).toMatchSnapshotWithArray();
147+
expect(await response.text()).toMatchSnapshotWithArray("response text");
150148

151149
expect(
152-
consoleMessages.map((message) => message.text())
153-
).toMatchSnapshotWithArray();
150+
consoleMessages.map((message) => message.text()),
151+
).toMatchSnapshotWithArray("console messages");
154152

155-
expect(pageErrors).toMatchSnapshotWithArray();
153+
expect(pageErrors).toMatchSnapshotWithArray("page errors");
156154
});
157155

158156
test("should handle HEAD request to directory index", async ({ page }) => {
@@ -162,11 +160,11 @@ describe("Built in routes", () => {
162160
})
163161
.on("pageerror", (error) => {
164162
pageErrors.push(error);
165-
})
163+
});
166164

167165
await page.route("**/*", (route) => {
168-
route.continue({ method: "HEAD" })
169-
})
166+
route.continue({ method: "HEAD" });
167+
});
170168

171169
const response = await page.goto(
172170
`http://127.0.0.1:${port}/webpack-dev-server/`,
@@ -175,19 +173,19 @@ describe("Built in routes", () => {
175173
},
176174
);
177175

178-
expect(
179-
response.headers()["content-type"]
180-
).toMatchSnapshotWithArray();
176+
expect(response.headers()["content-type"]).toMatchSnapshotWithArray(
177+
"response headers",
178+
);
181179

182-
expect(response.status()).toMatchSnapshotWithArray();
180+
expect(response.status()).toMatchSnapshotWithArray("response status");
183181

184-
expect(await response.text()).toMatchSnapshotWithArray();
182+
expect(await response.text()).toMatchSnapshotWithArray("response text");
185183

186184
expect(
187-
consoleMessages.map((message) => message.text())
188-
).toMatchSnapshotWithArray();
185+
consoleMessages.map((message) => message.text()),
186+
).toMatchSnapshotWithArray("console messages");
189187

190-
expect(pageErrors).toMatchSnapshotWithArray();
188+
expect(pageErrors).toMatchSnapshotWithArray("page errors");
191189
});
192190

193191
test("should handle GET request to magic async chunk", async ({ page }) => {
@@ -203,15 +201,15 @@ describe("Built in routes", () => {
203201
waitUntil: "networkidle0",
204202
});
205203

206-
expect(
207-
response.headers()["content-type"]
208-
).toMatchSnapshotWithArray();
204+
expect(response.headers()["content-type"]).toMatchSnapshotWithArray(
205+
"response headers",
206+
);
209207

210-
expect(response.status()).toMatchSnapshotWithArray();
208+
expect(response.status()).toMatchSnapshotWithArray("response status");
211209

212210
expect(
213-
consoleMessages.map((message) => message.text())
214-
).toMatchSnapshotWithArray();
211+
consoleMessages.map((message) => message.text()),
212+
).toMatchSnapshotWithArray("console messages");
215213
});
216214

217215
// FIXME: improve it
@@ -224,35 +222,35 @@ describe("Built in routes", () => {
224222
})
225223
.on("pageerror", (error) => {
226224
pageErrors.push(error);
227-
})
225+
});
228226

229227
await page.route("**/*", (route) => {
230-
route.continue({ method: "HEAD" })
231-
})
228+
route.continue({ method: "HEAD" });
229+
});
232230

233231
const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
234232
waitUntil: "networkidle0",
235233
});
236234

237-
expect(
238-
response.headers()["content-type"]
239-
).toMatchSnapshotWithArray();
235+
expect(response.headers()["content-type"]).toMatchSnapshotWithArray(
236+
"response headers",
237+
);
240238

241-
expect(response.status()).toMatchSnapshotWithArray();
239+
expect(response.status()).toMatchSnapshotWithArray("response status");
242240

243241
expect(
244-
consoleMessages.map((message) => message.text())
245-
).toMatchSnapshotWithArray();
242+
consoleMessages.map((message) => message.text()),
243+
).toMatchSnapshotWithArray("console messages");
246244
});
247245
});
248246

249-
describe("with multi config", () => {
247+
test.describe("with multi config", () => {
250248
let compiler;
251249
let server;
252250
let pageErrors;
253251
let consoleMessages;
254252

255-
beforeEach(async () => {
253+
test.beforeEach(async () => {
256254
compiler = webpack(multiConfig);
257255
server = new Server({ port }, compiler);
258256

@@ -262,7 +260,7 @@ describe("Built in routes", () => {
262260
consoleMessages = [];
263261
});
264262

265-
afterEach(async () => {
263+
test.afterEach(async () => {
266264
await server.stop();
267265
});
268266

@@ -284,19 +282,19 @@ describe("Built in routes", () => {
284282
},
285283
);
286284

287-
expect(
288-
response.headers()["content-type"]
289-
).toMatchSnapshotWithArray();
285+
expect(response.headers()["content-type"]).toMatchSnapshotWithArray(
286+
"response headers",
287+
);
290288

291-
expect(response.status()).toMatchSnapshotWithArray();
289+
expect(response.status()).toMatchSnapshotWithArray("response status");
292290

293-
expect(await response.text()).toMatchSnapshotWithArray();
291+
expect(await response.text()).toMatchSnapshotWithArray("response text");
294292

295293
expect(
296-
consoleMessages.map((message) => message.text())
297-
).toMatchSnapshotWithArray();
294+
consoleMessages.map((message) => message.text()),
295+
).toMatchSnapshotWithArray("console messages");
298296

299-
expect(pageErrors).toMatchSnapshotWithArray();
297+
expect(pageErrors).toMatchSnapshotWithArray("page errors");
300298
});
301299
});
302300
});

0 commit comments

Comments
 (0)