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
compress
option (#3790)
- Loading branch information
Showing
4 changed files
with
230 additions
and
94 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,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`compress option as false should handle GET request to bundle file: console messages 1`] = `Array []`; | ||
|
||
exports[`compress option as false should handle GET request to bundle file: page errors 1`] = `Array []`; | ||
|
||
exports[`compress option as false should handle GET request to bundle file: response headers content-encoding 1`] = `undefined`; | ||
|
||
exports[`compress option as false should handle GET request to bundle file: response status 1`] = `200`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: console messages 1`] = `Array []`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: page errors 1`] = `Array []`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: response headers content-encoding 1`] = `"gzip"`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: response status 1`] = `200`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: console messages 1`] = `Array []`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: page errors 1`] = `Array []`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: response headers content-encoding 1`] = `"gzip"`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: 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,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`compress option as false should handle GET request to bundle file: console messages 1`] = `Array []`; | ||
|
||
exports[`compress option as false should handle GET request to bundle file: page errors 1`] = `Array []`; | ||
|
||
exports[`compress option as false should handle GET request to bundle file: response headers content-encoding 1`] = `undefined`; | ||
|
||
exports[`compress option as false should handle GET request to bundle file: response status 1`] = `200`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: console messages 1`] = `Array []`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: page errors 1`] = `Array []`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: response headers content-encoding 1`] = `"gzip"`; | ||
|
||
exports[`compress option as true should handle GET request to bundle file: response status 1`] = `200`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: console messages 1`] = `Array []`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: page errors 1`] = `Array []`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: response headers content-encoding 1`] = `"gzip"`; | ||
|
||
exports[`compress option enabled by default when not specified should handle GET request to bundle file: 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,180 @@ | ||
"use strict"; | ||
|
||
const webpack = require("webpack"); | ||
const Server = require("../../lib/Server"); | ||
const config = require("../fixtures/simple-config-other/webpack.config"); | ||
const runBrowser = require("../helpers/run-browser"); | ||
const port = require("../ports-map")["compress-option"]; | ||
|
||
describe("compress option", () => { | ||
describe("enabled by default when not specified", () => { | ||
let compiler; | ||
let server; | ||
let page; | ||
let browser; | ||
let pageErrors; | ||
let consoleMessages; | ||
|
||
beforeEach(async () => { | ||
compiler = webpack(config); | ||
|
||
server = new Server({ port }, compiler); | ||
|
||
await server.start(); | ||
|
||
({ page, browser } = await runBrowser()); | ||
|
||
pageErrors = []; | ||
consoleMessages = []; | ||
}); | ||
|
||
afterEach(async () => { | ||
await browser.close(); | ||
await server.stop(); | ||
}); | ||
|
||
it("should handle GET request to bundle file", 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-encoding"]).toMatchSnapshot( | ||
"response headers content-encoding" | ||
); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
|
||
expect(pageErrors).toMatchSnapshot("page errors"); | ||
}); | ||
}); | ||
|
||
describe("as true", () => { | ||
let compiler; | ||
let server; | ||
let page; | ||
let browser; | ||
let pageErrors; | ||
let consoleMessages; | ||
|
||
beforeEach(async () => { | ||
compiler = webpack(config); | ||
|
||
server = new Server( | ||
{ | ||
compress: true, | ||
port, | ||
}, | ||
compiler | ||
); | ||
|
||
await server.start(); | ||
|
||
({ page, browser } = await runBrowser()); | ||
|
||
pageErrors = []; | ||
consoleMessages = []; | ||
}); | ||
|
||
afterEach(async () => { | ||
await browser.close(); | ||
await server.stop(); | ||
}); | ||
|
||
it("should handle GET request to bundle file", 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-encoding"]).toMatchSnapshot( | ||
"response headers content-encoding" | ||
); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
|
||
expect(pageErrors).toMatchSnapshot("page errors"); | ||
}); | ||
}); | ||
|
||
describe("as false", () => { | ||
let compiler; | ||
let server; | ||
let page; | ||
let browser; | ||
let pageErrors; | ||
let consoleMessages; | ||
|
||
beforeEach(async () => { | ||
compiler = webpack(config); | ||
|
||
server = new Server( | ||
{ | ||
compress: false, | ||
port, | ||
}, | ||
compiler | ||
); | ||
|
||
await server.start(); | ||
|
||
({ page, browser } = await runBrowser()); | ||
|
||
pageErrors = []; | ||
consoleMessages = []; | ||
}); | ||
|
||
afterEach(async () => { | ||
await browser.close(); | ||
await server.stop(); | ||
}); | ||
|
||
it("should handle GET request to bundle file", 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-encoding"]).toMatchSnapshot( | ||
"response headers content-encoding" | ||
); | ||
|
||
expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( | ||
"console messages" | ||
); | ||
|
||
expect(pageErrors).toMatchSnapshot("page errors"); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.