1
- import type { MetadataBearer } from " @smithy/types" ;
1
+ import type { MetadataBearer } from ' @smithy/types' ;
2
2
import type {
3
3
ExpectationResult ,
4
4
MatcherState ,
5
- } from " @vitest/expect" ;
6
- import type { AwsCommand , AwsStub } from " aws-sdk-client-mock" ;
5
+ } from ' @vitest/expect' ;
6
+ import type { AwsCommand , AwsStub } from ' aws-sdk-client-mock' ;
7
7
8
- import { ObjectContaining } from " @vitest/expect" ;
8
+ import { ObjectContaining } from ' @vitest/expect' ;
9
9
10
- import { notNull , ordinalOf } from " ./utils.js" ;
10
+ import { notNull , ordinalOf } from ' ./utils.js' ;
11
11
12
12
type AwsCommandConstructur <
13
13
Input extends object ,
14
- Output extends MetadataBearer
14
+ Output extends MetadataBearer ,
15
15
> = new ( input : Input ) => AwsCommand < Input , Output > ;
16
16
17
17
/*
@@ -41,38 +41,38 @@ interface BaseMatcher<R> {
41
41
42
42
toHaveReceivedCommandOnce <
43
43
Input extends object ,
44
- Ouptut extends MetadataBearer
44
+ Ouptut extends MetadataBearer ,
45
45
> (
46
46
command : AwsCommandConstructur < Input , Ouptut >
47
47
) : R ;
48
48
49
49
toHaveReceivedCommandTimes <
50
50
Input extends object ,
51
- Ouptut extends MetadataBearer
51
+ Ouptut extends MetadataBearer ,
52
52
> (
53
53
command : AwsCommandConstructur < Input , Ouptut > ,
54
54
times : number
55
55
) : R ;
56
56
57
57
toHaveReceivedCommandWith <
58
58
Input extends object ,
59
- Ouptut extends MetadataBearer
59
+ Ouptut extends MetadataBearer ,
60
60
> (
61
61
command : AwsCommandConstructur < Input , Ouptut > ,
62
62
input : Partial < Input >
63
63
) : R ;
64
64
65
65
toHaveReceivedLastCommandWith <
66
66
Input extends object ,
67
- Ouptut extends MetadataBearer
67
+ Ouptut extends MetadataBearer ,
68
68
> (
69
69
command : AwsCommandConstructur < Input , Ouptut > ,
70
70
input : Partial < Input >
71
71
) : R ;
72
72
73
73
toHaveReceivedNthCommandWith <
74
74
Input extends object ,
75
- Ouptut extends MetadataBearer
75
+ Ouptut extends MetadataBearer ,
76
76
> (
77
77
command : AwsCommandConstructur < Input , Ouptut > ,
78
78
times : number ,
@@ -84,12 +84,12 @@ interface BaseMatcher<R> {
84
84
* We define some aliases
85
85
*/
86
86
interface AliasMatcher < R > {
87
- toReceiveCommand : BaseMatcher < R > [ " toHaveReceivedCommand" ] ;
88
- toReceiveCommandOnce : BaseMatcher < R > [ " toHaveReceivedCommandOnce" ] ;
89
- toReceiveCommandTimes : BaseMatcher < R > [ " toHaveReceivedCommandTimes" ] ;
90
- toReceiveCommandWith : BaseMatcher < R > [ " toHaveReceivedCommandWith" ] ;
91
- toReceiveLastCommandWith : BaseMatcher < R > [ " toHaveReceivedLastCommandWith" ] ;
92
- toReceiveNthCommandWith : BaseMatcher < R > [ " toHaveReceivedNthCommandWith" ] ;
87
+ toReceiveCommand : BaseMatcher < R > [ ' toHaveReceivedCommand' ] ;
88
+ toReceiveCommandOnce : BaseMatcher < R > [ ' toHaveReceivedCommandOnce' ] ;
89
+ toReceiveCommandTimes : BaseMatcher < R > [ ' toHaveReceivedCommandTimes' ] ;
90
+ toReceiveCommandWith : BaseMatcher < R > [ ' toHaveReceivedCommandWith' ] ;
91
+ toReceiveLastCommandWith : BaseMatcher < R > [ ' toHaveReceivedLastCommandWith' ] ;
92
+ toReceiveNthCommandWith : BaseMatcher < R > [ ' toHaveReceivedNthCommandWith' ] ;
93
93
}
94
94
95
95
type CustomMatcher < R = unknown > = AliasMatcher < R > & BaseMatcher < R > ;
@@ -99,41 +99,41 @@ function formatCalls(
99
99
client : AwsStub < any , any , any > ,
100
100
command : AwsCommandConstructur < any , any > ,
101
101
expectedCall : Record < string , any > | undefined ,
102
- message : string
102
+ message : string ,
103
103
) : string {
104
104
const calls = client . commandCalls ( command ) ;
105
105
106
106
return calls . length === 0
107
107
? message
108
108
: [
109
- message ,
110
- "" ,
111
- " Received:" ,
112
- "" ,
113
- ...calls . flatMap ( ( call , index ) => {
109
+ message ,
110
+ '' ,
111
+ ' Received:' ,
112
+ '' ,
113
+ ...calls . flatMap ( ( call , index ) => {
114
114
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
115
- const input = call . args [ 0 ] . input ;
116
- return [
117
- ` ${ ordinalOf ( index + 1 ) } ${ command . name } call` ,
118
- "" ,
119
- expectedCall
120
- ? context . utils . diff ( expectedCall , input , { omitAnnotationLines : true } )
121
- : context . utils
122
- . stringify ( input )
123
- . split ( "\n" )
124
- . map ( line => ` ${ line } ` )
125
- . join ( "\n" ) ,
126
- ""
127
- ] . filter ( notNull ) ;
128
- } ) ,
129
- `Number of calls: ${ calls . length . toString ( ) } `
130
- ] . join ( "\n" ) ;
115
+ const input = call . args [ 0 ] . input ;
116
+ return [
117
+ ` ${ ordinalOf ( index + 1 ) } ${ command . name } call` ,
118
+ '' ,
119
+ expectedCall
120
+ ? context . utils . diff ( expectedCall , input , { omitAnnotationLines : true } )
121
+ : context . utils
122
+ . stringify ( input )
123
+ . split ( '\n' )
124
+ . map ( line => ` ${ line } ` )
125
+ . join ( '\n' ) ,
126
+ '' ,
127
+ ] . filter ( notNull ) ;
128
+ } ) ,
129
+ `Number of calls: ${ calls . length . toString ( ) } ` ,
130
+ ] . join ( '\n' ) ;
131
131
}
132
132
133
- const toHaveReceivedCommandTimes : CustomMatcherFn = function (
133
+ const toHaveReceivedCommandTimes : CustomMatcherFn = function (
134
134
client : AwsStub < any , any , any > ,
135
135
command : AwsCommandConstructur < any , any > ,
136
- times : number
136
+ times : number ,
137
137
) {
138
138
const { isNot } = this ;
139
139
const callCount = client . commandCalls ( command ) . length ;
@@ -146,14 +146,14 @@ const toHaveReceivedCommandTimes: CustomMatcherFn = function(
146
146
: `expected "${ command . name } " to be called ${ times . toString ( ) } times, but got ${ callCount . toString ( ) } times` ;
147
147
return formatCalls ( this , client , command , undefined , message ) ;
148
148
} ,
149
- pass
149
+ pass,
150
150
} ;
151
151
} ;
152
152
const toReceiveCommandTimes = toHaveReceivedCommandTimes ;
153
153
154
- const toHaveReceivedCommandOnce : CustomMatcherFn = function (
154
+ const toHaveReceivedCommandOnce : CustomMatcherFn = function (
155
155
client : AwsStub < any , any , any > ,
156
- command : AwsCommandConstructur < any , any >
156
+ command : AwsCommandConstructur < any , any > ,
157
157
) {
158
158
const { isNot } = this ;
159
159
const callCount = client . commandCalls ( command ) . length ;
@@ -165,14 +165,14 @@ const toHaveReceivedCommandOnce: CustomMatcherFn = function(
165
165
: `expected "${ command . name } " to be called once, but got ${ callCount . toString ( ) } times` ;
166
166
return formatCalls ( this , client , command , undefined , message ) ;
167
167
} ,
168
- pass
168
+ pass,
169
169
} ;
170
170
} ;
171
171
const toReceiveCommandOnce = toHaveReceivedCommandOnce ;
172
172
173
- const toHaveReceivedCommand : CustomMatcherFn = function (
173
+ const toHaveReceivedCommand : CustomMatcherFn = function (
174
174
client : AwsStub < any , any , any > ,
175
- command : AwsCommandConstructur < any , any >
175
+ command : AwsCommandConstructur < any , any > ,
176
176
) {
177
177
const { isNot } = this ;
178
178
const callCount = client . commandCalls ( command ) . length ;
@@ -184,21 +184,21 @@ const toHaveReceivedCommand: CustomMatcherFn = function(
184
184
: `expected "${ command . name } " to be called at least once` ;
185
185
return formatCalls ( this , client , command , undefined , message ) ;
186
186
} ,
187
- pass
187
+ pass,
188
188
} ;
189
189
} ;
190
190
const toReceiveCommand = toHaveReceivedCommand ;
191
191
192
- const toHaveReceivedCommandWith : CustomMatcherFn = function (
192
+ const toHaveReceivedCommandWith : CustomMatcherFn = function (
193
193
client : AwsStub < any , any , any > ,
194
194
command : AwsCommandConstructur < any , any > ,
195
- input : Record < string , any >
195
+ input : Record < string , any > ,
196
196
) {
197
197
const { isNot, utils } = this ;
198
198
const calls = client . commandCalls ( command ) ;
199
199
200
200
const pass = calls . some ( call =>
201
- new ObjectContaining ( input ) . asymmetricMatch ( call . args [ 0 ] . input )
201
+ new ObjectContaining ( input ) . asymmetricMatch ( call . args [ 0 ] . input ) ,
202
202
) ;
203
203
204
204
return {
@@ -208,18 +208,18 @@ const toHaveReceivedCommandWith: CustomMatcherFn = function(
208
208
: `expected "${ command . name } " to be called with arguments: ${ utils . printExpected ( input ) } ` ;
209
209
return formatCalls ( this , client , command , input , message ) ;
210
210
} ,
211
- pass
211
+ pass,
212
212
} ;
213
213
} ;
214
214
const toReceiveCommandWith = toHaveReceivedCommandWith ;
215
215
/*
216
216
217
217
*/
218
- const toHaveReceivedNthCommandWith : CustomMatcherFn = function (
218
+ const toHaveReceivedNthCommandWith : CustomMatcherFn = function (
219
219
client : AwsStub < any , any , any > ,
220
220
command : AwsCommandConstructur < any , any > ,
221
221
times : number ,
222
- input : Record < string , any >
222
+ input : Record < string , any > ,
223
223
) {
224
224
const { isNot, utils } = this ;
225
225
const calls = client . commandCalls ( command ) ;
@@ -236,15 +236,15 @@ const toHaveReceivedNthCommandWith: CustomMatcherFn = function(
236
236
: `expected ${ ordinalOf ( times ) } "${ command . name } " to be called with arguments: ${ utils . printExpected ( input ) } ` ;
237
237
return formatCalls ( this , client , command , input , message ) ;
238
238
} ,
239
- pass
239
+ pass,
240
240
} ;
241
241
} ;
242
242
const toReceiveNthCommandWith = toHaveReceivedNthCommandWith ;
243
243
244
- const toHaveReceivedLastCommandWith : CustomMatcherFn = function (
244
+ const toHaveReceivedLastCommandWith : CustomMatcherFn = function (
245
245
client : AwsStub < any , any , any > ,
246
246
command : AwsCommandConstructur < any , any > ,
247
- input : Record < string , any >
247
+ input : Record < string , any > ,
248
248
) {
249
249
const { isNot, utils } = this ;
250
250
const calls = client . commandCalls ( command ) ;
@@ -261,12 +261,12 @@ const toHaveReceivedLastCommandWith: CustomMatcherFn = function(
261
261
: `expected last "${ command . name } " to be called with arguments: ${ utils . printExpected ( input ) } ` ;
262
262
return formatCalls ( this , client , command , input , message ) ;
263
263
} ,
264
- pass
264
+ pass,
265
265
} ;
266
266
} ;
267
267
const toReceiveLastCommandWith = toHaveReceivedLastCommandWith ;
268
268
269
- export type { CustomMatcher }
269
+ export type { CustomMatcher } ;
270
270
export {
271
271
toHaveReceivedCommand ,
272
272
toHaveReceivedCommandOnce ,
@@ -279,5 +279,5 @@ export {
279
279
toReceiveCommandTimes ,
280
280
toReceiveCommandWith ,
281
281
toReceiveLastCommandWith ,
282
- toReceiveNthCommandWith
282
+ toReceiveNthCommandWith ,
283
283
} ;
0 commit comments