Skip to content

Commit 1acc76c

Browse files
authored
Merge pull request #455 from vim-denops/test-importmap-jsonc
🌿 Add test for import_map.jsonc support
2 parents b0ee649 + b7eccd6 commit 1acc76c

File tree

5 files changed

+74
-1
lines changed

5 files changed

+74
-1
lines changed

deno.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"exclude": [
1616
".coverage/",
1717
"tests/denops/testdata/no_check/",
18-
"tests/denops/testdata/with_import_map/"
18+
"tests/denops/testdata/with_import_map/",
19+
"tests/denops/testdata/with_import_map_jsonc/"
1920
],
2021
"imports": {
2122
"/denops-private/": "./denops/@denops-private/",

denops/@denops-private/plugin_test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const scriptWithImportMap = resolveTestDataURL(
2828
"with_import_map/plugin_with_import_map.ts",
2929
);
3030

31+
const scriptWithImportMapJsonc = resolveTestDataURL(
32+
"with_import_map_jsonc/plugin_with_import_map_jsonc.ts",
33+
);
34+
3135
Deno.test("Plugin", async (t) => {
3236
const meta: Meta = {
3337
mode: "debug",
@@ -545,6 +549,56 @@ Deno.test("Plugin", async (t) => {
545549
assertEquals(result, "Hello from mapped import!");
546550
});
547551

552+
await t.step("loads plugin with import_map.jsonc", async () => {
553+
const denops = createDenops();
554+
using _denops_call = stub(denops, "call");
555+
using _denops_cmd = stub(denops, "cmd");
556+
557+
const plugin = new Plugin(
558+
denops,
559+
"test-plugin",
560+
scriptWithImportMapJsonc,
561+
);
562+
563+
await plugin.waitLoaded();
564+
565+
// Should emit events
566+
assertSpyCalls(_denops_call, 2);
567+
assertSpyCall(_denops_call, 0, {
568+
args: [
569+
"denops#_internal#event#emit",
570+
"DenopsSystemPluginPre:test-plugin",
571+
],
572+
});
573+
assertSpyCall(_denops_call, 1, {
574+
args: [
575+
"denops#_internal#event#emit",
576+
"DenopsSystemPluginPost:test-plugin",
577+
],
578+
});
579+
580+
// Should call the plugin's main function
581+
assertSpyCalls(_denops_cmd, 1);
582+
assertSpyCall(_denops_cmd, 0, {
583+
args: ["echo 'Import map jsonc plugin initialized'"],
584+
});
585+
586+
// Reset spy calls
587+
_denops_cmd.calls.length = 0;
588+
589+
// Call the dispatcher function
590+
const result = await plugin.call("test");
591+
592+
// Should execute the command with the message from the mapped import
593+
assertSpyCalls(_denops_cmd, 1);
594+
assertSpyCall(_denops_cmd, 0, {
595+
args: ["echo 'Import map jsonc works for test-plugin!'"],
596+
});
597+
598+
// Should return the greeting from the mapped import
599+
assertEquals(result, "Hello from jsonc mapped import!");
600+
});
601+
548602
await t.step("works without import map", async () => {
549603
const denops = createDenops();
550604
using _denops_call = stub(denops, "call");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const greeting = "Hello from jsonc mapped import!";
2+
3+
export function getMessage(name: string): string {
4+
return `Import map jsonc works for ${name}!`;
5+
}

tests/denops/testdata/with_import_map/import_map.jsonc renamed to tests/denops/testdata/with_import_map_jsonc/import_map.jsonc

File renamed without changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Entrypoint } from "@denops/core";
2+
import { getMessage, greeting } from "@test/helper";
3+
4+
export const main: Entrypoint = async (denops) => {
5+
denops.dispatcher = {
6+
test: async () => {
7+
const message = getMessage("test-plugin");
8+
await denops.cmd(`echo '${message}'`);
9+
return greeting;
10+
},
11+
};
12+
await denops.cmd("echo 'Import map jsonc plugin initialized'");
13+
};

0 commit comments

Comments
 (0)