-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathplugin-manifest.test.ts
More file actions
53 lines (45 loc) · 2.12 KB
/
Copy pathplugin-manifest.test.ts
File metadata and controls
53 lines (45 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import assert from "node:assert/strict"
import { describe, it } from "node:test"
import { loadRightPanelPluginManifests, type RightPanelPluginManifest } from "./plugin-manifest"
const manifest = (id: string, events: string[]): RightPanelPluginManifest => ({
id,
tabs: [{ id: `${id}-tab`, labelKey: id, order: 10, render: () => undefined as any }],
lifecycle: {
onLoad: (context) => {
events.push(`${id}:load:${context.instanceId}`)
return () => events.push(`${id}:cleanup`)
},
onUnload: () => events.push(`${id}:unload`),
},
})
describe("right panel plugin manifests", () => {
it("loads modules and unloads lifecycle hooks in reverse order", () => {
const events: string[] = []
const runtime = loadRightPanelPluginManifests([manifest("first", events), manifest("second", events)], { instanceId: "abc" })
assert.deepEqual(runtime.modules.map((entry) => entry.id), ["first", "second"])
assert.deepEqual(events, ["first:load:abc", "second:load:abc"])
assert.deepEqual(runtime.unload(), [])
assert.deepEqual(events, ["first:load:abc", "second:load:abc", "second:cleanup", "second:unload", "first:cleanup", "first:unload"])
})
it("skips duplicate ids without blocking other plugins", () => {
const events: string[] = []
const runtime = loadRightPanelPluginManifests([manifest("plugin", events), manifest("plugin", events), manifest("other", events)], {
instanceId: "abc",
})
assert.deepEqual(runtime.modules.map((entry) => entry.id), ["plugin", "other"])
assert.equal(runtime.errors.length, 1)
assert.equal(runtime.errors[0]?.pluginId, "plugin")
})
it("skips plugins that fail during load", () => {
const runtime = loadRightPanelPluginManifests(
[
{ id: "bad", lifecycle: { onLoad: () => { throw new Error("boom") } } },
{ id: "good", tabs: [{ id: "good-tab", labelKey: "good", order: 10, render: () => undefined as any }] },
],
{ instanceId: "abc" },
)
assert.deepEqual(runtime.modules.map((entry) => entry.id), ["good"])
assert.equal(runtime.errors.length, 1)
assert.equal(runtime.errors[0]?.pluginId, "bad")
})
})