-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added
magicHtml
option (#3717)
- Loading branch information
Showing
16 changed files
with
422 additions
and
7 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
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
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
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
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
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
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
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
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,18 @@ | ||
"use strict"; | ||
|
||
const { testBin } = require("../helpers/test-bin"); | ||
const port = require("../ports-map")["cli-magic-html"]; | ||
|
||
describe('"liveReload" CLI option', () => { | ||
it('should work using "--magic-html"', async () => { | ||
const { exitCode } = await testBin(["--port", port, "--magic-html"]); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
|
||
it('should work using "--no-magic-html"', async () => { | ||
const { exitCode } = await testBin(["--port", port, "--no-magic-html"]); | ||
|
||
expect(exitCode).toEqual(0); | ||
}); | ||
}); |
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,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`magicHtml option disabled should not handle GET request to magic async html: console messages 1`] = ` | ||
Array [ | ||
"Failed to load resource: the server responded with a status of 404 (Not Found)", | ||
] | ||
`; | ||
|
||
exports[`magicHtml option disabled should not handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option disabled should not handle GET request to magic async html: response status 1`] = `404`; | ||
|
||
exports[`magicHtml option disabled should not handle HEAD request to magic async html: console messages 1`] = ` | ||
Array [ | ||
"Failed to load resource: the server responded with a status of 404 (Not Found)", | ||
] | ||
`; | ||
|
||
exports[`magicHtml option disabled should not handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option disabled should not handle HEAD request to magic async html: response status 1`] = `404`; | ||
|
||
exports[`magicHtml option enabled should handle GET request to magic async html: console messages 1`] = ` | ||
Array [ | ||
"[HMR] Waiting for update signal from WDS...", | ||
"Hey.", | ||
"[webpack-dev-server] Hot Module Replacement enabled.", | ||
"[webpack-dev-server] Live Reloading enabled.", | ||
] | ||
`; | ||
|
||
exports[`magicHtml option enabled should handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option enabled should handle GET request to magic async html: response status 1`] = `200`; | ||
|
||
exports[`magicHtml option enabled should handle HEAD request to magic async html: console messages 1`] = `Array []`; | ||
|
||
exports[`magicHtml option enabled should handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option enabled should handle HEAD request to magic async html: 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,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`magicHtml option disabled should not handle GET request to magic async html: console messages 1`] = ` | ||
Array [ | ||
"Failed to load resource: the server responded with a status of 404 (Not Found)", | ||
] | ||
`; | ||
|
||
exports[`magicHtml option disabled should not handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option disabled should not handle GET request to magic async html: response status 1`] = `404`; | ||
|
||
exports[`magicHtml option disabled should not handle HEAD request to magic async html: console messages 1`] = ` | ||
Array [ | ||
"Failed to load resource: the server responded with a status of 404 (Not Found)", | ||
] | ||
`; | ||
|
||
exports[`magicHtml option disabled should not handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option disabled should not handle HEAD request to magic async html: response status 1`] = `404`; | ||
|
||
exports[`magicHtml option enabled should handle GET request to magic async html: console messages 1`] = ` | ||
Array [ | ||
"[HMR] Waiting for update signal from WDS...", | ||
"Hey.", | ||
"[webpack-dev-server] Hot Module Replacement enabled.", | ||
"[webpack-dev-server] Live Reloading enabled.", | ||
] | ||
`; | ||
|
||
exports[`magicHtml option enabled should handle GET request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option enabled should handle GET request to magic async html: response status 1`] = `200`; | ||
|
||
exports[`magicHtml option enabled should handle HEAD request to magic async html: console messages 1`] = `Array []`; | ||
|
||
exports[`magicHtml option enabled should handle HEAD request to magic async html: response headers content-type 1`] = `"text/html; charset=utf-8"`; | ||
|
||
exports[`magicHtml option enabled should handle HEAD request to magic async html: 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,167 @@ | ||
"use strict"; | ||
|
||
const webpack = require("webpack"); | ||
const Server = require("../../lib/Server"); | ||
const config = require("../fixtures/client-config/webpack.config"); | ||
const runBrowser = require("../helpers/run-browser"); | ||
const port = require("../ports-map")["magic-html-option"]; | ||
|
||
describe("magicHtml option", () => { | ||
describe("enabled", () => { | ||
let compiler; | ||
let server; | ||
let page; | ||
let browser; | ||
let pageErrors; | ||
let consoleMessages; | ||
|
||
beforeEach(async () => { | ||
compiler = webpack(config); | ||
server = new Server({ port, magicHtml: true }, compiler); | ||
|
||
await server.start(); | ||
|
||
({ page, browser } = await runBrowser()); | ||
|
||
pageErrors = []; | ||
consoleMessages = []; | ||
}); | ||
|
||
afterEach(async () => { | ||
await browser.close(); | ||
await server.stop(); | ||
}); | ||
|
||
it("should handle GET request to magic async html", 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`, { | ||
waitUntil: "networkidle0", | ||
}); | ||
|
||
expect(response.headers()["content-type"]).toMatchSnapshot( | ||
"response headers content-type" | ||
); | ||
|
||
expect(response.status()).toMatchSnapshot("response status"); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
}); | ||
|
||
it("should handle HEAD request to magic async html", async () => { | ||
await page.setRequestInterception(true); | ||
|
||
page | ||
.on("console", (message) => { | ||
consoleMessages.push(message); | ||
}) | ||
.on("pageerror", (error) => { | ||
pageErrors.push(error); | ||
}) | ||
.on("request", (interceptedRequest) => { | ||
interceptedRequest.continue({ method: "HEAD" }); | ||
}); | ||
|
||
const response = await page.goto(`http://127.0.0.1:${port}/main`, { | ||
waitUntil: "networkidle0", | ||
}); | ||
|
||
expect(response.headers()["content-type"]).toMatchSnapshot( | ||
"response headers content-type" | ||
); | ||
|
||
expect(response.status()).toMatchSnapshot("response status"); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
}); | ||
}); | ||
|
||
describe("disabled", () => { | ||
let compiler; | ||
let server; | ||
let page; | ||
let browser; | ||
let pageErrors; | ||
let consoleMessages; | ||
|
||
beforeEach(async () => { | ||
compiler = webpack(config); | ||
server = new Server({ port, magicHtml: false }, compiler); | ||
|
||
await server.start(); | ||
|
||
({ page, browser } = await runBrowser()); | ||
|
||
pageErrors = []; | ||
consoleMessages = []; | ||
}); | ||
|
||
afterEach(async () => { | ||
await browser.close(); | ||
await server.stop(); | ||
}); | ||
|
||
it("should not handle GET request to magic async html", 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`, { | ||
waitUntil: "networkidle0", | ||
}); | ||
|
||
expect(response.headers()["content-type"]).toMatchSnapshot( | ||
"response headers content-type" | ||
); | ||
|
||
expect(response.status()).toMatchSnapshot("response status"); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
}); | ||
|
||
it("should not handle HEAD request to magic async html", async () => { | ||
await page.setRequestInterception(true); | ||
|
||
page | ||
.on("console", (message) => { | ||
consoleMessages.push(message); | ||
}) | ||
.on("pageerror", (error) => { | ||
pageErrors.push(error); | ||
}) | ||
.on("request", (interceptedRequest) => { | ||
interceptedRequest.continue({ method: "HEAD" }); | ||
}); | ||
|
||
const response = await page.goto(`http://127.0.0.1:${port}/main`, { | ||
waitUntil: "networkidle0", | ||
}); | ||
|
||
expect(response.headers()["content-type"]).toMatchSnapshot( | ||
"response headers content-type" | ||
); | ||
|
||
expect(response.status()).toMatchSnapshot("response status"); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.