Skip to content

Commit a343cd7

Browse files
authored
test: add e2e tests for mimeTypes option (#3797)
1 parent 44a6f65 commit a343cd7

File tree

4 files changed

+169
-85
lines changed

4 files changed

+169
-85
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: console messages 1`] = `Array []`;
4+
5+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: page errors 1`] = `Array []`;
6+
7+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: response headers content-type 1`] = `"text/html; charset=utf-8"`;
8+
9+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: response status 1`] = `200`;
10+
11+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: console messages 1`] = `Array []`;
12+
13+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: page errors 1`] = `Array []`;
14+
15+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: response headers content-type 1`] = `"text/plain; charset=utf-8"`;
16+
17+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: response status 1`] = `200`;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: console messages 1`] = `Array []`;
4+
5+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: page errors 1`] = `Array []`;
6+
7+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: response headers content-type 1`] = `"text/html; charset=utf-8"`;
8+
9+
exports[`mimeTypes option as an object with a custom type should request file with different js mime type: response status 1`] = `200`;
10+
11+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: console messages 1`] = `Array []`;
12+
13+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: page errors 1`] = `Array []`;
14+
15+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: response headers content-type 1`] = `"text/plain; charset=utf-8"`;
16+
17+
exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: response status 1`] = `200`;

test/e2e/mime-types.test.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
"use strict";
2+
3+
const webpack = require("webpack");
4+
const Server = require("../../lib/Server");
5+
const config = require("../fixtures/mime-types-config/webpack.config");
6+
const runBrowser = require("../helpers/run-browser");
7+
const port = require("../ports-map")["mime-types-option"];
8+
9+
describe("mimeTypes option", () => {
10+
describe("as an object with a remapped type", () => {
11+
let compiler;
12+
let server;
13+
let page;
14+
let browser;
15+
let pageErrors;
16+
let consoleMessages;
17+
18+
beforeEach(async () => {
19+
compiler = webpack(config);
20+
21+
server = new Server(
22+
{
23+
devMiddleware: {
24+
mimeTypes: {
25+
js: "text/plain",
26+
},
27+
},
28+
port,
29+
},
30+
compiler
31+
);
32+
33+
await server.start();
34+
35+
({ page, browser } = await runBrowser());
36+
37+
pageErrors = [];
38+
consoleMessages = [];
39+
});
40+
41+
afterEach(async () => {
42+
await browser.close();
43+
await server.stop();
44+
});
45+
46+
it("should request file with different js mime type", async () => {
47+
page
48+
.on("console", (message) => {
49+
consoleMessages.push(message);
50+
})
51+
.on("pageerror", (error) => {
52+
pageErrors.push(error);
53+
});
54+
55+
const response = await page.goto(`http://127.0.0.1:${port}/main.js`, {
56+
waitUntil: "networkidle0",
57+
});
58+
59+
expect(response.status()).toMatchSnapshot("response status");
60+
61+
expect(response.headers()["content-type"]).toMatchSnapshot(
62+
"response headers content-type"
63+
);
64+
65+
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
66+
"console messages"
67+
);
68+
69+
expect(pageErrors).toMatchSnapshot("page errors");
70+
});
71+
});
72+
73+
describe("as an object with a custom type", () => {
74+
let compiler;
75+
let server;
76+
let page;
77+
let browser;
78+
let pageErrors;
79+
let consoleMessages;
80+
81+
beforeEach(async () => {
82+
compiler = webpack(config);
83+
84+
server = new Server(
85+
{
86+
devMiddleware: {
87+
mimeTypes: {
88+
custom: "text/html",
89+
},
90+
},
91+
port,
92+
},
93+
compiler
94+
);
95+
96+
await server.start();
97+
98+
({ page, browser } = await runBrowser());
99+
100+
pageErrors = [];
101+
consoleMessages = [];
102+
});
103+
104+
afterEach(async () => {
105+
await browser.close();
106+
await server.stop();
107+
});
108+
109+
it("should request file with different js mime type", async () => {
110+
page
111+
.on("console", (message) => {
112+
consoleMessages.push(message);
113+
})
114+
.on("pageerror", (error) => {
115+
pageErrors.push(error);
116+
});
117+
118+
const response = await page.goto(`http://127.0.0.1:${port}/file.custom`, {
119+
waitUntil: "networkidle0",
120+
});
121+
122+
expect(response.status()).toMatchSnapshot("response status");
123+
124+
expect(response.headers()["content-type"]).toMatchSnapshot(
125+
"response headers content-type"
126+
);
127+
128+
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
129+
"console messages"
130+
);
131+
132+
expect(pageErrors).toMatchSnapshot("page errors");
133+
});
134+
});
135+
});

test/server/mimeTypes-option.test.js

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

0 commit comments

Comments
 (0)