Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
54 changes: 54 additions & 0 deletions denops/@denops-private/plugin_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions tests/denops/testdata/with_import_map_jsonc/helper.ts
Original file line number Diff line number Diff line change
@@ -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}!`;
}
Original file line number Diff line number Diff line change
@@ -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'");
};
Loading