File size: 1,507 Bytes
fcd8223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { afterEach, expect, it, vi } from "vitest";
import { createEmptyPluginRegistry } from "./registry-empty.js";
import {
  clearActivePluginRegistry,
  getActivePluginRegistry,
  resetPluginRuntimeStateForTest,
  setActivePluginRegistry,
} from "./runtime.js";

afterEach(async () => {
  vi.doUnmock("./loader-runtime-load.js");
  await clearActivePluginRegistry();
  resetPluginRuntimeStateForTest();
  vi.resetModules();
});

it("reads loaded registries without evaluating the plugin loader on hits or misses", async () => {
  await clearActivePluginRegistry();
  vi.resetModules();
  vi.doMock("./loader-runtime-load.js", () => {
    throw new Error("loaded-registry lookup must not evaluate loader-runtime-load");
  });

  const { getLoadedRuntimePluginRegistry } = await import("./active-runtime-registry.js");
  expect(getLoadedRuntimePluginRegistry()).toBeUndefined();

  const { resolvePluginLoadCacheContext } = await import("./loader-load-context.js");
  const loadOptions = { config: {}, installRecords: {} };
  const registry = createEmptyPluginRegistry();
  setActivePluginRegistry(registry, resolvePluginLoadCacheContext(loadOptions).cacheKey);

  expect(getLoadedRuntimePluginRegistry()).toBe(registry);
  expect(getLoadedRuntimePluginRegistry({ loadOptions })).toBe(registry);
  expect(
    getLoadedRuntimePluginRegistry({
      loadOptions: { ...loadOptions, workspaceDir: "/different-workspace" },
    }),
  ).toBeUndefined();
  expect(getActivePluginRegistry()).toBe(registry);
});