Skip to content

Commit

Permalink
test: added
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 24, 2024
1 parent a57d1fd commit 91f5110
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const schema = require("./options.json");
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
* @property {boolean | string | Static | Array<string | Static>} [static]
* @property {boolean | ServerOptions} [https]
* @property {boolean} [http2]
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
* @property {() => Promise<T>} [app]
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
Expand Down
133 changes: 133 additions & 0 deletions test/e2e/__snapshots__/app.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`app option should work using "connect (async)" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect (async)" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "connect (async)" application and "http" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "http" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "http" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect (async)" application and "http" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "connect (async)" application and "https" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "https" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "https" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect (async)" application and "https" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "connect (async)" application and "spdy" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "spdy" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect (async)" application and "spdy" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect (async)" application and "spdy" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "connect" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "connect" application and "http" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect" application and "http" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect" application and "http" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect" application and "http" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "connect" application and "https" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect" application and "https" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect" application and "https" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect" application and "https" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "connect" application and "spdy" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "connect" application and "spdy" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "connect" application and "spdy" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "connect" application and "spdy" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "express" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "express" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "express" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "express" application and "/home/akait/IdeaProjects/webpack-dev-server/test/helpers/custom-http.js" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "express" application and "http" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "express" application and "http" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "express" application and "http" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "express" application and "http" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "express" application and "https" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "express" application and "https" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "express" application and "https" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "express" application and "https" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;

exports[`app option should work using "express" application and "spdy" server should handle GET request to index route (/): console messages 1`] = `[]`;

exports[`app option should work using "express" application and "spdy" server should handle GET request to index route (/): page errors 1`] = `[]`;

exports[`app option should work using "express" application and "spdy" server should handle GET request to index route (/): response status 1`] = `200`;

exports[`app option should work using "express" application and "spdy" server should handle GET request to index route (/): response text 1`] = `
"Heyo.
"
`;
108 changes: 108 additions & 0 deletions test/e2e/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"use strict";

const path = require("path");
const webpack = require("webpack");
const Server = require("../../lib/Server");
const config = require("../fixtures/static-config/webpack.config");
const runBrowser = require("../helpers/run-browser");
const port = require("../ports-map").app;

const staticDirectory = path.resolve(
__dirname,
"../fixtures/static-config/public",
);

const apps = [
["express", () => require("express")()],
["connect", () => require("connect")()],
["connect (async)", async () => require("express")()],
];

const servers = [
"http",
"https",
path.resolve(__dirname, "../helpers/custom-http.js"),
"spdy",
];

describe("app option", () => {
for (const [appName, app] of apps) {
for (const server of servers) {
let compiler;
let devServer;
let page;
let browser;
let pageErrors;
let consoleMessages;

describe(`should work using "${appName}" application and "${server}" server`, () => {
beforeEach(async () => {
compiler = webpack(config);

devServer = new Server(
{
static: {
directory: staticDirectory,
watch: false,
},
app,
server,
port,
},
compiler,
);

await devServer.start();

({ page, browser } = await runBrowser());

pageErrors = [];
consoleMessages = [];
});

afterEach(async () => {
await browser.close();
await devServer.stop();
});

it("should handle GET request to index route (/)", async () => {
page
.on("console", (message) => {
consoleMessages.push(message);
})
.on("pageerror", (error) => {
pageErrors.push(error);
});

const pageUrl =
server === "https" || server === "spdy" || server === "http2"
? `https://127.0.0.1:${port}/`
: `http://127.0.0.1:${port}/`;

const response = await page.goto(pageUrl, {
waitUntil: "networkidle0",
});

const HTTPVersion = await page.evaluate(
() => performance.getEntries()[0].nextHopProtocol,
);

const isSpdy = server === "spdy";

if (isSpdy) {
expect(HTTPVersion).toEqual("h2");
} else {
expect(HTTPVersion).toEqual("http/1.1");
}

expect(response.status()).toMatchSnapshot("response status");
expect(await response.text()).toMatchSnapshot("response text");
expect(
consoleMessages.map((message) => message.text()),
).toMatchSnapshot("console messages");
expect(pageErrors).toMatchSnapshot("page errors");
});
});
}
}
});
1 change: 1 addition & 0 deletions test/ports-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const listOfTests = {
"normalize-option": 1,
"setup-middlewares-option": 1,
"options-request-response": 2,
app: 1,
};

let startPort = 8089;
Expand Down

0 comments on commit 91f5110

Please sign in to comment.