|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const webpack = require("webpack"); |
| 4 | +const Server = require("../../lib/Server"); |
| 5 | +const config = require("../fixtures/simple-config-other/webpack.config"); |
| 6 | +const runBrowser = require("../helpers/run-browser"); |
| 7 | +const port = require("../ports-map")["compress-option"]; |
| 8 | + |
| 9 | +describe("compress option", () => { |
| 10 | + describe("enabled by default when not specified", () => { |
| 11 | + let compiler; |
| 12 | + let server; |
| 13 | + let page; |
| 14 | + let browser; |
| 15 | + let pageErrors; |
| 16 | + let consoleMessages; |
| 17 | + |
| 18 | + beforeEach(async () => { |
| 19 | + compiler = webpack(config); |
| 20 | + |
| 21 | + server = new Server({ port }, compiler); |
| 22 | + |
| 23 | + await server.start(); |
| 24 | + |
| 25 | + ({ page, browser } = await runBrowser()); |
| 26 | + |
| 27 | + pageErrors = []; |
| 28 | + consoleMessages = []; |
| 29 | + }); |
| 30 | + |
| 31 | + afterEach(async () => { |
| 32 | + await browser.close(); |
| 33 | + await server.stop(); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should handle GET request to bundle file", async () => { |
| 37 | + page |
| 38 | + .on("console", (message) => { |
| 39 | + consoleMessages.push(message); |
| 40 | + }) |
| 41 | + .on("pageerror", (error) => { |
| 42 | + pageErrors.push(error); |
| 43 | + }); |
| 44 | + |
| 45 | + const response = await page.goto(`http://127.0.0.1:${port}/main.js`, { |
| 46 | + waitUntil: "networkidle0", |
| 47 | + }); |
| 48 | + |
| 49 | + expect(response.status()).toMatchSnapshot("response status"); |
| 50 | + |
| 51 | + expect(response.headers()["content-encoding"]).toMatchSnapshot( |
| 52 | + "response headers content-encoding" |
| 53 | + ); |
| 54 | + |
| 55 | + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( |
| 56 | + "console messages" |
| 57 | + ); |
| 58 | + |
| 59 | + expect(pageErrors).toMatchSnapshot("page errors"); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + describe("as true", () => { |
| 64 | + let compiler; |
| 65 | + let server; |
| 66 | + let page; |
| 67 | + let browser; |
| 68 | + let pageErrors; |
| 69 | + let consoleMessages; |
| 70 | + |
| 71 | + beforeEach(async () => { |
| 72 | + compiler = webpack(config); |
| 73 | + |
| 74 | + server = new Server( |
| 75 | + { |
| 76 | + compress: true, |
| 77 | + port, |
| 78 | + }, |
| 79 | + compiler |
| 80 | + ); |
| 81 | + |
| 82 | + await server.start(); |
| 83 | + |
| 84 | + ({ page, browser } = await runBrowser()); |
| 85 | + |
| 86 | + pageErrors = []; |
| 87 | + consoleMessages = []; |
| 88 | + }); |
| 89 | + |
| 90 | + afterEach(async () => { |
| 91 | + await browser.close(); |
| 92 | + await server.stop(); |
| 93 | + }); |
| 94 | + |
| 95 | + it("should handle GET request to bundle file", async () => { |
| 96 | + page |
| 97 | + .on("console", (message) => { |
| 98 | + consoleMessages.push(message); |
| 99 | + }) |
| 100 | + .on("pageerror", (error) => { |
| 101 | + pageErrors.push(error); |
| 102 | + }); |
| 103 | + |
| 104 | + const response = await page.goto(`http://127.0.0.1:${port}/main.js`, { |
| 105 | + waitUntil: "networkidle0", |
| 106 | + }); |
| 107 | + |
| 108 | + expect(response.status()).toMatchSnapshot("response status"); |
| 109 | + |
| 110 | + expect(response.headers()["content-encoding"]).toMatchSnapshot( |
| 111 | + "response headers content-encoding" |
| 112 | + ); |
| 113 | + |
| 114 | + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( |
| 115 | + "console messages" |
| 116 | + ); |
| 117 | + |
| 118 | + expect(pageErrors).toMatchSnapshot("page errors"); |
| 119 | + }); |
| 120 | + }); |
| 121 | + |
| 122 | + describe("as false", () => { |
| 123 | + let compiler; |
| 124 | + let server; |
| 125 | + let page; |
| 126 | + let browser; |
| 127 | + let pageErrors; |
| 128 | + let consoleMessages; |
| 129 | + |
| 130 | + beforeEach(async () => { |
| 131 | + compiler = webpack(config); |
| 132 | + |
| 133 | + server = new Server( |
| 134 | + { |
| 135 | + compress: false, |
| 136 | + port, |
| 137 | + }, |
| 138 | + compiler |
| 139 | + ); |
| 140 | + |
| 141 | + await server.start(); |
| 142 | + |
| 143 | + ({ page, browser } = await runBrowser()); |
| 144 | + |
| 145 | + pageErrors = []; |
| 146 | + consoleMessages = []; |
| 147 | + }); |
| 148 | + |
| 149 | + afterEach(async () => { |
| 150 | + await browser.close(); |
| 151 | + await server.stop(); |
| 152 | + }); |
| 153 | + |
| 154 | + it("should handle GET request to bundle file", async () => { |
| 155 | + page |
| 156 | + .on("console", (message) => { |
| 157 | + consoleMessages.push(message); |
| 158 | + }) |
| 159 | + .on("pageerror", (error) => { |
| 160 | + pageErrors.push(error); |
| 161 | + }); |
| 162 | + |
| 163 | + const response = await page.goto(`http://127.0.0.1:${port}/main.js`, { |
| 164 | + waitUntil: "networkidle0", |
| 165 | + }); |
| 166 | + |
| 167 | + expect(response.status()).toMatchSnapshot("response status"); |
| 168 | + |
| 169 | + expect(response.headers()["content-encoding"]).toMatchSnapshot( |
| 170 | + "response headers content-encoding" |
| 171 | + ); |
| 172 | + |
| 173 | + expect(consoleMessages.map((message) => message.text())).toMatchSnapshot( |
| 174 | + "console messages" |
| 175 | + ); |
| 176 | + |
| 177 | + expect(pageErrors).toMatchSnapshot("page errors"); |
| 178 | + }); |
| 179 | + }); |
| 180 | +}); |
0 commit comments