@@ -29,6 +29,9 @@ const scriptInvalidConstraint = resolveTestDataURL(
2929const scriptInvalidConstraint2 = resolveTestDataURL (
3030 "dummy_invalid_constraint_plugin2.ts" ,
3131) ;
32+ const scriptWithImportMap = resolveTestDataURL (
33+ "with_import_map/plugin_with_import_map.ts" ,
34+ ) ;
3235
3336Deno . test ( "Plugin" , async ( t ) => {
3437 const meta : Meta = {
@@ -490,4 +493,79 @@ Deno.test("Plugin", async (t) => {
490493 } ) ;
491494 } ) ;
492495 } ) ;
496+
497+ await t . step ( "import map support" , async ( t ) => {
498+ await t . step ( "loads plugin with import_map.json" , async ( ) => {
499+ const denops = createDenops ( ) ;
500+ using _denops_call = stub ( denops , "call" ) ;
501+ using _denops_cmd = stub ( denops , "cmd" ) ;
502+
503+ const plugin = new Plugin ( denops , "test-plugin" , scriptWithImportMap ) ;
504+
505+ await plugin . waitLoaded ( ) ;
506+
507+ // Should emit events
508+ assertSpyCalls ( _denops_call , 2 ) ;
509+ assertSpyCall ( _denops_call , 0 , {
510+ args : [
511+ "denops#_internal#event#emit" ,
512+ "DenopsSystemPluginPre:test-plugin" ,
513+ ] ,
514+ } ) ;
515+ assertSpyCall ( _denops_call , 1 , {
516+ args : [
517+ "denops#_internal#event#emit" ,
518+ "DenopsSystemPluginPost:test-plugin" ,
519+ ] ,
520+ } ) ;
521+
522+ // Should call the plugin's main function
523+ assertSpyCalls ( _denops_cmd , 1 ) ;
524+ assertSpyCall ( _denops_cmd , 0 , {
525+ args : [ "echo 'Import map plugin initialized'" ] ,
526+ } ) ;
527+ } ) ;
528+
529+ await t . step ( "plugin can use mapped imports" , async ( ) => {
530+ const denops = createDenops ( ) ;
531+ using _denops_call = stub ( denops , "call" ) ;
532+ using _denops_cmd = stub ( denops , "cmd" ) ;
533+
534+ const plugin = new Plugin ( denops , "test-plugin" , scriptWithImportMap ) ;
535+ await plugin . waitLoaded ( ) ;
536+
537+ // Reset spy calls
538+ _denops_cmd . calls . length = 0 ;
539+
540+ // Call the dispatcher function
541+ const result = await plugin . call ( "test" ) ;
542+
543+ // Should execute the command with the message from the mapped import
544+ assertSpyCalls ( _denops_cmd , 1 ) ;
545+ assertSpyCall ( _denops_cmd , 0 , {
546+ args : [ "echo 'Import map works for test-plugin!'" ] ,
547+ } ) ;
548+
549+ // Should return the greeting from the mapped import
550+ assertEquals ( result , "Hello from mapped import!" ) ;
551+ } ) ;
552+
553+ await t . step ( "works without import map" , async ( ) => {
554+ const denops = createDenops ( ) ;
555+ using _denops_call = stub ( denops , "call" ) ;
556+ using _denops_cmd = stub ( denops , "cmd" ) ;
557+
558+ // Use a regular plugin without import map
559+ const plugin = new Plugin ( denops , "test-plugin" , scriptValid ) ;
560+
561+ await plugin . waitLoaded ( ) ;
562+
563+ // Should load normally
564+ assertSpyCalls ( _denops_call , 2 ) ;
565+ assertSpyCalls ( _denops_cmd , 1 ) ;
566+ assertSpyCall ( _denops_cmd , 0 , {
567+ args : [ "echo 'Hello, Denops!'" ] ,
568+ } ) ;
569+ } ) ;
570+ } ) ;
493571} ) ;
0 commit comments