Skip to content

Commit

Permalink
test: add e2e tests for mimeTypes option (#3797)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Sep 6, 2021
1 parent 44a6f65 commit a343cd7
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 85 deletions.
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.

0 comments on commit a343cd7

Please sign in to comment.