@thisisagile/easy-test 15.8.3 → 15.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/index.d.mts +379 -0
  2. package/dist/index.d.ts +379 -2
  3. package/dist/index.js +3 -19
  4. package/dist/index.mjs +3 -0
  5. package/package.json +3 -1
  6. package/src/matchers/Check.ts +18 -18
  7. package/src/matchers/HttpMatchers.ts +12 -13
  8. package/src/matchers/Match.ts +1 -2
  9. package/src/matchers/ResultMatchers.ts +3 -4
  10. package/src/matchers/toBeArrayOf.ts +1 -2
  11. package/src/matchers/toBeArrayOfWithLength.ts +1 -2
  12. package/src/matchers/toBeAt.ts +1 -2
  13. package/src/matchers/toBeExactlyAt.ts +1 -2
  14. package/src/matchers/toBeValid.ts +1 -2
  15. package/src/matchers/toFailMatcher.ts +2 -3
  16. package/src/matchers/toMatchExactJson.ts +1 -2
  17. package/src/matchers/toMatchException.ts +1 -2
  18. package/src/matchers/toMatchJson.ts +1 -2
  19. package/src/matchers/toMatchRoute.ts +1 -2
  20. package/src/matchers/toMatchText.ts +1 -2
  21. package/src/matchers/toPassMatcher.ts +3 -3
  22. package/src/mock/Mocks.ts +12 -16
  23. package/src/utils/Req.ts +9 -4
  24. package/dist/index.js.map +0 -1
  25. package/dist/matchers/Check.d.ts +0 -18
  26. package/dist/matchers/Check.js +0 -46
  27. package/dist/matchers/Check.js.map +0 -1
  28. package/dist/matchers/HttpMatchers.d.ts +0 -33
  29. package/dist/matchers/HttpMatchers.js +0 -52
  30. package/dist/matchers/HttpMatchers.js.map +0 -1
  31. package/dist/matchers/Match.d.ts +0 -13
  32. package/dist/matchers/Match.js +0 -36
  33. package/dist/matchers/Match.js.map +0 -1
  34. package/dist/matchers/ResultMatchers.d.ts +0 -15
  35. package/dist/matchers/ResultMatchers.js +0 -30
  36. package/dist/matchers/ResultMatchers.js.map +0 -1
  37. package/dist/matchers/index.d.ts +0 -19
  38. package/dist/matchers/index.js +0 -36
  39. package/dist/matchers/index.js.map +0 -1
  40. package/dist/matchers/toBeArrayOf.d.ts +0 -11
  41. package/dist/matchers/toBeArrayOf.js +0 -14
  42. package/dist/matchers/toBeArrayOf.js.map +0 -1
  43. package/dist/matchers/toBeArrayOfWithLength.d.ts +0 -11
  44. package/dist/matchers/toBeArrayOfWithLength.js +0 -15
  45. package/dist/matchers/toBeArrayOfWithLength.js.map +0 -1
  46. package/dist/matchers/toBeAt.d.ts +0 -11
  47. package/dist/matchers/toBeAt.js +0 -19
  48. package/dist/matchers/toBeAt.js.map +0 -1
  49. package/dist/matchers/toBeExactlyAt.d.ts +0 -11
  50. package/dist/matchers/toBeExactlyAt.js +0 -22
  51. package/dist/matchers/toBeExactlyAt.js.map +0 -1
  52. package/dist/matchers/toBeQueriedWith.d.ts +0 -9
  53. package/dist/matchers/toBeQueriedWith.js +0 -14
  54. package/dist/matchers/toBeQueriedWith.js.map +0 -1
  55. package/dist/matchers/toBeRoutedTo.d.ts +0 -9
  56. package/dist/matchers/toBeRoutedTo.js +0 -15
  57. package/dist/matchers/toBeRoutedTo.js.map +0 -1
  58. package/dist/matchers/toBeValid.d.ts +0 -10
  59. package/dist/matchers/toBeValid.js +0 -15
  60. package/dist/matchers/toBeValid.js.map +0 -1
  61. package/dist/matchers/toFailMatcher.d.ts +0 -21
  62. package/dist/matchers/toFailMatcher.js +0 -27
  63. package/dist/matchers/toFailMatcher.js.map +0 -1
  64. package/dist/matchers/toMatchArray.d.ts +0 -9
  65. package/dist/matchers/toMatchArray.js +0 -15
  66. package/dist/matchers/toMatchArray.js.map +0 -1
  67. package/dist/matchers/toMatchExactJson.d.ts +0 -16
  68. package/dist/matchers/toMatchExactJson.js +0 -21
  69. package/dist/matchers/toMatchExactJson.js.map +0 -1
  70. package/dist/matchers/toMatchException.d.ts +0 -11
  71. package/dist/matchers/toMatchException.js +0 -16
  72. package/dist/matchers/toMatchException.js.map +0 -1
  73. package/dist/matchers/toMatchJson.d.ts +0 -16
  74. package/dist/matchers/toMatchJson.js +0 -22
  75. package/dist/matchers/toMatchJson.js.map +0 -1
  76. package/dist/matchers/toMatchRoute.d.ts +0 -11
  77. package/dist/matchers/toMatchRoute.js +0 -15
  78. package/dist/matchers/toMatchRoute.js.map +0 -1
  79. package/dist/matchers/toMatchText.d.ts +0 -10
  80. package/dist/matchers/toMatchText.js +0 -15
  81. package/dist/matchers/toMatchText.js.map +0 -1
  82. package/dist/matchers/toPassMatcher.d.ts +0 -21
  83. package/dist/matchers/toPassMatcher.js +0 -27
  84. package/dist/matchers/toPassMatcher.js.map +0 -1
  85. package/dist/mock/Fits.d.ts +0 -24
  86. package/dist/mock/Fits.js +0 -44
  87. package/dist/mock/Fits.js.map +0 -1
  88. package/dist/mock/Mocks.d.ts +0 -41
  89. package/dist/mock/Mocks.js +0 -75
  90. package/dist/mock/Mocks.js.map +0 -1
  91. package/dist/mock/index.d.ts +0 -2
  92. package/dist/mock/index.js +0 -19
  93. package/dist/mock/index.js.map +0 -1
  94. package/dist/utils/Eq.d.ts +0 -5
  95. package/dist/utils/Eq.js +0 -11
  96. package/dist/utils/Eq.js.map +0 -1
  97. package/dist/utils/Req.d.ts +0 -14
  98. package/dist/utils/Req.js +0 -32
  99. package/dist/utils/Req.js.map +0 -1
  100. package/dist/utils/Response.d.ts +0 -25
  101. package/dist/utils/Response.js +0 -3
  102. package/dist/utils/Response.js.map +0 -1
  103. package/dist/utils/Types.d.ts +0 -44
  104. package/dist/utils/Types.js +0 -7
  105. package/dist/utils/Types.js.map +0 -1
  106. package/dist/utils/Utils.d.ts +0 -12
  107. package/dist/utils/Utils.js +0 -28
  108. package/dist/utils/Utils.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,2 +1,379 @@
1
- export * from './matchers';
2
- export * from './mock';
1
+ import { AsymmetricMatcher } from 'expect';
2
+
3
+ type OneOrMore<T> = T | Array<T>;
4
+ type Constructor<T> = {
5
+ new (...args: any[]): T;
6
+ };
7
+ type Message<P> = Text | ((...params: P[]) => Text);
8
+ type Validatable = {
9
+ isValid: boolean;
10
+ };
11
+ type Result = {
12
+ domain?: string;
13
+ location?: string;
14
+ message: string;
15
+ };
16
+ type Results = Validatable & {
17
+ results: Result[];
18
+ };
19
+ type Uri = Text;
20
+ type Id = string | number;
21
+ type JsonValue = string | number | boolean | null | Json | JsonValue[];
22
+ type Json = {
23
+ [key: string]: JsonValue;
24
+ };
25
+ type Exception = {
26
+ id: Id;
27
+ reason?: string;
28
+ };
29
+ type Text = {
30
+ toString: () => string;
31
+ };
32
+ type Query = Text;
33
+ type UseCase = {
34
+ app: {
35
+ id: Text;
36
+ };
37
+ id: Text;
38
+ };
39
+ type Tester = {
40
+ url: string;
41
+ };
42
+
43
+ type HttpStatus = {
44
+ name: string;
45
+ id: Id;
46
+ };
47
+ type RestResult = {
48
+ data?: {
49
+ code: number;
50
+ items: unknown[];
51
+ itemCount: number;
52
+ };
53
+ error?: {
54
+ code: number;
55
+ message: string;
56
+ errorCount: number;
57
+ errors: unknown[];
58
+ };
59
+ };
60
+ type Response = {
61
+ status: HttpStatus;
62
+ headers?: {
63
+ [key: string]: any;
64
+ };
65
+ body?: RestResult;
66
+ };
67
+
68
+ declare const toHaveStatus: (res: Response, code: number) => jest.CustomMatcherResult;
69
+ declare const toBeOk: (res: Response) => jest.CustomMatcherResult;
70
+ declare const toBeCreated: (res: Response) => jest.CustomMatcherResult;
71
+ declare const toHaveNoContent: (res: Response) => jest.CustomMatcherResult;
72
+ declare const toBeBadRequest: (res: Response) => jest.CustomMatcherResult;
73
+ declare const toBeUnauthorized: (res: Response) => jest.CustomMatcherResult;
74
+ declare const toBeForbidden: (res: Response) => jest.CustomMatcherResult;
75
+ declare const toBeNotFound: (res: Response) => jest.CustomMatcherResult;
76
+ declare const toBeConflict: (res: Response) => jest.CustomMatcherResult;
77
+ declare const toBeInternalServerError: (res: Response) => jest.CustomMatcherResult;
78
+ declare const toBeBadGateway: (res: Response) => jest.CustomMatcherResult;
79
+ declare const toBeOkWithItems: (res: Response, length: number) => jest.CustomMatcherResult;
80
+ declare global {
81
+ namespace jest {
82
+ interface Matchers<R, T> {
83
+ toBeOk(): R;
84
+ toBeOkWithItems(length: number): R;
85
+ toBeCreated(): R;
86
+ toHaveNoContent(): R;
87
+ toBeNotFound(): R;
88
+ toBeUnauthorized(): R;
89
+ toBeForbidden(): R;
90
+ toBeBadRequest(): R;
91
+ toBeConflict(): R;
92
+ toBeInternalServerError(): R;
93
+ toBeBadGateway(): R;
94
+ toHaveStatus(code: number): R;
95
+ }
96
+ }
97
+ }
98
+
99
+ declare class Match<S> {
100
+ private readonly subject;
101
+ private readonly failed;
102
+ private readonly message;
103
+ constructor(subject: S, failed?: boolean, message?: Message<S>);
104
+ not(p: (s: S) => boolean, message: Message<S>): Match<S>;
105
+ undefined(p: (s: S) => any, message: Message<S>): Match<S>;
106
+ else(message: Message<S>): jest.CustomMatcherResult;
107
+ }
108
+ declare const match: <S>(subject: S) => Match<S>;
109
+
110
+ type ToMessage<S> = string | ((s: S[]) => string);
111
+ declare class Check<S> {
112
+ private ctx;
113
+ private readonly received;
114
+ private readonly expected;
115
+ private readonly failed;
116
+ private readonly message;
117
+ constructor(ctx: jest.MatcherContext, received: S, expected: S, failed?: boolean, message?: string);
118
+ print(message: ToMessage<S>): string;
119
+ not(p: (s: S[]) => boolean, message: ToMessage<S>): Check<S>;
120
+ undefined(p: (s: S[]) => any, message: ToMessage<S>): Check<S>;
121
+ else(message?: ToMessage<S>): jest.CustomMatcherResult;
122
+ }
123
+ declare const check: <S>(ctx: jest.MatcherContext, received: S, expected?: S | undefined) => Check<S>;
124
+ declare const checkDefined: <S>(ctx: jest.MatcherContext, received: S, expected?: S | undefined) => Check<S>;
125
+
126
+ declare const toResultWith: (results: Results, message: string) => jest.CustomMatcherResult;
127
+ declare const toFail: (results: Results) => jest.CustomMatcherResult;
128
+ declare const toFailWith: (results: Results, message: string) => jest.CustomMatcherResult;
129
+ declare global {
130
+ namespace jest {
131
+ interface Matchers<R, T> {
132
+ toResultWith(message: string): R;
133
+ toFail(): R;
134
+ toFailWith(message: string): R;
135
+ }
136
+ }
137
+ }
138
+
139
+ declare const toBeArrayOf: <T>(items: unknown, ctor: Constructor<T>) => jest.CustomMatcherResult;
140
+ declare global {
141
+ namespace jest {
142
+ interface Matchers<R, T> {
143
+ toBeArrayOf<Z>(ctor: Constructor<Z>): R;
144
+ }
145
+ }
146
+ }
147
+
148
+ declare const toBeArrayOfWithLength: <T>(items: unknown, ctor: Constructor<T>, length: number) => jest.CustomMatcherResult;
149
+ declare global {
150
+ namespace jest {
151
+ interface Matchers<R, T> {
152
+ toBeArrayOfWithLength<Z>(ctor: Constructor<Z>, length: number): R;
153
+ }
154
+ }
155
+ }
156
+
157
+ declare const toBeAt: (tester?: Tester, uc?: UseCase, id?: Id) => jest.CustomMatcherResult;
158
+ declare global {
159
+ namespace jest {
160
+ interface Matchers<R, T> {
161
+ toBeAt(uc?: UseCase, id?: Id): R;
162
+ }
163
+ }
164
+ }
165
+
166
+ declare const toBeExactlyAt: (tester?: Tester, uc?: UseCase, id?: Id) => jest.CustomMatcherResult;
167
+ declare global {
168
+ namespace jest {
169
+ interface Matchers<R, T> {
170
+ toBeExactlyAt(uc?: UseCase, id?: Id): R;
171
+ }
172
+ }
173
+ }
174
+
175
+ declare const Fails: {
176
+ Yes: string;
177
+ No: (reason: string) => string;
178
+ };
179
+ declare const FailsWith: {
180
+ Yes: string;
181
+ No: (message: string, instead: string) => string;
182
+ };
183
+ declare const toFailMatcher: (result: jest.CustomMatcherResult) => jest.CustomMatcherResult;
184
+ declare const toFailMatcherWith: (result: jest.CustomMatcherResult, message: Message<jest.CustomMatcherResult>) => jest.CustomMatcherResult;
185
+ declare global {
186
+ namespace jest {
187
+ interface Matchers<R, T> {
188
+ toFailMatcher(): R;
189
+ toFailMatcherWith(message: string): R;
190
+ }
191
+ }
192
+ }
193
+
194
+ declare const toBeValid: (v?: unknown) => jest.CustomMatcherResult;
195
+ declare global {
196
+ namespace jest {
197
+ interface Matchers<R, T> {
198
+ toBeValid(): R;
199
+ }
200
+ }
201
+ }
202
+
203
+ declare function toMatchArray(this: jest.MatcherContext, received: any[], expected: any[]): jest.CustomMatcherResult;
204
+ declare global {
205
+ namespace jest {
206
+ interface Matchers<R, T> {
207
+ toMatchArray(expected: any[]): R;
208
+ }
209
+ }
210
+ }
211
+
212
+ declare const MatchesExactJson: {
213
+ SubjectUndefined: string;
214
+ SubsetUndefined: string;
215
+ DoesNotMatch: string;
216
+ Yes: string;
217
+ };
218
+ declare const toMatchExactJson: (value?: unknown, json?: unknown) => jest.CustomMatcherResult;
219
+ declare global {
220
+ namespace jest {
221
+ interface Matchers<R, T> {
222
+ toMatchExactJson(json?: unknown): R;
223
+ }
224
+ }
225
+ }
226
+
227
+ declare const toMatchException: (received: Exception, expected: unknown, reason?: string) => jest.CustomMatcherResult;
228
+ declare global {
229
+ namespace jest {
230
+ interface Matchers<R, T> {
231
+ toMatchException(exception: unknown, reason?: string): R;
232
+ }
233
+ }
234
+ }
235
+
236
+ declare const MatchesJson: {
237
+ SubjectUndefined: string;
238
+ SubsetUndefined: string;
239
+ DoesNotMatch: string;
240
+ Yes: string;
241
+ };
242
+ declare const toMatchJson: (value?: unknown, subset?: unknown) => jest.CustomMatcherResult;
243
+ declare global {
244
+ namespace jest {
245
+ interface Matchers<R, T> {
246
+ toMatchJson(subset?: unknown): R;
247
+ }
248
+ }
249
+ }
250
+
251
+ declare const toMatchRoute: (uri?: Uri, route?: Uri | string) => jest.CustomMatcherResult;
252
+ declare global {
253
+ namespace jest {
254
+ interface Matchers<R, T> {
255
+ toMatchRoute(route?: Uri | string): R;
256
+ }
257
+ }
258
+ }
259
+
260
+ declare const toMatchText: (value?: unknown, text?: unknown) => jest.CustomMatcherResult;
261
+ declare global {
262
+ namespace jest {
263
+ interface Matchers<R, T> {
264
+ toMatchText(text?: unknown): R;
265
+ }
266
+ }
267
+ }
268
+
269
+ declare const Passes: {
270
+ Yes: string;
271
+ No: (reason: string) => string;
272
+ };
273
+ declare const PassesWith: {
274
+ Yes: string;
275
+ No: (message: string, instead: string) => string;
276
+ };
277
+ declare const toPassMatcher: (result: jest.CustomMatcherResult) => jest.CustomMatcherResult;
278
+ declare const toPassMatcherWith: (result: jest.CustomMatcherResult, message: Message<jest.CustomMatcherResult>) => jest.CustomMatcherResult;
279
+ declare global {
280
+ namespace jest {
281
+ interface Matchers<R, T> {
282
+ toPassMatcher(): R;
283
+ toPassMatcherWith(message: string): R;
284
+ }
285
+ }
286
+ }
287
+
288
+ declare const toBeQueriedWith: (query: jest.Mock, expected: Query) => jest.CustomMatcherResult;
289
+ declare global {
290
+ namespace jest {
291
+ interface Matchers<R, T> {
292
+ toBeQueriedWith(expected: Query): R;
293
+ }
294
+ }
295
+ }
296
+
297
+ declare const toBeRoutedTo: (query: jest.Mock, expected: Uri) => jest.CustomMatcherResult;
298
+ declare global {
299
+ namespace jest {
300
+ interface Matchers<R, T> {
301
+ toBeRoutedTo(uri: Uri): R;
302
+ }
303
+ }
304
+ }
305
+
306
+ declare class ObjectContainingText extends AsymmetricMatcher<string> {
307
+ asymmetricMatch(other: any): boolean;
308
+ toString(): string;
309
+ }
310
+ declare class ObjectContainingTextExact extends AsymmetricMatcher<string> {
311
+ asymmetricMatch(other: any): boolean;
312
+ toString(): string;
313
+ }
314
+ declare class ObjectContainingJson extends AsymmetricMatcher<any> {
315
+ asymmetricMatch(other: any): boolean;
316
+ toString(): string;
317
+ }
318
+ declare const fits: {
319
+ any: () => any;
320
+ type: (type?: unknown) => any;
321
+ with: (o: unknown) => any;
322
+ text: (s: any) => any;
323
+ textExact: (s: any) => any;
324
+ uri: (u: Uri) => any;
325
+ json: (s: any) => any;
326
+ items: (...items: any[]) => any;
327
+ };
328
+
329
+ declare class Req {
330
+ readonly state: any;
331
+ constructor(state?: any);
332
+ get id(): Id;
333
+ get q(): JsonValue;
334
+ get path(): Json;
335
+ get query(): Json;
336
+ get skip(): number | undefined;
337
+ get take(): number | undefined;
338
+ get body(): unknown;
339
+ get headers(): Record<string, OneOrMore<string>>;
340
+ get: (key: Text) => any;
341
+ }
342
+
343
+ declare class Mocks {
344
+ clear: () => typeof jest;
345
+ impl: (f?: ((...args: any[]) => any) | undefined) => jest.Mock;
346
+ property: <T extends object, P extends keyof { [K in keyof Required<T> as Required<T>[K] extends jest.Func ? never : K]: Required<T>[K]; }>(object: T, getter: P, value: T[P]) => jest.SpyInstance;
347
+ reject: (value?: unknown) => jest.Mock;
348
+ rejectWith: <T = any>(props?: Partial<T>) => jest.Mock;
349
+ req: {
350
+ id: (id: Id) => Req;
351
+ q: (q: unknown) => Req;
352
+ with: (a: Json) => Req;
353
+ body: (body: unknown) => Req;
354
+ path: (path: Json) => Req;
355
+ query: (query: Json) => Req;
356
+ };
357
+ resp: {
358
+ items: (status: HttpStatus, items?: unknown[]) => Response;
359
+ errors: (status: HttpStatus, message: string, errors?: unknown[]) => Response;
360
+ };
361
+ resolve: (value?: unknown) => jest.Mock;
362
+ resolveWith: <T = any>(props?: Partial<T>) => jest.Mock;
363
+ return: (value?: unknown) => jest.Mock;
364
+ returnWith: <T = any>(props?: Partial<T>) => jest.Mock;
365
+ this: () => jest.Mock;
366
+ provider: {
367
+ data: (...items: any[]) => {
368
+ execute: jest.Mock;
369
+ };
370
+ };
371
+ empty: <T = any>(props?: Partial<T>) => T;
372
+ a: <T = any>(props?: Partial<T>) => T;
373
+ an: <T = any>(props?: Partial<T>) => T;
374
+ date: (epoch?: number) => Date;
375
+ once: (...values: unknown[]) => jest.Mock;
376
+ }
377
+ declare const mock: Mocks;
378
+
379
+ export { Fails, FailsWith, Match, MatchesExactJson, MatchesJson, Mocks, ObjectContainingJson, ObjectContainingText, ObjectContainingTextExact, Passes, PassesWith, check, checkDefined, fits, match, mock, toBeArrayOf, toBeArrayOfWithLength, toBeAt, toBeBadGateway, toBeBadRequest, toBeConflict, toBeCreated, toBeExactlyAt, toBeForbidden, toBeInternalServerError, toBeNotFound, toBeOk, toBeOkWithItems, toBeQueriedWith, toBeRoutedTo, toBeUnauthorized, toBeValid, toFail, toFailMatcher, toFailMatcherWith, toFailWith, toHaveNoContent, toHaveStatus, toMatchArray, toMatchExactJson, toMatchException, toMatchJson, toMatchRoute, toMatchText, toPassMatcher, toPassMatcherWith, toResultWith };
package/dist/index.js CHANGED
@@ -1,19 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./matchers"), exports);
18
- __exportStar(require("./mock"), exports);
19
- //# sourceMappingURL=index.js.map
1
+ "use strict";var C=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var je=Object.prototype.hasOwnProperty;var Se=(t,e)=>{for(var s in e)C(t,s,{get:e[s],enumerable:!0})},we=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of be(e))!je.call(t,c)&&c!==s&&C(t,c,{get:()=>e[c],enumerable:!(n=Me(e,c))||n.enumerable});return t};var ke=t=>we(C({},"__esModule",{value:!0}),t);var $e={};Se($e,{Fails:()=>M,FailsWith:()=>N,Match:()=>R,MatchesExactJson:()=>x,MatchesJson:()=>y,Mocks:()=>T,ObjectContainingJson:()=>w,ObjectContainingText:()=>j,ObjectContainingTextExact:()=>S,Passes:()=>b,PassesWith:()=>q,check:()=>Ce,checkDefined:()=>B,fits:()=>ge,match:()=>o,mock:()=>l,toBeArrayOf:()=>te,toBeArrayOfWithLength:()=>se,toBeAt:()=>ne,toBeBadGateway:()=>H,toBeBadRequest:()=>I,toBeConflict:()=>Q,toBeCreated:()=>P,toBeExactlyAt:()=>re,toBeForbidden:()=>D,toBeInternalServerError:()=>L,toBeNotFound:()=>Y,toBeOk:()=>V,toBeOkWithItems:()=>Z,toBeQueriedWith:()=>ye,toBeRoutedTo:()=>Re,toBeUnauthorized:()=>O,toBeValid:()=>ce,toFail:()=>_,toFailMatcher:()=>ae,toFailMatcherWith:()=>ie,toFailWith:()=>ee,toHaveNoContent:()=>F,toHaveStatus:()=>i,toMatchArray:()=>ue,toMatchExactJson:()=>de,toMatchException:()=>pe,toMatchJson:()=>le,toMatchRoute:()=>me,toMatchText:()=>he,toPassMatcher:()=>fe,toPassMatcherWith:()=>xe,toResultWith:()=>X});module.exports=ke($e);var a=t=>t!=null,f=t=>a(t)&&typeof t=="number"&&!Number.isNaN(t),$=t=>a(t)&&typeof t=="function",A=(t,...e)=>a(t)&&e.every(s=>a(t[s]));var J=t=>a(t)&&t instanceof Array,Te=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&!J(t),m=t=>t?.toJSON?t.toJSON():Te(t)?t:void 0,r=t=>t?.toString(),v=(t,e)=>{let s=parseInt(r(t));return f(s)?s:$(e)?e():f(e)?e:NaN},E=(...t)=>t.length>1?t:J(t[0])?t[0]:a(t[0])?[t[0]]:[];var u=(t,...e)=>r($(t)?t(...e):t);var R=class t{constructor(e,s=!1,n=""){this.subject=e;this.failed=s;this.message=n}not(e,s){if(this.failed)return this;try{return new t(this.subject,!e(this.subject),u(s,this.subject))}catch(n){return new t(this.subject,!0,n.message)}}undefined(e,s){return this.not(()=>a(e(this.subject)),s)}else(e){return{pass:!this.failed,message:()=>this.failed?u(this.message):`${u(e,this.subject)}, which we did not expect.`}}},o=t=>new R(t);var i=(t,e)=>o(t).undefined(s=>s,"Response is unknown.").undefined(s=>s?.status?.id,()=>"Response does not have a status code").not(s=>s.status.id===e,s=>`Response does not have code '${e}', but has code '${s.status.id}' instead.`).else(`Response does have status code '${e}'.`),V=t=>i(t,200),P=t=>i(t,201),F=t=>i(t,204),I=t=>i(t,400),O=t=>i(t,401),D=t=>i(t,403),Y=t=>i(t,404),Q=t=>i(t,409),L=t=>i(t,500),H=t=>i(t,502),Z=(t,e)=>o(t).undefined(s=>s.status?.id,"Response did not have a status").not(s=>s.status.id===200,s=>`Response did not have status '200'. It had status '${s.status.id}' instead.`).undefined(s=>s?.body?.data?.items,"Response did not have any items.").not(s=>(s?.body?.data?.itemCount??0)>=e,s=>`Response did not have at least ${e} items. It only had ${s?.body?.data?.itemCount??0} items.`).else(`Response had status 200 and at least ${e} items`);expect.extend({toBeOk:V,toBeOkWithItems:Z,toBeCreated:P,toHaveNoContent:F,toBeNotFound:Y,toBeBadRequest:I,toBeUnauthorized:O,toBeForbidden:D,toBeConflict:Q,toBeInternalServerError:L,toHaveStatus:i,toBeBadGateway:H});var g=class t{constructor(e,s,n,c=!1,W=""){this.ctx=e;this.received=s;this.expected=n;this.failed=c;this.message=W}print(e){return(typeof e=="function"?e([this.received,this.expected]):e).replace("{r}",this.ctx.utils.printReceived(this.received)).replace("{e}",this.ctx.utils.printExpected(this.expected)).replace("{diff}",this.ctx.utils.diff(this.received,this.expected)??"")}not(e,s){if(this.failed)return this;try{return new t(this.ctx,this.received,this.expected,!e([this.received,this.expected]),this.print(s))}catch(n){return new t(this.ctx,this.received,this.expected,!0,n.message)}}undefined(e,s){return this.not(()=>a(e([this.received,this.expected])),this.print(s))}else(e="Expected {r} not to match with {e}, but it did."){return{pass:!this.failed,message:()=>this.failed?this.message:this.print(e)}}},Ce=(t,e,s)=>new g(t,e,s),B=(t,e,s)=>new g(t,e,s).undefined(([n])=>n,"Received array is undefined.").undefined(([,n])=>n,"Expected array is undefined.");var U="Results is not defined.",G="Results does not fail.",z=(t,e)=>t.results.some(s=>s.message===e),K=t=>"'"+t?.results.map(e=>e.message).join("', '")+"'",X=(t,e)=>o(t).undefined(s=>s,U).not(s=>z(s,e),s=>`Results does not have message '${e}', but it has messages ${K(s)} instead.`).else(`Succeeds with message ${e}`),_=t=>o(t).undefined(e=>e,U).not(e=>!e.isValid,G).else("Results does not fail"),ee=(t,e)=>o(t).undefined(s=>s,U).not(s=>!s.isValid,G).not(s=>z(s,e),s=>`Fails, but results does not have message '${e}', but it has messages ${K(s)} instead.`).else(`Fails with message '${e}'`);expect.extend({toResultWith:X,toFail:_,toFailWith:ee});var te=(t,e)=>o(t).undefined(s=>s,"Subject is undefined.").not(s=>s instanceof Array,"Subject is not an array.").not(s=>s.every(n=>n instanceof e),`Not all elements are of type '${e.name}'.`).else(`All elements in array are of type '${e.name}'`);expect.extend({toBeArrayOf:te});var se=(t,e,s)=>o(t).undefined(n=>n,"Subject is undefined.").not(n=>n instanceof Array,"Subject is not an array.").not(n=>n.length===s,n=>`Subject does not have ${s} elements, but ${n.length}.`).not(n=>n.every(c=>c instanceof e),`Not all elements are of type '${e.name}'.`).else(`Subject has ${s} elements, which are all of type '${e.name}'`);expect.extend({toBeArrayOfWithLength:se});var ne=(t,e,s)=>o(t).undefined(n=>n,"Tester is undefined").undefined(n=>n.url,"Tester does not contain a URL").undefined(()=>e,"Use case is undefined").not(n=>n.url.includes(`/${e?.app.id}`),n=>`We expected the tester to be at app '${e?.app.id}', but it is at '${n?.url}' instead.`).not(n=>n.url.includes(`/${e?.id}`),n=>`We expected the tester to be at use case '${e?.id}', but it is at '${n?.url}' instead.`).not(n=>n.url.includes(s?`/${s}`:""),n=>`We expected the path to contain '/42', but it is '${n?.url}' instead.`).else(n=>`The tester is at '${n?.url}'`);expect.extend({toBeAt:ne});var oe=(t,e)=>{let s=a(e)?`/${e}`:"";return`/${t.app.id}/${t.id}${s}`},re=(t,e,s)=>o(t).undefined(n=>n,"Tester is undefined").undefined(n=>n.url,"Tester does not contain a URL").undefined(()=>e,"Use case is undefined").not(n=>n.url.includes(oe(e,s)),n=>`We expected the tester to be at: '${oe(e,s)}', but it is at: '${n?.url}' instead.`).else(n=>`The tester is at '${n?.url}'`);expect.extend({toBeExactlyAt:re});var M={Yes:"Match fails, instead of passes.",No:t=>`Match doesn't fail, because '${t}'`},N={Yes:"Match fails with correct message.",No:(t,e)=>`Match does fail, however not with message '${t}', but with message '${e}' instead.`},ae=t=>o(t).not(e=>!e.pass,e=>M.No(e.message())).else(M.Yes),ie=(t,e)=>o(t).not(s=>!s.pass,s=>M.No(s.message())).not(s=>s.message().includes(u(e)),s=>N.No(u(e),s.message())).else(N.Yes);expect.extend({toFailMatcher:ae,toFailMatcherWith:ie});var ce=t=>o(t).undefined(e=>e,"Subject is undefined.").not(e=>A(e,"isValid"),"Subject is not validatable.").not(e=>e.isValid,"Subject is not valid.").else("Subject is valid");expect.extend({toBeValid:ce});function ue(t,e){return B(this,t,e).not(([s,n])=>s.length===n.length,([s,n])=>`Received array has length ${s.length}, while expected array has length ${n.length}.`).not(([s,n])=>s.every((c,W)=>this.equals(c,n[W])),`Elements in {r} do not match elements in {e}.
2
+
3
+ {diff}.`).else()}expect.extend({toMatchArray:ue});var p=require("@jest/expect-utils"),h={exact:(t,e)=>(0,p.equals)(t,e,[]),subset:(t,e)=>(0,p.equals)(t,e,[p.iterableEquality,p.subsetEquality]),string:(t,e)=>r(t)===r(e)};var x={SubjectUndefined:"Subject is undefined.",SubsetUndefined:"Object to match with is undefined.",DoesNotMatch:"Object does not exactly match subject.",Yes:"Object matches subject exactly"},de=(t,e)=>o(t).undefined(s=>s,x.SubjectUndefined).undefined(()=>e,x.SubsetUndefined).not(s=>h.exact(s,e),x.DoesNotMatch).else(()=>x.Yes);expect.extend({toMatchExactJson:de});var pe=(t,e,s)=>o(e).undefined(n=>n.id,"Expected value is not an exception.").not(n=>n.id===t.id,n=>`Expected exception has id '${n.id}', while the received exception has id '${t.id}'.`).not(()=>!a(s)||a(s)&&a(t.reason),()=>`We expected to have reason '${s}', but we received no reason.`).not(()=>!a(s)||a(s)&&t.reason===s,()=>`We expected to have reason '${s}', but we received reason '${t.reason}'.`).else("Expected exception matches received exception");expect.extend({toMatchException:pe});var y={SubjectUndefined:"Subject is undefined.",SubsetUndefined:"Subset to match with is undefined.",DoesNotMatch:"Subset does not match subject.",Yes:"Subset matches subject"},le=(t,e)=>o(t).undefined(s=>s,y.SubjectUndefined).undefined(()=>e,y.SubsetUndefined).not(s=>h.subset(m(s),m(e)),y.DoesNotMatch).else(()=>y.Yes);expect.extend({toMatchJson:le});var me=(t,e)=>o(t).undefined(s=>s,"Subject is undefined.").undefined(()=>e,"Route to include is undefined.").not(s=>r(s).includes(r(e)),s=>`Uri '${s}' does not include '${e}'.`).else(s=>`Uri '${s}' includes '${e}'`);expect.extend({toMatchRoute:me});var he=(t,e)=>o(t).undefined(s=>s,"Subject is undefined.").undefined(()=>e,"Text to match with is undefined.").not(s=>r(s)===r(e),s=>`Text '${s}' does not match with text '${e}'.`).else(s=>`Text '${s}' matches`);expect.extend({toMatchText:he});var b={Yes:"Match passes, instead of fails.",No:t=>`Match doesn't pass, because '${t}'`},q={Yes:"Match passes with correct message.",No:(t,e)=>`Match does pass, however not with message '${t}', but with message '${e}' instead.`},fe=t=>o(t).not(e=>e.pass,e=>b.No(e.message())).else(b.Yes),xe=(t,e)=>o(t).not(s=>s.pass,s=>b.No(s.message())).not(s=>s.message().includes(u(e)),s=>q.No(u(e),s.message())).else(q.Yes);expect.extend({toPassMatcher:fe,toPassMatcherWith:xe});var ye=(t,e)=>o(t?.mock?.calls).undefined(s=>s,"Query is unknown.").not(s=>s.length===1,"Query did not execute.").not(s=>s[0][0].toString()===e?.toString(),s=>`We expected query '${e}', but we received query '${s[0][0]}' instead.`).else(`Received query does match '${e}'`);expect.extend({toBeQueriedWith:ye});var Re=(t,e)=>o(t?.mock?.calls).undefined(s=>s,"Uri is unknown.").not(s=>s.length===1,"Method was not called.").not(s=>r(s[0][0])===r(e),s=>`We expected uri '${r(e)}', but we received uri '${r(s[0][0])}' instead.`).else(`Called uri does match '${r(e)}'`);expect.extend({toBeRoutedTo:Re});var k=require("expect"),j=class extends k.AsymmetricMatcher{asymmetricMatch(e){return r(e).includes(r(this.sample))}toString(){return`String${this.inverse?"Not":""}Containing`}},S=class extends k.AsymmetricMatcher{asymmetricMatch(e){return r(e)===r(this.sample)}toString(){return`String${this.inverse?"Not":""}Containing`}},w=class extends k.AsymmetricMatcher{asymmetricMatch(e){return h.subset(m(e),m(this.sample))}toString(){return`Object${this.inverse?"Not":""}Containing`}},ge={any:()=>expect.anything(),type:t=>expect.any(t),with:t=>expect.objectContaining(t),text:t=>new j(t),textExact:t=>new S(t),uri:t=>ge.textExact(t),json:t=>new w(t),items:(...t)=>expect.arrayContaining(E(...t))};var d=class{constructor(e={}){this.state=e}get id(){return this.state.id??this.path.id}get q(){return this.state.q??this.query.q}get path(){return this.state?.path??{}}get query(){return this.state?.query??{}}get skip(){return f(this.query?.skip)?v(this.query?.skip):void 0}get take(){return f(this.query?.take)?v(this.query?.take):void 0}get body(){return this.state.body}get headers(){return this.state.headers}get=e=>this?.state[e.toString()]??this.path[e.toString()]??this.query[e.toString()]};var T=class{clear=()=>jest.clearAllMocks();impl=e=>jest.fn().mockImplementation(e);property=(e,s,n)=>jest.spyOn(e,s,"get").mockReturnValue(n);reject=e=>jest.fn().mockRejectedValue(e);rejectWith=(e={})=>jest.fn().mockRejectedValue(l.a(e));req={id:e=>new d({id:e}),q:e=>new d({q:e}),with:e=>new d(e),body:e=>new d({body:e}),path:e=>new d({path:e}),query:e=>new d({query:e})};resp={items:(e,s=[])=>({status:e,body:{data:{code:e.id,itemCount:s.length,items:s}}}),errors:(e,s,n=[])=>({status:e,body:{error:{code:e.id,message:s,errorCount:n.length,errors:n}}})};resolve=e=>jest.fn().mockResolvedValue(e);resolveWith=(e={})=>jest.fn().mockResolvedValue(l.a(e));return=e=>jest.fn().mockReturnValue(e);returnWith=(e={})=>jest.fn().mockReturnValue(l.a(e));this=()=>jest.fn().mockReturnThis();provider={data:(...e)=>({execute:jest.fn().mockResolvedValue({body:{data:{itemCount:e.length,items:e}}})})};empty=(e={})=>e;a=this.empty;an=this.empty;date=(e=1621347575)=>{let s=new Date(e);return s.toString=l.return("Mon Jan 19 1970 19:22:27 GMT+0100 (Central European Standard Time)"),s.toLocaleDateString=l.return("19/01/1970"),s.toDateString=l.return("19/01/1970"),s};once=(...e)=>e.reduce((s,n)=>s.mockImplementationOnce(()=>n),jest.fn())},l=new T;0&&(module.exports={Fails,FailsWith,Match,MatchesExactJson,MatchesJson,Mocks,ObjectContainingJson,ObjectContainingText,ObjectContainingTextExact,Passes,PassesWith,check,checkDefined,fits,match,mock,toBeArrayOf,toBeArrayOfWithLength,toBeAt,toBeBadGateway,toBeBadRequest,toBeConflict,toBeCreated,toBeExactlyAt,toBeForbidden,toBeInternalServerError,toBeNotFound,toBeOk,toBeOkWithItems,toBeQueriedWith,toBeRoutedTo,toBeUnauthorized,toBeValid,toFail,toFailMatcher,toFailMatcherWith,toFailWith,toHaveNoContent,toHaveStatus,toMatchArray,toMatchExactJson,toMatchException,toMatchJson,toMatchRoute,toMatchText,toPassMatcher,toPassMatcherWith,toResultWith});
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ var a=t=>t!=null,m=t=>a(t)&&typeof t=="number"&&!Number.isNaN(t),R=t=>a(t)&&typeof t=="function",B=(t,...e)=>a(t)&&e.every(s=>a(t[s]));var U=t=>a(t)&&t instanceof Array,I=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&!U(t),d=t=>t?.toJSON?t.toJSON():I(t)?t:void 0,r=t=>t?.toString(),g=(t,e)=>{let s=parseInt(r(t));return m(s)?s:R(e)?e():m(e)?e:NaN},N=(...t)=>t.length>1?t:U(t[0])?t[0]:a(t[0])?[t[0]]:[];var c=(t,...e)=>r(R(t)?t(...e):t);var M=class t{constructor(e,s=!1,n=""){this.subject=e;this.failed=s;this.message=n}not(e,s){if(this.failed)return this;try{return new t(this.subject,!e(this.subject),c(s,this.subject))}catch(n){return new t(this.subject,!0,n.message)}}undefined(e,s){return this.not(()=>a(e(this.subject)),s)}else(e){return{pass:!this.failed,message:()=>this.failed?c(this.message):`${c(e,this.subject)}, which we did not expect.`}}},o=t=>new M(t);var i=(t,e)=>o(t).undefined(s=>s,"Response is unknown.").undefined(s=>s?.status?.id,()=>"Response does not have a status code").not(s=>s.status.id===e,s=>`Response does not have code '${e}', but has code '${s.status.id}' instead.`).else(`Response does have status code '${e}'.`),O=t=>i(t,200),D=t=>i(t,201),Y=t=>i(t,204),Q=t=>i(t,400),L=t=>i(t,401),H=t=>i(t,403),Z=t=>i(t,404),G=t=>i(t,409),z=t=>i(t,500),K=t=>i(t,502),X=(t,e)=>o(t).undefined(s=>s.status?.id,"Response did not have a status").not(s=>s.status.id===200,s=>`Response did not have status '200'. It had status '${s.status.id}' instead.`).undefined(s=>s?.body?.data?.items,"Response did not have any items.").not(s=>(s?.body?.data?.itemCount??0)>=e,s=>`Response did not have at least ${e} items. It only had ${s?.body?.data?.itemCount??0} items.`).else(`Response had status 200 and at least ${e} items`);expect.extend({toBeOk:O,toBeOkWithItems:X,toBeCreated:D,toHaveNoContent:Y,toBeNotFound:Z,toBeBadRequest:Q,toBeUnauthorized:L,toBeForbidden:H,toBeConflict:G,toBeInternalServerError:z,toHaveStatus:i,toBeBadGateway:K});var f=class t{constructor(e,s,n,h=!1,v=""){this.ctx=e;this.received=s;this.expected=n;this.failed=h;this.message=v}print(e){return(typeof e=="function"?e([this.received,this.expected]):e).replace("{r}",this.ctx.utils.printReceived(this.received)).replace("{e}",this.ctx.utils.printExpected(this.expected)).replace("{diff}",this.ctx.utils.diff(this.received,this.expected)??"")}not(e,s){if(this.failed)return this;try{return new t(this.ctx,this.received,this.expected,!e([this.received,this.expected]),this.print(s))}catch(n){return new t(this.ctx,this.received,this.expected,!0,n.message)}}undefined(e,s){return this.not(()=>a(e([this.received,this.expected])),this.print(s))}else(e="Expected {r} not to match with {e}, but it did."){return{pass:!this.failed,message:()=>this.failed?this.message:this.print(e)}}},Ne=(t,e,s)=>new f(t,e,s),q=(t,e,s)=>new f(t,e,s).undefined(([n])=>n,"Received array is undefined.").undefined(([,n])=>n,"Expected array is undefined.");var b="Results is not defined.",W="Results does not fail.",A=(t,e)=>t.results.some(s=>s.message===e),J=t=>"'"+t?.results.map(e=>e.message).join("', '")+"'",_=(t,e)=>o(t).undefined(s=>s,b).not(s=>A(s,e),s=>`Results does not have message '${e}', but it has messages ${J(s)} instead.`).else(`Succeeds with message ${e}`),ee=t=>o(t).undefined(e=>e,b).not(e=>!e.isValid,W).else("Results does not fail"),te=(t,e)=>o(t).undefined(s=>s,b).not(s=>!s.isValid,W).not(s=>A(s,e),s=>`Fails, but results does not have message '${e}', but it has messages ${J(s)} instead.`).else(`Fails with message '${e}'`);expect.extend({toResultWith:_,toFail:ee,toFailWith:te});var se=(t,e)=>o(t).undefined(s=>s,"Subject is undefined.").not(s=>s instanceof Array,"Subject is not an array.").not(s=>s.every(n=>n instanceof e),`Not all elements are of type '${e.name}'.`).else(`All elements in array are of type '${e.name}'`);expect.extend({toBeArrayOf:se});var ne=(t,e,s)=>o(t).undefined(n=>n,"Subject is undefined.").not(n=>n instanceof Array,"Subject is not an array.").not(n=>n.length===s,n=>`Subject does not have ${s} elements, but ${n.length}.`).not(n=>n.every(h=>h instanceof e),`Not all elements are of type '${e.name}'.`).else(`Subject has ${s} elements, which are all of type '${e.name}'`);expect.extend({toBeArrayOfWithLength:ne});var oe=(t,e,s)=>o(t).undefined(n=>n,"Tester is undefined").undefined(n=>n.url,"Tester does not contain a URL").undefined(()=>e,"Use case is undefined").not(n=>n.url.includes(`/${e?.app.id}`),n=>`We expected the tester to be at app '${e?.app.id}', but it is at '${n?.url}' instead.`).not(n=>n.url.includes(`/${e?.id}`),n=>`We expected the tester to be at use case '${e?.id}', but it is at '${n?.url}' instead.`).not(n=>n.url.includes(s?`/${s}`:""),n=>`We expected the path to contain '/42', but it is '${n?.url}' instead.`).else(n=>`The tester is at '${n?.url}'`);expect.extend({toBeAt:oe});var E=(t,e)=>{let s=a(e)?`/${e}`:"";return`/${t.app.id}/${t.id}${s}`},re=(t,e,s)=>o(t).undefined(n=>n,"Tester is undefined").undefined(n=>n.url,"Tester does not contain a URL").undefined(()=>e,"Use case is undefined").not(n=>n.url.includes(E(e,s)),n=>`We expected the tester to be at: '${E(e,s)}', but it is at: '${n?.url}' instead.`).else(n=>`The tester is at '${n?.url}'`);expect.extend({toBeExactlyAt:re});var j={Yes:"Match fails, instead of passes.",No:t=>`Match doesn't fail, because '${t}'`},V={Yes:"Match fails with correct message.",No:(t,e)=>`Match does fail, however not with message '${t}', but with message '${e}' instead.`},ae=t=>o(t).not(e=>!e.pass,e=>j.No(e.message())).else(j.Yes),ie=(t,e)=>o(t).not(s=>!s.pass,s=>j.No(s.message())).not(s=>s.message().includes(c(e)),s=>V.No(c(e),s.message())).else(V.Yes);expect.extend({toFailMatcher:ae,toFailMatcherWith:ie});var ce=t=>o(t).undefined(e=>e,"Subject is undefined.").not(e=>B(e,"isValid"),"Subject is not validatable.").not(e=>e.isValid,"Subject is not valid.").else("Subject is valid");expect.extend({toBeValid:ce});function ue(t,e){return q(this,t,e).not(([s,n])=>s.length===n.length,([s,n])=>`Received array has length ${s.length}, while expected array has length ${n.length}.`).not(([s,n])=>s.every((h,v)=>this.equals(h,n[v])),`Elements in {r} do not match elements in {e}.
2
+
3
+ {diff}.`).else()}expect.extend({toMatchArray:ue});import{equals as P,iterableEquality as de,subsetEquality as pe}from"@jest/expect-utils";var p={exact:(t,e)=>P(t,e,[]),subset:(t,e)=>P(t,e,[de,pe]),string:(t,e)=>r(t)===r(e)};var x={SubjectUndefined:"Subject is undefined.",SubsetUndefined:"Object to match with is undefined.",DoesNotMatch:"Object does not exactly match subject.",Yes:"Object matches subject exactly"},le=(t,e)=>o(t).undefined(s=>s,x.SubjectUndefined).undefined(()=>e,x.SubsetUndefined).not(s=>p.exact(s,e),x.DoesNotMatch).else(()=>x.Yes);expect.extend({toMatchExactJson:le});var me=(t,e,s)=>o(e).undefined(n=>n.id,"Expected value is not an exception.").not(n=>n.id===t.id,n=>`Expected exception has id '${n.id}', while the received exception has id '${t.id}'.`).not(()=>!a(s)||a(s)&&a(t.reason),()=>`We expected to have reason '${s}', but we received no reason.`).not(()=>!a(s)||a(s)&&t.reason===s,()=>`We expected to have reason '${s}', but we received reason '${t.reason}'.`).else("Expected exception matches received exception");expect.extend({toMatchException:me});var y={SubjectUndefined:"Subject is undefined.",SubsetUndefined:"Subset to match with is undefined.",DoesNotMatch:"Subset does not match subject.",Yes:"Subset matches subject"},he=(t,e)=>o(t).undefined(s=>s,y.SubjectUndefined).undefined(()=>e,y.SubsetUndefined).not(s=>p.subset(d(s),d(e)),y.DoesNotMatch).else(()=>y.Yes);expect.extend({toMatchJson:he});var fe=(t,e)=>o(t).undefined(s=>s,"Subject is undefined.").undefined(()=>e,"Route to include is undefined.").not(s=>r(s).includes(r(e)),s=>`Uri '${s}' does not include '${e}'.`).else(s=>`Uri '${s}' includes '${e}'`);expect.extend({toMatchRoute:fe});var xe=(t,e)=>o(t).undefined(s=>s,"Subject is undefined.").undefined(()=>e,"Text to match with is undefined.").not(s=>r(s)===r(e),s=>`Text '${s}' does not match with text '${e}'.`).else(s=>`Text '${s}' matches`);expect.extend({toMatchText:xe});var S={Yes:"Match passes, instead of fails.",No:t=>`Match doesn't pass, because '${t}'`},F={Yes:"Match passes with correct message.",No:(t,e)=>`Match does pass, however not with message '${t}', but with message '${e}' instead.`},ye=t=>o(t).not(e=>e.pass,e=>S.No(e.message())).else(S.Yes),Re=(t,e)=>o(t).not(s=>s.pass,s=>S.No(s.message())).not(s=>s.message().includes(c(e)),s=>F.No(c(e),s.message())).else(F.Yes);expect.extend({toPassMatcher:ye,toPassMatcherWith:Re});var ge=(t,e)=>o(t?.mock?.calls).undefined(s=>s,"Query is unknown.").not(s=>s.length===1,"Query did not execute.").not(s=>s[0][0].toString()===e?.toString(),s=>`We expected query '${e}', but we received query '${s[0][0]}' instead.`).else(`Received query does match '${e}'`);expect.extend({toBeQueriedWith:ge});var Me=(t,e)=>o(t?.mock?.calls).undefined(s=>s,"Uri is unknown.").not(s=>s.length===1,"Method was not called.").not(s=>r(s[0][0])===r(e),s=>`We expected uri '${r(e)}', but we received uri '${r(s[0][0])}' instead.`).else(`Called uri does match '${r(e)}'`);expect.extend({toBeRoutedTo:Me});import{AsymmetricMatcher as C}from"expect";var w=class extends C{asymmetricMatch(e){return r(e).includes(r(this.sample))}toString(){return`String${this.inverse?"Not":""}Containing`}},k=class extends C{asymmetricMatch(e){return r(e)===r(this.sample)}toString(){return`String${this.inverse?"Not":""}Containing`}},T=class extends C{asymmetricMatch(e){return p.subset(d(e),d(this.sample))}toString(){return`Object${this.inverse?"Not":""}Containing`}},be={any:()=>expect.anything(),type:t=>expect.any(t),with:t=>expect.objectContaining(t),text:t=>new w(t),textExact:t=>new k(t),uri:t=>be.textExact(t),json:t=>new T(t),items:(...t)=>expect.arrayContaining(N(...t))};var u=class{constructor(e={}){this.state=e}get id(){return this.state.id??this.path.id}get q(){return this.state.q??this.query.q}get path(){return this.state?.path??{}}get query(){return this.state?.query??{}}get skip(){return m(this.query?.skip)?g(this.query?.skip):void 0}get take(){return m(this.query?.take)?g(this.query?.take):void 0}get body(){return this.state.body}get headers(){return this.state.headers}get=e=>this?.state[e.toString()]??this.path[e.toString()]??this.query[e.toString()]};var $=class{clear=()=>jest.clearAllMocks();impl=e=>jest.fn().mockImplementation(e);property=(e,s,n)=>jest.spyOn(e,s,"get").mockReturnValue(n);reject=e=>jest.fn().mockRejectedValue(e);rejectWith=(e={})=>jest.fn().mockRejectedValue(l.a(e));req={id:e=>new u({id:e}),q:e=>new u({q:e}),with:e=>new u(e),body:e=>new u({body:e}),path:e=>new u({path:e}),query:e=>new u({query:e})};resp={items:(e,s=[])=>({status:e,body:{data:{code:e.id,itemCount:s.length,items:s}}}),errors:(e,s,n=[])=>({status:e,body:{error:{code:e.id,message:s,errorCount:n.length,errors:n}}})};resolve=e=>jest.fn().mockResolvedValue(e);resolveWith=(e={})=>jest.fn().mockResolvedValue(l.a(e));return=e=>jest.fn().mockReturnValue(e);returnWith=(e={})=>jest.fn().mockReturnValue(l.a(e));this=()=>jest.fn().mockReturnThis();provider={data:(...e)=>({execute:jest.fn().mockResolvedValue({body:{data:{itemCount:e.length,items:e}}})})};empty=(e={})=>e;a=this.empty;an=this.empty;date=(e=1621347575)=>{let s=new Date(e);return s.toString=l.return("Mon Jan 19 1970 19:22:27 GMT+0100 (Central European Standard Time)"),s.toLocaleDateString=l.return("19/01/1970"),s.toDateString=l.return("19/01/1970"),s};once=(...e)=>e.reduce((s,n)=>s.mockImplementationOnce(()=>n),jest.fn())},l=new $;export{j as Fails,V as FailsWith,M as Match,x as MatchesExactJson,y as MatchesJson,$ as Mocks,T as ObjectContainingJson,w as ObjectContainingText,k as ObjectContainingTextExact,S as Passes,F as PassesWith,Ne as check,q as checkDefined,be as fits,o as match,l as mock,se as toBeArrayOf,ne as toBeArrayOfWithLength,oe as toBeAt,K as toBeBadGateway,Q as toBeBadRequest,G as toBeConflict,D as toBeCreated,re as toBeExactlyAt,H as toBeForbidden,z as toBeInternalServerError,Z as toBeNotFound,O as toBeOk,X as toBeOkWithItems,ge as toBeQueriedWith,Me as toBeRoutedTo,L as toBeUnauthorized,ce as toBeValid,ee as toFail,ae as toFailMatcher,ie as toFailMatcherWith,te as toFailWith,Y as toHaveNoContent,i as toHaveStatus,ue as toMatchArray,le as toMatchExactJson,me as toMatchException,he as toMatchJson,fe as toMatchRoute,xe as toMatchText,ye as toPassMatcher,Re as toPassMatcherWith,_ as toResultWith};
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@thisisagile/easy-test",
3
- "version": "15.8.3",
3
+ "version": "15.8.5",
4
4
  "description": "Straightforward library for testing microservices built with @thisisagile/easy",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
+ "module": "dist/index.mjs",
8
9
  "types": "dist/index",
9
10
  "repository": {
10
11
  "type": "git",
@@ -22,6 +23,7 @@
22
23
  "lint": "yarn g:eslint . --ext .js,.jsx,.ts,.tsx --fix",
23
24
  "format": "yarn g:prettier --check --write src test *.json",
24
25
  "build": "yarn g:tsc",
26
+ "build:tsup": "yarn g:tsup",
25
27
  "test": "yarn g:jest --coverage",
26
28
  "prepack": "yarn g:copy-readme"
27
29
  },
@@ -1,21 +1,24 @@
1
- import { isDefined } from "../utils/Utils";
2
- import CustomMatcherResult = jest.CustomMatcherResult;
3
-
1
+ import { isDefined } from '../utils/Utils';
4
2
 
5
3
  type ToMessage<S> = string | ((s: S[]) => string);
6
4
 
7
5
  class Check<S> {
8
- constructor(private ctx: jest.MatcherContext, private readonly received: S, private readonly expected: S, private readonly failed = false, private readonly message = "") {
9
- }
6
+ constructor(
7
+ private ctx: jest.MatcherContext,
8
+ private readonly received: S,
9
+ private readonly expected: S,
10
+ private readonly failed = false,
11
+ private readonly message = ''
12
+ ) {}
10
13
 
11
14
  print(message: ToMessage<S>): string {
12
- return (typeof message === "function" ? message([this.received, this.expected]) : message)
13
- .replace("{r}", this.ctx.utils.printReceived(this.received))
14
- .replace("{e}", this.ctx.utils.printExpected(this.expected))
15
- .replace("{diff}", this.ctx.utils.diff(this.received, this.expected) ?? "");
15
+ return (typeof message === 'function' ? message([this.received, this.expected]) : message)
16
+ .replace('{r}', this.ctx.utils.printReceived(this.received))
17
+ .replace('{e}', this.ctx.utils.printExpected(this.expected))
18
+ .replace('{diff}', this.ctx.utils.diff(this.received, this.expected) ?? '');
16
19
  }
17
20
 
18
- not(p: (s: (S)[]) => boolean, message: ToMessage<S>): Check<S> {
21
+ not(p: (s: S[]) => boolean, message: ToMessage<S>): Check<S> {
19
22
  if (this.failed) {
20
23
  return this;
21
24
  }
@@ -26,22 +29,19 @@ class Check<S> {
26
29
  }
27
30
  }
28
31
 
29
- undefined(p: (s: (S)[]) => any, message: ToMessage<S>): Check<S> {
32
+ undefined(p: (s: S[]) => any, message: ToMessage<S>): Check<S> {
30
33
  return this.not(() => isDefined(p([this.received, this.expected])), this.print(message));
31
34
  }
32
35
 
33
- else(message: ToMessage<S> = "Expected {r} not to match with {e}, but it did."): CustomMatcherResult {
36
+ else(message: ToMessage<S> = 'Expected {r} not to match with {e}, but it did.'): jest.CustomMatcherResult {
34
37
  return {
35
38
  pass: !this.failed,
36
- message: () => (this.failed ? this.message : this.print(message))
39
+ message: () => (this.failed ? this.message : this.print(message)),
37
40
  };
38
41
  }
39
42
  }
40
43
 
41
44
  export const check = <S>(ctx: jest.MatcherContext, received: S, expected?: S): Check<S> => new Check<S>(ctx, received, expected as S);
42
45
 
43
- export const checkDefined = <S>(ctx: jest.MatcherContext, received: S, expected?: S): Check<S> => new Check<S>(ctx, received, expected as S)
44
- .undefined(([r]) => r, "Received array is undefined.")
45
- .undefined(([, e]) => e, "Expected array is undefined.")
46
- ;
47
-
46
+ export const checkDefined = <S>(ctx: jest.MatcherContext, received: S, expected?: S): Check<S> =>
47
+ new Check<S>(ctx, received, expected as S).undefined(([r]) => r, 'Received array is undefined.').undefined(([, e]) => e, 'Expected array is undefined.');
@@ -1,8 +1,7 @@
1
- import CustomMatcherResult = jest.CustomMatcherResult;
2
1
  import { Response } from '../utils/Response';
3
2
  import { match } from './Match';
4
3
 
5
- export const toHaveStatus = (res: Response, code: number): CustomMatcherResult =>
4
+ export const toHaveStatus = (res: Response, code: number): jest.CustomMatcherResult =>
6
5
  match<Response>(res)
7
6
  .undefined(r => r, 'Response is unknown.')
8
7
  .undefined(
@@ -15,27 +14,27 @@ export const toHaveStatus = (res: Response, code: number): CustomMatcherResult =
15
14
  )
16
15
  .else(`Response does have status code '${code}'.`);
17
16
 
18
- export const toBeOk = (res: Response): CustomMatcherResult => toHaveStatus(res, 200);
17
+ export const toBeOk = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 200);
19
18
 
20
- export const toBeCreated = (res: Response): CustomMatcherResult => toHaveStatus(res, 201);
19
+ export const toBeCreated = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 201);
21
20
 
22
- export const toHaveNoContent = (res: Response): CustomMatcherResult => toHaveStatus(res, 204);
21
+ export const toHaveNoContent = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 204);
23
22
 
24
- export const toBeBadRequest = (res: Response): CustomMatcherResult => toHaveStatus(res, 400);
23
+ export const toBeBadRequest = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 400);
25
24
 
26
- export const toBeUnauthorized = (res: Response): CustomMatcherResult => toHaveStatus(res, 401);
25
+ export const toBeUnauthorized = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 401);
27
26
 
28
- export const toBeForbidden = (res: Response): CustomMatcherResult => toHaveStatus(res, 403);
27
+ export const toBeForbidden = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 403);
29
28
 
30
- export const toBeNotFound = (res: Response): CustomMatcherResult => toHaveStatus(res, 404);
29
+ export const toBeNotFound = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 404);
31
30
 
32
- export const toBeConflict = (res: Response): CustomMatcherResult => toHaveStatus(res, 409);
31
+ export const toBeConflict = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 409);
33
32
 
34
- export const toBeInternalServerError = (res: Response): CustomMatcherResult => toHaveStatus(res, 500);
33
+ export const toBeInternalServerError = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 500);
35
34
 
36
- export const toBeBadGateway = (res: Response): CustomMatcherResult => toHaveStatus(res, 502);
35
+ export const toBeBadGateway = (res: Response): jest.CustomMatcherResult => toHaveStatus(res, 502);
37
36
 
38
- export const toBeOkWithItems = (res: Response, length: number): CustomMatcherResult =>
37
+ export const toBeOkWithItems = (res: Response, length: number): jest.CustomMatcherResult =>
39
38
  match<Response>(res)
40
39
  .undefined(r => r.status?.id, 'Response did not have a status')
41
40
  .not(
@@ -1,6 +1,5 @@
1
1
  import { isDefined } from '../utils/Utils';
2
2
  import { Message, toMessage } from '../utils/Types';
3
- import CustomMatcherResult = jest.CustomMatcherResult;
4
3
 
5
4
  export class Match<S> {
6
5
  constructor(private readonly subject: S, private readonly failed = false, private readonly message: Message<S> = '') {}
@@ -21,7 +20,7 @@ export class Match<S> {
21
20
  return this.not(() => isDefined(p(this.subject)), message);
22
21
  }
23
22
 
24
- else(message: Message<S>): CustomMatcherResult {
23
+ else(message: Message<S>): jest.CustomMatcherResult {
25
24
  return {
26
25
  pass: !this.failed,
27
26
  message: () => (this.failed ? toMessage(this.message) : `${toMessage(message, this.subject)}, which we did not expect.`),
@@ -1,4 +1,3 @@
1
- import CustomMatcherResult = jest.CustomMatcherResult;
2
1
  import { match } from './Match';
3
2
  import { Results } from '../utils/Types';
4
3
 
@@ -11,7 +10,7 @@ const hasMessage = (res: Results, message: string) => res.results.some((r: any)
11
10
 
12
11
  const messages = (res: Results): string => "'" + res?.results.map(r => r.message).join("', '") + "'";
13
12
 
14
- export const toResultWith = (results: Results, message: string): CustomMatcherResult =>
13
+ export const toResultWith = (results: Results, message: string): jest.CustomMatcherResult =>
15
14
  match(results)
16
15
  .undefined(r => r, notDefined)
17
16
  .not(
@@ -20,13 +19,13 @@ export const toResultWith = (results: Results, message: string): CustomMatcherRe
20
19
  )
21
20
  .else(`Succeeds with message ${message}`);
22
21
 
23
- export const toFail = (results: Results): CustomMatcherResult =>
22
+ export const toFail = (results: Results): jest.CustomMatcherResult =>
24
23
  match(results)
25
24
  .undefined(r => r, notDefined)
26
25
  .not(r => !r.isValid, doesNotFail)
27
26
  .else('Results does not fail');
28
27
 
29
- export const toFailWith = (results: Results, message: string): CustomMatcherResult =>
28
+ export const toFailWith = (results: Results, message: string): jest.CustomMatcherResult =>
30
29
  match(results)
31
30
  .undefined(r => r, notDefined)
32
31
  .not(r => !r.isValid, doesNotFail)
@@ -1,8 +1,7 @@
1
- import CustomMatcherResult = jest.CustomMatcherResult;
2
1
  import { Constructor as Ctor } from '../utils/Types';
3
2
  import { match } from './Match';
4
3
 
5
- export const toBeArrayOf = <T>(items: unknown, ctor: Ctor<T>): CustomMatcherResult =>
4
+ export const toBeArrayOf = <T>(items: unknown, ctor: Ctor<T>): jest.CustomMatcherResult =>
6
5
  match<unknown>(items)
7
6
  .undefined(it => it, 'Subject is undefined.')
8
7
  .not(it => it instanceof Array, 'Subject is not an array.')