|
| 1 | +import { assert, assertEquals } from "jsr:@std/assert@^1.0.1"; |
| 2 | +import { resolveTestDataPath } from "/denops-testdata/resolve.ts"; |
| 3 | +import { testHost } from "/denops-testutil/host.ts"; |
| 4 | +import { wait } from "/denops-testutil/wait.ts"; |
| 5 | + |
| 6 | +const scriptInterrupt = resolveTestDataPath("dummy_interrupt_plugin.ts"); |
| 7 | + |
| 8 | +testHost({ |
| 9 | + name: "denops#interrupt()", |
| 10 | + mode: "all", |
| 11 | + postlude: [ |
| 12 | + "let g:__test_denops_events = []", |
| 13 | + "autocmd User DenopsPlugin* call add(g:__test_denops_events, expand('<amatch>'))", |
| 14 | + "autocmd User DummyInterruptPlugin:* call add(g:__test_denops_events, expand('<amatch>'))", |
| 15 | + "runtime plugin/denops.vim", |
| 16 | + // NOTE: Disable startup on VimEnter. |
| 17 | + "autocmd! denops_plugin_internal_startup VimEnter", |
| 18 | + ], |
| 19 | + fn: async ({ host, t }) => { |
| 20 | + await t.step("if the server is not yet running", async (t) => { |
| 21 | + await t.step("returns immediately", async () => { |
| 22 | + await host.call("denops#interrupt"); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + // Start the server and wait. |
| 27 | + await host.call("denops#server#start"); |
| 28 | + await wait(() => host.call("eval", "denops#server#status() ==# 'running'")); |
| 29 | + |
| 30 | + await t.step("if the plugin is not yet loaded", async (t) => { |
| 31 | + await t.step("returns immediately", async () => { |
| 32 | + await host.call("denops#interrupt"); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + await t.step("if the plugin is loaded", async (t) => { |
| 37 | + // Load plugin and wait. |
| 38 | + await host.call("execute", [ |
| 39 | + "let g:__test_denops_events = []", |
| 40 | + `call denops#plugin#load('dummy', '${scriptInterrupt}')`, |
| 41 | + ], ""); |
| 42 | + await wait(async () => |
| 43 | + (await host.call("eval", "g:__test_denops_events") as string[]) |
| 44 | + .includes("DenopsPluginPost:dummy") |
| 45 | + ); |
| 46 | + await host.call("execute", [ |
| 47 | + "let g:__test_denops_events = []", |
| 48 | + ], ""); |
| 49 | + |
| 50 | + await t.step("returns immediately", async () => { |
| 51 | + await host.call("denops#interrupt"); |
| 52 | + }); |
| 53 | + |
| 54 | + await t.step("sends signal to the plugin", async () => { |
| 55 | + await wait(() => host.call("eval", "len(g:__test_denops_events)")); |
| 56 | + const events = await host.call( |
| 57 | + "eval", |
| 58 | + "g:__test_denops_events", |
| 59 | + ) as string[]; |
| 60 | + assert( |
| 61 | + events.some((event) => |
| 62 | + event.startsWith("DummyInterruptPlugin:Interrupted:") |
| 63 | + ), |
| 64 | + `Expected event 'DummyInterruptPlugin:Interrupted:*', but: ${ |
| 65 | + JSON.stringify(events) |
| 66 | + }`, |
| 67 | + ); |
| 68 | + }); |
| 69 | + |
| 70 | + await host.call("denops#request", "dummy", "reset", []); |
| 71 | + |
| 72 | + await t.step("sends signal to the plugin with reason", async () => { |
| 73 | + await host.call("execute", [ |
| 74 | + "let g:__test_denops_events = []", |
| 75 | + ], ""); |
| 76 | + |
| 77 | + await host.call("denops#interrupt", "test"); |
| 78 | + |
| 79 | + await wait(() => host.call("eval", "len(g:__test_denops_events)")); |
| 80 | + assertEquals(await host.call("eval", "g:__test_denops_events"), [ |
| 81 | + "DummyInterruptPlugin:Interrupted:test", |
| 82 | + ]); |
| 83 | + }); |
| 84 | + }); |
| 85 | + }, |
| 86 | +}); |
0 commit comments