|
| 1 | +// ============================================================================= |
| 2 | +// File : colorscheme_lazy_test.ts |
| 3 | +// Author : yukimemi |
| 4 | +// Last Change : 2026/04/01 00:00:00. |
| 5 | +// ============================================================================= |
| 6 | + |
| 7 | +import { assertEquals } from "@std/assert"; |
| 8 | +import { test } from "@denops/test"; |
| 9 | +import { Dvpm } from "../dvpm.ts"; |
| 10 | + |
| 11 | +test({ |
| 12 | + mode: "all", |
| 13 | + name: "Lazy Loading: colorscheme trigger defines ColorSchemePre autocmd", |
| 14 | + fn: async (denops) => { |
| 15 | + const base = await Deno.makeTempDir(); |
| 16 | + // Use Dvpm.begin to register dispatcher |
| 17 | + const dvpm = await Dvpm.begin(denops, { base, health: false }); |
| 18 | + |
| 19 | + const colorName = "mycolor"; |
| 20 | + const pluginUrl = "color/plugin"; |
| 21 | + await dvpm.add({ |
| 22 | + url: pluginUrl, |
| 23 | + lazy: { |
| 24 | + enabled: true, |
| 25 | + colorscheme: colorName, |
| 26 | + }, |
| 27 | + }); |
| 28 | + |
| 29 | + const plugin = dvpm.plugins[0]; |
| 30 | + |
| 31 | + try { |
| 32 | + await dvpm.end(); |
| 33 | + |
| 34 | + // Check if ColorSchemePre autocmd for mycolor is defined |
| 35 | + const isDefined = await denops.call("exists", `#ColorSchemePre#${colorName}`); |
| 36 | + assertEquals(isDefined, 1, `ColorSchemePre autocmd for ${colorName} should be defined`); |
| 37 | + |
| 38 | + // Manually trigger ColorSchemePre to simulate colorscheme command |
| 39 | + await denops.cmd(`doautocmd ColorSchemePre ${colorName}`); |
| 40 | + |
| 41 | + // Verify the plugin was loaded into runtimepath |
| 42 | + const rtp = await denops.eval("&runtimepath") as string; |
| 43 | + assertEquals( |
| 44 | + rtp.includes(plugin.info.dst), |
| 45 | + true, |
| 46 | + "Plugin destination should be in runtimepath after trigger", |
| 47 | + ); |
| 48 | + } finally { |
| 49 | + // Clean up |
| 50 | + await denops.cmd(`autocmd! ColorSchemePre ${colorName}`); |
| 51 | + try { |
| 52 | + await Deno.remove(base, { recursive: true }); |
| 53 | + } catch { |
| 54 | + // Ignore |
| 55 | + } |
| 56 | + } |
| 57 | + }, |
| 58 | +}); |
0 commit comments