Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add e2e tests for mimeTypes option #3797

Merged
merged 1 commit into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/e2e/__snapshots__/mime-types.test.js.snap.webpack4
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`mimeTypes option as an object with a custom type should request file with different js mime type: console messages 1`] = `Array []`;

exports[`mimeTypes option as an object with a custom type should request file with different js mime type: page errors 1`] = `Array []`;

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"`;

exports[`mimeTypes option as an object with a custom type should request file with different js mime type: response status 1`] = `200`;

exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: console messages 1`] = `Array []`;

exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: page errors 1`] = `Array []`;

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"`;

exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: response status 1`] = `200`;
17 changes: 17 additions & 0 deletions test/e2e/__snapshots__/mime-types.test.js.snap.webpack5
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`mimeTypes option as an object with a custom type should request file with different js mime type: console messages 1`] = `Array []`;

exports[`mimeTypes option as an object with a custom type should request file with different js mime type: page errors 1`] = `Array []`;

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"`;

exports[`mimeTypes option as an object with a custom type should request file with different js mime type: response status 1`] = `200`;

exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: console messages 1`] = `Array []`;

exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: page errors 1`] = `Array []`;

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"`;

exports[`mimeTypes option as an object with a remapped type should request file with different js mime type: response status 1`] = `200`;
135 changes: 135 additions & 0 deletions test/e2e/mime-types.test.js
@@ -0,0 +1,135 @@
"use strict";

const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/mime-types-config/webpack.config");
const runBrowser = require("../helpers/run-browser");
const port = require("../ports-map")["mime-types-option"];

describe("mimeTypes option", () => {
describe("as an object with a remapped type", () => {
let compiler;
let server;
let page;
let browser;
let pageErrors;
let consoleMessages;

beforeEach(async () => {
compiler = webpack(config);

server = new Server(
{
devMiddleware: {
mimeTypes: {
js: "text/plain",
},
},
port,
},
compiler
);

await server.start();

({ page, browser } = await runBrowser());

pageErrors = [];
consoleMessages = [];
});

afterEach(async () => {
await browser.close();
await server.stop();
});

it("should request file with different js mime type", async () => {
page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

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

expect(response.status()).toMatchSnapshot("response status");

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
"console messages"
);

expect(pageErrors).toMatchSnapshot("page errors");
});
});

describe("as an object with a custom type", () => {
let compiler;
let server;
let page;
let browser;
let pageErrors;
let consoleMessages;

beforeEach(async () => {
compiler = webpack(config);

server = new Server(
{
devMiddleware: {
mimeTypes: {
custom: "text/html",
},
},
port,
},
compiler
);

await server.start();

({ page, browser } = await runBrowser());

pageErrors = [];
consoleMessages = [];
});

afterEach(async () => {
await browser.close();
await server.stop();
});

it("should request file with different js mime type", async () => {
page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

const response = await page.goto(`http://127.0.0.1:${port}/file.custom`, {
waitUntil: "networkidle0",
});

expect(response.status()).toMatchSnapshot("response status");

expect(response.headers()["content-type"]).toMatchSnapshot(
"response headers content-type"
);

expect(consoleMessages.map((message) => message.text())).toMatchSnapshot(
"console messages"
);

expect(pageErrors).toMatchSnapshot("page errors");
});
});
});
85 changes: 0 additions & 85 deletions test/server/mimeTypes-option.test.js

This file was deleted.