diff --git a/deno.jsonc b/deno.jsonc index 7ff94edd..666e93c8 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -15,7 +15,8 @@ "exclude": [ ".coverage/", "tests/denops/testdata/no_check/", - "tests/denops/testdata/with_import_map/" + "tests/denops/testdata/with_import_map/", + "tests/denops/testdata/with_import_map_jsonc/" ], "imports": { "/denops-private/": "./denops/@denops-private/", diff --git a/denops/@denops-private/plugin_test.ts b/denops/@denops-private/plugin_test.ts index 3f9dbcb4..c0a4b891 100644 --- a/denops/@denops-private/plugin_test.ts +++ b/denops/@denops-private/plugin_test.ts @@ -28,6 +28,10 @@ const scriptWithImportMap = resolveTestDataURL( "with_import_map/plugin_with_import_map.ts", ); +const scriptWithImportMapJsonc = resolveTestDataURL( + "with_import_map_jsonc/plugin_with_import_map_jsonc.ts", +); + Deno.test("Plugin", async (t) => { const meta: Meta = { mode: "debug", @@ -545,6 +549,56 @@ Deno.test("Plugin", async (t) => { assertEquals(result, "Hello from mapped import!"); }); + await t.step("loads plugin with import_map.jsonc", async () => { + const denops = createDenops(); + using _denops_call = stub(denops, "call"); + using _denops_cmd = stub(denops, "cmd"); + + const plugin = new Plugin( + denops, + "test-plugin", + scriptWithImportMapJsonc, + ); + + await plugin.waitLoaded(); + + // Should emit events + assertSpyCalls(_denops_call, 2); + assertSpyCall(_denops_call, 0, { + args: [ + "denops#_internal#event#emit", + "DenopsSystemPluginPre:test-plugin", + ], + }); + assertSpyCall(_denops_call, 1, { + args: [ + "denops#_internal#event#emit", + "DenopsSystemPluginPost:test-plugin", + ], + }); + + // Should call the plugin's main function + assertSpyCalls(_denops_cmd, 1); + assertSpyCall(_denops_cmd, 0, { + args: ["echo 'Import map jsonc plugin initialized'"], + }); + + // Reset spy calls + _denops_cmd.calls.length = 0; + + // Call the dispatcher function + const result = await plugin.call("test"); + + // Should execute the command with the message from the mapped import + assertSpyCalls(_denops_cmd, 1); + assertSpyCall(_denops_cmd, 0, { + args: ["echo 'Import map jsonc works for test-plugin!'"], + }); + + // Should return the greeting from the mapped import + assertEquals(result, "Hello from jsonc mapped import!"); + }); + await t.step("works without import map", async () => { const denops = createDenops(); using _denops_call = stub(denops, "call"); diff --git a/tests/denops/testdata/with_import_map_jsonc/helper.ts b/tests/denops/testdata/with_import_map_jsonc/helper.ts new file mode 100644 index 00000000..77fef10f --- /dev/null +++ b/tests/denops/testdata/with_import_map_jsonc/helper.ts @@ -0,0 +1,5 @@ +export const greeting = "Hello from jsonc mapped import!"; + +export function getMessage(name: string): string { + return `Import map jsonc works for ${name}!`; +} diff --git a/tests/denops/testdata/with_import_map/import_map.jsonc b/tests/denops/testdata/with_import_map_jsonc/import_map.jsonc similarity index 100% rename from tests/denops/testdata/with_import_map/import_map.jsonc rename to tests/denops/testdata/with_import_map_jsonc/import_map.jsonc diff --git a/tests/denops/testdata/with_import_map_jsonc/plugin_with_import_map_jsonc.ts b/tests/denops/testdata/with_import_map_jsonc/plugin_with_import_map_jsonc.ts new file mode 100644 index 00000000..e8228e48 --- /dev/null +++ b/tests/denops/testdata/with_import_map_jsonc/plugin_with_import_map_jsonc.ts @@ -0,0 +1,13 @@ +import type { Entrypoint } from "@denops/core"; +import { getMessage, greeting } from "@test/helper"; + +export const main: Entrypoint = async (denops) => { + denops.dispatcher = { + test: async () => { + const message = getMessage("test-plugin"); + await denops.cmd(`echo '${message}'`); + return greeting; + }, + }; + await denops.cmd("echo 'Import map jsonc plugin initialized'"); +};