mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 14:15:24 +00:00
feat: dev:all runner for web, electron and docker with plugin hot reload, termix-plugin dev
This commit is contained in:
1 parent
49fc241e06
commit
ec80a8ef8d
24 files changed
+1848
-44
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("../../utils/logger.js", () => ({
|
||||
pluginLogger: { info: vi.fn(), error: vi.fn() },
|
||||
}));
|
||||
|
||||
const { handleDevMessage } = await import("../../plugins/dev-reload.js");
|
||||
|
||||
describe("dev reload messages", () => {
|
||||
it("reloads the plugin and answers with its state", async () => {
|
||||
const send = vi.fn();
|
||||
const reload = vi.fn(async () => ({ version: "1.0.0", state: "active" }));
|
||||
await handleDevMessage(
|
||||
{ type: "plugin-reload", id: "snippets" },
|
||||
send,
|
||||
reload,
|
||||
);
|
||||
expect(reload).toHaveBeenCalledWith("snippets");
|
||||
expect(send).toHaveBeenCalledWith({
|
||||
type: "plugin-reloaded",
|
||||
id: "snippets",
|
||||
state: "active",
|
||||
});
|
||||
});
|
||||
|
||||
it("answers with the error when the reload fails", async () => {
|
||||
const send = vi.fn();
|
||||
await handleDevMessage(
|
||||
{ type: "plugin-reload", id: "snippets" },
|
||||
send,
|
||||
async () => {
|
||||
throw new Error("bad manifest");
|
||||
},
|
||||
);
|
||||
expect(send).toHaveBeenCalledWith({
|
||||
type: "plugin-reload-failed",
|
||||
id: "snippets",
|
||||
error: "bad manifest",
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores other messages", async () => {
|
||||
const send = vi.fn();
|
||||
const reload = vi.fn();
|
||||
await handleDevMessage({ type: "shutdown" }, send, reload);
|
||||
await handleDevMessage({ type: "plugin-reload" }, send, reload);
|
||||
await handleDevMessage(null, send, reload);
|
||||
expect(reload).not.toHaveBeenCalled();
|
||||
expect(send).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -445,6 +445,46 @@ describe("dependencies", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("reloading a bundled plugin for the dev runner", () => {
|
||||
it("loads the rebuilt copy and restarts what depends on it", async () => {
|
||||
createFixturePlugin({ id: "base", root: bundled });
|
||||
createFixturePlugin({
|
||||
id: "addon",
|
||||
root: bundled,
|
||||
manifestOverrides: { dependencies: { base: "^1.0.0" } },
|
||||
});
|
||||
const loader = await boot();
|
||||
createFixturePlugin({
|
||||
id: "base",
|
||||
root: bundled,
|
||||
manifestOverrides: { version: "1.1.0" },
|
||||
});
|
||||
|
||||
const result = await manage.reloadBundledPlugin("base");
|
||||
expect(result).toEqual({ id: "base", version: "1.1.0", state: "active" });
|
||||
expect(loader.get("base")?.manifest.version).toBe("1.1.0");
|
||||
expect(loader.get("addon")?.state).toBe("active");
|
||||
expect(db.rows.get("base")?.version).toBe("1.1.0");
|
||||
});
|
||||
|
||||
it("loads and starts a plugin added since boot", async () => {
|
||||
const loader = await boot();
|
||||
createFixturePlugin({ id: "fresh", root: bundled });
|
||||
const result = await manage.reloadBundledPlugin("fresh");
|
||||
expect(result.state).toBe("active");
|
||||
expect(loader.get("fresh")?.state).toBe("active");
|
||||
});
|
||||
|
||||
it("keeps a disabled plugin stopped", async () => {
|
||||
createFixturePlugin({ id: "base", root: bundled });
|
||||
const loader = await boot();
|
||||
await manage.setPluginState("base", false);
|
||||
const result = await manage.reloadBundledPlugin("base");
|
||||
expect(result.state).toBe("stopped");
|
||||
expect(loader.get("base")?.state).toBe("loaded");
|
||||
});
|
||||
});
|
||||
|
||||
describe("consent", () => {
|
||||
it("refuses an install without the consented list, before any download", async () => {
|
||||
registry.index.plugins = [registryEntry("notes", [{ version: "1.0.0" }])];
|
||||
|
||||
Reference in new issue
Block a user