import assert from "node:assert"; import { describe, it } from "node:test"; import { Dispatcher } from "../dispatcher/index"; import { Observer } from "../observer/index"; import { Core } from "./index"; type TWindowWithApp = Window & typeof globalThis & { App: Record; }; describe("Core plugin", () => { it("initializes infrastructure plugins in app namespace", async () => { new Core({ plugins: {} }); await new Promise((resolve) => { setTimeout(resolve, 10); }); const app = (window as TWindowWithApp).App; assert.ok(app[Dispatcher.name + "Plugin"] instanceof Dispatcher); assert.ok(app[Observer.name + "Plugin"] instanceof Observer); }); it("creates singleton instance", () => { const core1 = new Core({ plugins: {} }); const core2 = new Core({ plugins: {} }); assert.strictEqual(core1, core2); }); it("initializes with empty plugins array", () => { assert.doesNotThrow(() => { new Core({ plugins: {} }); }); }); it("has correct stats structure", () => { const core = new Core({ plugins: {} }); assert.ok(typeof core.stats === "object"); assert.ok("plugins" in core.stats); assert.ok("styles" in core.stats); assert.ok("icons" in core.stats); }); it("sets default environment", () => { const core = new Core({ plugins: {} }); assert.ok(core.env); assert.ok(typeof core.env === "string"); }); it("sets default app namespace", () => { const core = new Core({ plugins: {} }); assert.equal(core.appNameSpace, "App"); }); it("clears cache when clearCache keys provided", () => { assert.doesNotThrow(() => { const core = new Core({ plugins: {}, clearCacheKeys: [ "test-key" ] }); core.clearCache(); }); }); it("has utils object with default utilities", () => { const core = new Core({ plugins: {} }); assert.ok(typeof core.utils === "object"); assert.ok(typeof core.utils.setVhVar === "function"); assert.ok(typeof core.utils.setScrollBarWidth === "function"); }); it("runs onInit after async plugins are resolved", async () => { Core.instance = null; let asyncPluginInOnInit: unknown; new Core({ plugins: { AsyncPlugin: async () => { await new Promise((resolve) => { setTimeout(resolve, 10); }); return { isReady: true }; }, }, onInit: ({ plugins }) => { asyncPluginInOnInit = plugins.get("AsyncPlugin"); }, }); await new Promise((resolve) => { setTimeout(resolve, 50); }); assert.deepEqual(asyncPluginInOnInit, { isReady: true }); }); });