1
1
import {
2
+ assertArrayIncludes ,
2
3
assertEquals ,
3
4
assertObjectMatch ,
4
- assertStringIncludes ,
5
5
} from "jsr:@std/assert@^1.0.1" ;
6
+ import { delay } from "jsr:@std/async@^1.0.1/delay" ;
6
7
import { INVALID_PLUGIN_NAMES } from "/denops-testdata/invalid_plugin_names.ts" ;
7
8
import { resolveTestDataPath } from "/denops-testdata/resolve.ts" ;
8
9
import { testHost } from "/denops-testutil/host.ts" ;
9
10
import { wait } from "/denops-testutil/wait.ts" ;
10
11
11
- const scriptValid = resolveTestDataPath ( "dummy_valid_plugin.ts" ) ;
12
+ const ASYNC_DELAY = 100 ;
13
+
14
+ const scriptDispatcher = resolveTestDataPath ( "dummy_dispatcher_plugin.ts" ) ;
12
15
13
16
testHost ( {
14
17
name : "denops#request_async()" ,
15
18
mode : "all" ,
16
19
postlude : [
17
20
"runtime plugin/denops.vim" ,
18
21
] ,
19
- fn : async ( { host, t, stderr, mode } ) => {
20
- let outputs : string [ ] = [ ] ;
21
- stderr . pipeTo (
22
- new WritableStream ( { write : ( s ) => void outputs . push ( s ) } ) ,
23
- ) . catch ( ( ) => { } ) ;
22
+ fn : async ( { host, t } ) => {
24
23
await wait ( ( ) => host . call ( "eval" , "denops#server#status() ==# 'running'" ) ) ;
25
24
await host . call ( "execute" , [
26
25
"let g:__test_denops_events = []" ,
27
26
"autocmd User DenopsPlugin* call add(g:__test_denops_events, expand('<amatch>'))" ,
27
+ "autocmd User DummyDispatcherPlugin:* call add(g:__test_denops_events, expand('<amatch>'))" ,
28
28
"function TestDenopsRequestAsyncSuccess(...)" ,
29
- " call add(g:__test_denops_events, ['TestDenopsRequestAsyncSuccess', a:000])" ,
29
+ " call add(g:__test_denops_events, ['TestDenopsRequestAsyncSuccess:Called ', a:000])" ,
30
30
"endfunction" ,
31
31
"function TestDenopsRequestAsyncFailure(...)" ,
32
- " call add(g:__test_denops_events, ['TestDenopsRequestAsyncFailure', a:000])" ,
32
+ " call add(g:__test_denops_events, ['TestDenopsRequestAsyncFailure:Called ', a:000])" ,
33
33
"endfunction" ,
34
34
] , "" ) ;
35
35
@@ -53,10 +53,10 @@ testHost({
53
53
await t . step ( "calls failure callback" , async ( ) => {
54
54
await wait ( ( ) => host . call ( "eval" , "len(g:__test_denops_events)" ) ) ;
55
55
assertObjectMatch (
56
- await host . call ( "eval" , "g:__test_denops_events" ) as [ ] ,
56
+ await host . call ( "eval" , "g:__test_denops_events" ) as unknown [ ] ,
57
57
{
58
58
0 : [
59
- "TestDenopsRequestAsyncFailure" ,
59
+ "TestDenopsRequestAsyncFailure:Called " ,
60
60
[
61
61
{
62
62
message : `Invalid plugin name: ${ plugin_name } ` ,
@@ -74,43 +74,86 @@ testHost({
74
74
// Load plugin and wait.
75
75
await host . call ( "execute" , [
76
76
"let g:__test_denops_events = []" ,
77
- `call denops#plugin#load('dummyLoaded ', '${ scriptValid } ')` ,
77
+ `call denops#plugin#load('dummy ', '${ scriptDispatcher } ')` ,
78
78
] , "" ) ;
79
79
await wait ( async ( ) =>
80
80
( await host . call ( "eval" , "g:__test_denops_events" ) as string [ ] )
81
- . includes ( "DenopsPluginPost:dummyLoaded " )
81
+ . includes ( "DenopsPluginPost:dummy " )
82
82
) ;
83
- await host . call ( "execute" , [
84
- "let g:__test_denops_events = []" ,
85
- ] , "" ) ;
86
83
87
- outputs = [ ] ;
88
- await host . call (
89
- "denops#request_async" ,
90
- "dummyLoaded" ,
91
- "test" ,
92
- [ "foo" ] ,
93
- "TestDenopsRequestAsyncSuccess" ,
94
- "TestDenopsRequestAsyncFailure" ,
95
- ) ;
84
+ await t . step ( "returns immediately" , async ( ) => {
85
+ await host . call ( "execute" , [
86
+ "let g:__test_denops_events = []" ,
87
+ ] , "" ) ;
88
+
89
+ await host . call (
90
+ "denops#request_async" ,
91
+ "dummy" ,
92
+ "test" ,
93
+ [ "foo" ] ,
94
+ "TestDenopsRequestAsyncSuccess" ,
95
+ "TestDenopsRequestAsyncFailure" ,
96
+ ) ;
96
97
97
- await t . step ( "returns immediately" , ( ) => {
98
- assertEquals ( outputs , [ ] ) ;
98
+ assertEquals ( await host . call ( "eval" , "g:__test_denops_events" ) , [ ] ) ;
99
+ } ) ;
100
+
101
+ await t . step ( "calls dispatcher method" , async ( ) => {
102
+ await delay ( 100 + ASYNC_DELAY ) ;
103
+ assertArrayIncludes (
104
+ await host . call ( "eval" , "g:__test_denops_events" ) as unknown [ ] ,
105
+ [ 'DummyDispatcherPlugin:TestCalled:["foo"]' ] ,
106
+ ) ;
99
107
} ) ;
100
108
101
109
await t . step ( "calls success callback" , async ( ) => {
102
- await wait ( ( ) => host . call ( "eval" , "len(g:__test_denops_events)" ) ) ;
103
- const returnValue = mode === "vim" ? null : 0 ;
104
- assertObjectMatch (
105
- await host . call ( "eval" , "g:__test_denops_events" ) as [ ] ,
106
- {
107
- 0 : [ "TestDenopsRequestAsyncSuccess" , [ returnValue ] ] ,
108
- } ,
110
+ assertArrayIncludes (
111
+ await host . call ( "eval" , "g:__test_denops_events" ) as unknown [ ] ,
112
+ [
113
+ [
114
+ "TestDenopsRequestAsyncSuccess:Called" ,
115
+ [ { result : "OK" , args : [ "foo" ] } ] ,
116
+ ] ,
117
+ ] ,
109
118
) ;
110
119
} ) ;
111
120
112
- await t . step ( "calls dispatcher method" , ( ) => {
113
- assertStringIncludes ( outputs . join ( "" ) , 'This is test call: ["foo"]' ) ;
121
+ await t . step ( "if the dispatcher method is not exist" , async ( t ) => {
122
+ await t . step ( "returns immediately" , async ( ) => {
123
+ await host . call ( "execute" , [
124
+ "let g:__test_denops_events = []" ,
125
+ ] , "" ) ;
126
+
127
+ await host . call (
128
+ "denops#request_async" ,
129
+ "dummy" ,
130
+ "not_exist_method" ,
131
+ [ "foo" ] ,
132
+ "TestDenopsRequestAsyncSuccess" ,
133
+ "TestDenopsRequestAsyncFailure" ,
134
+ ) ;
135
+
136
+ assertEquals ( await host . call ( "eval" , "g:__test_denops_events" ) , [ ] ) ;
137
+ } ) ;
138
+
139
+ await t . step ( "calls failure callback" , async ( ) => {
140
+ await wait ( ( ) => host . call ( "eval" , "len(g:__test_denops_events)" ) ) ;
141
+ assertObjectMatch (
142
+ await host . call ( "eval" , "g:__test_denops_events" ) as unknown [ ] ,
143
+ {
144
+ 0 : [
145
+ "TestDenopsRequestAsyncFailure:Called" ,
146
+ [
147
+ {
148
+ message :
149
+ "Failed to call 'not_exist_method' API in 'dummy': this[#denops].dispatcher[fn] is not a function" ,
150
+ name : "Error" ,
151
+ } ,
152
+ ] ,
153
+ ] ,
154
+ } ,
155
+ ) ;
156
+ } ) ;
114
157
} ) ;
115
158
} ) ;
116
159
} ,
0 commit comments