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