hardlounge/test/plugins/packages/indexTest.ts

64 lines
2.0 KiB
TypeScript
Raw Permalink Normal View History

import log from "../../../server/log";
import {expect} from "chai";
import TestUtil from "../../util";
import sinon from "ts-sinon";
import packagePlugin from "../../../server/plugins/packages";
let packages: typeof packagePlugin;
describe("packages", function () {
let logInfoStub: sinon.SinonStub<string[], void>;
beforeEach(function () {
logInfoStub = sinon.stub(log, "info");
delete require.cache[require.resolve("../../../server/plugins/packages")];
// eslint-disable-next-line @typescript-eslint/no-var-requires
packages = require("../../../server/plugins/packages").default;
});
afterEach(function () {
logInfoStub.restore();
});
describe(".getStylesheets", function () {
it("should contain no stylesheets before packages are loaded", function () {
expect(packages.getStylesheets()).to.be.empty;
});
it("should return the list of registered stylesheets for loaded packages", function () {
packages.loadPackages();
2019-07-17 09:33:59 +00:00
expect(packages.getStylesheets()).to.deep.equal(["thelounge-package-foo/style.css"]);
});
});
describe(".getPackage", function () {
it("should contain no reference to packages before loading them", function () {
expect(packages.getPackage("thelounge-package-foo")).to.be.undefined;
});
it("should return details of a registered package after it was loaded", function () {
packages.loadPackages();
2019-07-17 09:33:59 +00:00
expect(packages.getPackage("thelounge-package-foo")).to.have.key("onServerStart");
});
});
describe(".loadPackages", function () {
it("should display report about loading packages", function () {
// Mock `log.info` to extract its effect into a string
logInfoStub.restore();
let stdout = "";
logInfoStub = sinon
.stub(log, "info")
.callsFake(TestUtil.sanitizeLog((str) => (stdout += str)));
packages.loadPackages();
2019-07-17 09:33:59 +00:00
expect(stdout).to.deep.equal(
2023-10-09 10:28:14 +00:00
"Package thelounge-package-foo vdummy loaded\nThere are packages using the experimental plugin API. Be aware that this API is not yet stable and may change in future Hard Lounge releases.\n"
2019-07-17 09:33:59 +00:00
);
});
});
});