Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add e2e tests for
mimeTypes
option (#3797)
- Loading branch information
Showing
4 changed files
with
169 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.