1
1
import type { Meta } from "https://deno.land/x/denops_core@v6.0.5/mod.ts" ;
2
+ import { assertEquals } from "https://deno.land/std@0.217.0/assert/mod.ts" ;
2
3
import {
3
4
assertSpyCall ,
4
5
stub ,
5
6
} from "https://deno.land/std@0.217.0/testing/mock.ts" ;
6
7
import { DenopsImpl , Host , Service } from "./denops.ts" ;
8
+ import { promiseState } from "https://deno.land/x/async@v2.1.0/mod.ts" ;
7
9
import { unimplemented } from "https://deno.land/x/errorutil@v0.1.1/mod.ts" ;
8
10
9
11
Deno . test ( "DenopsImpl" , async ( t ) => {
@@ -20,6 +22,7 @@ Deno.test("DenopsImpl", async (t) => {
20
22
} ;
21
23
const service : Service = {
22
24
dispatch : ( ) => unimplemented ( ) ,
25
+ waitLoaded : ( ) => unimplemented ( ) ,
23
26
} ;
24
27
const denops = new DenopsImpl ( "dummy" , meta , host , service ) ;
25
28
@@ -93,14 +96,41 @@ Deno.test("DenopsImpl", async (t) => {
93
96
} ) ;
94
97
95
98
await t . step ( "dispatch() calls service.dispatch()" , async ( ) => {
96
- const s = stub ( service , "dispatch" ) ;
99
+ const s1 = stub ( service , "waitLoaded" , ( ) => Promise . resolve ( ) ) ;
100
+ const s2 = stub ( service , "dispatch" , ( ) => Promise . resolve ( ) ) ;
97
101
try {
98
102
await denops . dispatch ( "dummy" , "fn" , "args" ) ;
99
- assertSpyCall ( s , 0 , {
103
+ assertSpyCall ( s1 , 0 , {
104
+ args : [ "dummy" ] ,
105
+ } ) ;
106
+ assertSpyCall ( s2 , 0 , {
100
107
args : [ "dummy" , "fn" , [ "args" ] ] ,
101
108
} ) ;
102
109
} finally {
103
- s . restore ( ) ;
110
+ s1 . restore ( ) ;
111
+ s2 . restore ( ) ;
104
112
}
105
113
} ) ;
114
+
115
+ await t . step (
116
+ "dispatch() internally waits 'service.waitLoaded()' before 'service.dispatch()'" ,
117
+ async ( ) => {
118
+ const { promise, resolve } = Promise . withResolvers < void > ( ) ;
119
+ const s1 = stub ( service , "waitLoaded" , ( ) => promise ) ;
120
+ const s2 = stub ( service , "dispatch" , ( ) => Promise . resolve ( ) ) ;
121
+ try {
122
+ const p = denops . dispatch ( "dummy" , "fn" , "args" ) ;
123
+ assertEquals ( await promiseState ( p ) , "pending" ) ;
124
+ assertEquals ( s1 . calls . length , 1 ) ;
125
+ assertEquals ( s2 . calls . length , 0 ) ;
126
+ resolve ( ) ;
127
+ assertEquals ( await promiseState ( p ) , "fulfilled" ) ;
128
+ assertEquals ( s1 . calls . length , 1 ) ;
129
+ assertEquals ( s2 . calls . length , 1 ) ;
130
+ } finally {
131
+ s1 . restore ( ) ;
132
+ s2 . restore ( ) ;
133
+ }
134
+ } ,
135
+ ) ;
106
136
} ) ;
0 commit comments