mirror of
https://github.com/thelounge/thelounge.git
synced 2026-08-02 08:06:11 -04:00
``` Webpack vs Vite Build Comparison ┌────────────┬──────────────────────┬────────────────────┬───────────────┐ │ Metric │ Webpack 5 │ Vite 8 (Rolldown) │ Change │ ├────────────┼──────────────────────┼────────────────────┼───────────────┤ │ Build time │ 1,961ms (2.96s wall) │ 612ms (0.82s wall) │ 3.2x faster │ ├────────────┼──────────────────────┼────────────────────┼───────────────┤ │ CPU time │ 11.0s user │ 1.3s user │ 8.5x less CPU │ └────────────┴──────────────────────┴────────────────────┴───────────────┘ Bundle sizes (gzipped) ┌────────────────┬─────────┬────────┬────────┐ │ Asset │ Webpack │ Vite │ Change │ ├────────────────┼─────────┼────────┼────────┤ │ App JS │ 152.6K │ 104.9K │ -31% │ ├────────────────┼─────────┼────────┼────────┤ │ Vendor JS │ 251.1K │ 81.6K │ -68% │ ├────────────────┼─────────┼────────┼────────┤ │ Runtime JS │ — │ 0.5K │ new │ ├────────────────┼─────────┼────────┼────────┤ │ Total JS │ 403.7K │ 187.0K │ -54% │ ├────────────────┼─────────┼────────┼────────┤ │ CSS │ 12.5K │ 11.9K │ -5% │ ├────────────────┼─────────┼────────┼────────┤ │ Total transfer │ 416.2K │ 198.9K │ -52% │ └────────────────┴─────────┴────────┴────────┘ Raw (uncompressed) ┌───────────────┬─────────┬──────┬────────┐ │ Asset │ Webpack │ Vite │ Change │ ├───────────────┼─────────┼──────┼────────┤ │ App JS │ 1.3M │ 304K │ -77% │ ├───────────────┼─────────┼──────┼────────┤ │ Vendor JS │ 1.1M │ 236K │ -79% │ ├───────────────┼─────────┼──────┼────────┤ │ CSS │ 64K │ 56K │ -13% │ ├───────────────┼─────────┼──────┼────────┤ │ Total public/ │ 5.1M │ 3.4M │ -33% │ └───────────────┴─────────┴──────┴────────┘ ``` --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
160 lines
4.6 KiB
TypeScript
160 lines
4.6 KiB
TypeScript
import log from "../server/log";
|
|
import Config from "../server/config";
|
|
import {expect, vi} from "vitest";
|
|
import got from "got";
|
|
import io from "socket.io-client";
|
|
import util from "./util";
|
|
import changelog from "../server/plugins/changelog";
|
|
|
|
import sinon from "ts-sinon";
|
|
import ClientManager from "../server/clientManager";
|
|
|
|
describe("Server", function () {
|
|
let server: import("http").Server;
|
|
let logInfoStub: sinon.SinonStub<string[], void>;
|
|
let logWarnStub: sinon.SinonStub<string[], void>;
|
|
let checkForUpdatesStub: sinon.SinonStub<[manager: ClientManager], void>;
|
|
|
|
beforeAll(async function () {
|
|
logInfoStub = sinon.stub(log, "info");
|
|
logWarnStub = sinon.stub(log, "warn").callsFake((...args: string[]) => {
|
|
// vapid.json permissions do not survive in git
|
|
if (args.length > 1 && args[1] === "is world readable.") {
|
|
return;
|
|
}
|
|
|
|
if (args.length > 0 && args[0].startsWith("run `chmod")) {
|
|
return;
|
|
}
|
|
|
|
// eslint-disable-next-line no-console
|
|
console.error(`Unhandled log.warn in server tests: ${args.join(" ")}`);
|
|
});
|
|
|
|
checkForUpdatesStub = sinon.stub(changelog, "checkForUpdates");
|
|
server = await (await import("../server/server")).default({} as any);
|
|
});
|
|
|
|
afterAll(async function () {
|
|
logInfoStub.restore();
|
|
logWarnStub.restore();
|
|
checkForUpdatesStub.restore();
|
|
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
|
|
await vi.dynamicImportSettled();
|
|
});
|
|
|
|
const webURL = `http://${Config.values.host}:${Config.values.port}/`;
|
|
|
|
describe("Express", () => {
|
|
it("should run a web server on " + webURL, async () => {
|
|
const response = await got(webURL);
|
|
expect(response.statusCode).to.equal(200);
|
|
expect(response.body).to.include("<title>The Lounge</title>");
|
|
expect(response.body).to.include('type="module"');
|
|
});
|
|
|
|
it("should serve static content correctly", async () => {
|
|
const response = await got(webURL + "thelounge.webmanifest");
|
|
const body = JSON.parse(response.body);
|
|
|
|
expect(response.statusCode).to.equal(200);
|
|
expect(body.name).to.equal("The Lounge");
|
|
expect(response.headers["content-type"]).to.equal("application/manifest+json");
|
|
});
|
|
});
|
|
|
|
describe("WebSockets", function () {
|
|
let client: ReturnType<typeof io>;
|
|
|
|
beforeEach(() => {
|
|
client = io(webURL, {
|
|
path: "/socket.io/",
|
|
autoConnect: false,
|
|
reconnection: false,
|
|
timeout: 1000,
|
|
transports: ["websocket"],
|
|
});
|
|
|
|
// Server emits events faster than the test can bind them
|
|
setTimeout(() => {
|
|
client.open();
|
|
}, 1);
|
|
});
|
|
|
|
afterEach(() => {
|
|
client.close();
|
|
});
|
|
|
|
it("should emit authorized message", () =>
|
|
new Promise<void>((resolve) => {
|
|
client.on("auth:success", () => resolve());
|
|
}));
|
|
|
|
it("should create network", () =>
|
|
new Promise<void>((resolve) => {
|
|
client.on("init", () => {
|
|
client.emit("network:new", {
|
|
username: "test-user",
|
|
realname: "The Lounge Test",
|
|
nick: "test-user",
|
|
join: "#thelounge, #spam",
|
|
name: "Test Network",
|
|
host: Config.values.host,
|
|
port: 6667,
|
|
});
|
|
});
|
|
|
|
client.on("network", (data) => {
|
|
expect(data.network).to.exist;
|
|
expect(data.network.nick).to.equal("test-user");
|
|
expect(data.network.name).to.equal("Test Network");
|
|
expect(data.network.channels).to.have.lengthOf(3);
|
|
expect(data.network.channels[0].name).to.equal("Test Network");
|
|
expect(data.network.channels[1].name).to.equal("#thelounge");
|
|
expect(data.network.channels[2].name).to.equal("#spam");
|
|
resolve();
|
|
});
|
|
}));
|
|
|
|
it("should emit configuration message", () =>
|
|
new Promise<void>((resolve) => {
|
|
client.on("configuration", (data) => {
|
|
// Private key defined in vapid.json is "01020304050607080910111213141516" for this public key.
|
|
expect(data.applicationServerKey).to.equal(
|
|
"BM0eTDpvDnH7ewlHuXWcPTE1NjlJ06XWIS1cQeBTZmsg4EDx5sOpY7kdX1pniTo8RakL3UdfFuIbC8_zog_BWIM"
|
|
);
|
|
|
|
expect(data.public).to.equal(true);
|
|
expect(data.defaultTheme).to.equal("default");
|
|
expect(data.themes).to.be.an("array");
|
|
expect(data.lockNetwork).to.equal(false);
|
|
expect(data.useHexIp).to.equal(false);
|
|
|
|
resolve();
|
|
});
|
|
}));
|
|
|
|
it("should emit push subscription state message", () =>
|
|
new Promise<void>((resolve) => {
|
|
client.on("push:issubscribed", (data) => {
|
|
expect(data).to.be.false;
|
|
|
|
resolve();
|
|
});
|
|
}));
|
|
|
|
it("should emit init message", () =>
|
|
new Promise<void>((resolve) => {
|
|
client.on("init", (data) => {
|
|
expect(data.active).to.equal(-1);
|
|
expect(data.networks).to.be.an("array");
|
|
expect(data.networks).to.be.empty;
|
|
expect(data.token).to.be.undefined;
|
|
|
|
resolve();
|
|
});
|
|
}));
|
|
});
|
|
});
|