@neurodevs/node-tdd 1.0.5 → 1.0.7

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 (179) hide show
  1. package/package.json +1 -1
  2. package/.nvmrc +0 -1
  3. package/.vscode/launch.json +0 -53
  4. package/.vscode/settings.json +0 -62
  5. package/.vscode/tasks.json +0 -99
  6. package/build/__tests__/MockFetch.d.ts +0 -18
  7. package/build/__tests__/MockFetch.js +0 -55
  8. package/build/__tests__/MockFetch.js.map +0 -1
  9. package/build/__tests__/behavioral/AbstractModuleTest.test.d.ts +0 -5
  10. package/build/__tests__/behavioral/AbstractModuleTest.test.js +0 -22
  11. package/build/__tests__/behavioral/AbstractModuleTest.test.js.map +0 -1
  12. package/build/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.d.ts +0 -5
  13. package/build/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.js +0 -34
  14. package/build/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.js.map +0 -1
  15. package/build/__tests__/behavioral/utilities/Assert.test.d.ts +0 -45
  16. package/build/__tests__/behavioral/utilities/Assert.test.js +0 -645
  17. package/build/__tests__/behavioral/utilities/Assert.test.js.map +0 -1
  18. package/build/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.d.ts +0 -4
  19. package/build/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.js +0 -23
  20. package/build/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.js.map +0 -1
  21. package/build/__tests__/behavioral/utilities/MockFetch.test.d.ts +0 -28
  22. package/build/__tests__/behavioral/utilities/MockFetch.test.js +0 -211
  23. package/build/__tests__/behavioral/utilities/MockFetch.test.js.map +0 -1
  24. package/build/__tests__/behavioral/utilities/StackCleaner.test.d.ts +0 -4
  25. package/build/__tests__/behavioral/utilities/StackCleaner.test.js +0 -46
  26. package/build/__tests__/behavioral/utilities/StackCleaner.test.js.map +0 -1
  27. package/build/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.d.ts +0 -7
  28. package/build/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.js +0 -32
  29. package/build/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.js.map +0 -1
  30. package/build/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.d.ts +0 -4
  31. package/build/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.js +0 -19
  32. package/build/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.js.map +0 -1
  33. package/build/__tests__/behavioral/utilities/Stringify.test.d.ts +0 -5
  34. package/build/__tests__/behavioral/utilities/Stringify.test.js +0 -127
  35. package/build/__tests__/behavioral/utilities/Stringify.test.js.map +0 -1
  36. package/build/__tests__/behavioral/utilities/TestDecoratorResolver.test.d.ts +0 -7
  37. package/build/__tests__/behavioral/utilities/TestDecoratorResolver.test.js +0 -38
  38. package/build/__tests__/behavioral/utilities/TestDecoratorResolver.test.js.map +0 -1
  39. package/build/__tests__/behavioral/utilities/TestOnBasic.test.d.ts +0 -12
  40. package/build/__tests__/behavioral/utilities/TestOnBasic.test.js +0 -68
  41. package/build/__tests__/behavioral/utilities/TestOnBasic.test.js.map +0 -1
  42. package/build/__tests__/behavioral/utilities/TestOnInstance.test.d.ts +0 -28
  43. package/build/__tests__/behavioral/utilities/TestOnInstance.test.js +0 -289
  44. package/build/__tests__/behavioral/utilities/TestOnInstance.test.js.map +0 -1
  45. package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.d.ts +0 -9
  46. package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.js +0 -118
  47. package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.js.map +0 -1
  48. package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.d.ts +0 -5
  49. package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.js +0 -78
  50. package/build/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.js.map +0 -1
  51. package/build/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.d.ts +0 -4
  52. package/build/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.js +0 -23
  53. package/build/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.js.map +0 -1
  54. package/build/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.d.ts +0 -4
  55. package/build/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.js +0 -24
  56. package/build/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.js.map +0 -1
  57. package/build/__tests__/behavioral/utilities/TestResolver.test.d.ts +0 -7
  58. package/build/__tests__/behavioral/utilities/TestResolver.test.js +0 -38
  59. package/build/__tests__/behavioral/utilities/TestResolver.test.js.map +0 -1
  60. package/build/__tests__/behavioral/utilities/TestResolverOnStatic.test.d.ts +0 -4
  61. package/build/__tests__/behavioral/utilities/TestResolverOnStatic.test.js +0 -20
  62. package/build/__tests__/behavioral/utilities/TestResolverOnStatic.test.js.map +0 -1
  63. package/build/__tests__/behavioral/workspace/JestJsonParser.test.d.ts +0 -18
  64. package/build/__tests__/behavioral/workspace/JestJsonParser.test.js +0 -267
  65. package/build/__tests__/behavioral/workspace/JestJsonParser.test.js.map +0 -1
  66. package/build/__tests__/behavioral/workspace/TestReporter.test.d.ts +0 -27
  67. package/build/__tests__/behavioral/workspace/TestReporter.test.js +0 -508
  68. package/build/__tests__/behavioral/workspace/TestReporter.test.js.map +0 -1
  69. package/build/__tests__/behavioral/workspace/TestRunner.test.d.ts +0 -15
  70. package/build/__tests__/behavioral/workspace/TestRunner.test.js +0 -99
  71. package/build/__tests__/behavioral/workspace/TestRunner.test.js.map +0 -1
  72. package/build/__tests__/behavioral/workspace/Widgets.test.d.ts +0 -16
  73. package/build/__tests__/behavioral/workspace/Widgets.test.js +0 -134
  74. package/build/__tests__/behavioral/workspace/Widgets.test.js.map +0 -1
  75. package/build/__tests__/mock-terminal-kit.d.ts +0 -79
  76. package/build/__tests__/mock-terminal-kit.js +0 -103
  77. package/build/__tests__/mock-terminal-kit.js.map +0 -1
  78. package/build/__tests__/support/AbstractForInstanceTest.d.ts +0 -4
  79. package/build/__tests__/support/AbstractForInstanceTest.js +0 -9
  80. package/build/__tests__/support/AbstractForInstanceTest.js.map +0 -1
  81. package/build/__tests__/support/AbstractLevelOneTest.d.ts +0 -3
  82. package/build/__tests__/support/AbstractLevelOneTest.js +0 -4
  83. package/build/__tests__/support/AbstractLevelOneTest.js.map +0 -1
  84. package/build/__tests__/support/AbstractLevelTwoTest.d.ts +0 -7
  85. package/build/__tests__/support/AbstractLevelTwoTest.js +0 -14
  86. package/build/__tests__/support/AbstractLevelTwoTest.js.map +0 -1
  87. package/build/__tests__/support/AbstractStaticTest.d.ts +0 -7
  88. package/build/__tests__/support/AbstractStaticTest.js +0 -14
  89. package/build/__tests__/support/AbstractStaticTest.js.map +0 -1
  90. package/build/__tests__/support/AbstractTestOnInstanceTest.d.ts +0 -22
  91. package/build/__tests__/support/AbstractTestOnInstanceTest.js +0 -23
  92. package/build/__tests__/support/AbstractTestOnInstanceTest.js.map +0 -1
  93. package/build/__tests__/support/AbstractTestOnInstanceWithHooks.d.ts +0 -26
  94. package/build/__tests__/support/AbstractTestOnInstanceWithHooks.js +0 -59
  95. package/build/__tests__/support/AbstractTestOnInstanceWithHooks.js.map +0 -1
  96. package/build/__tests__/support/jest.setup.d.ts +0 -1
  97. package/build/__tests__/support/jest.setup.js +0 -4
  98. package/build/__tests__/support/jest.setup.js.map +0 -1
  99. package/build/__tests__/support/onTestFileResult.d.ts +0 -244
  100. package/build/__tests__/support/onTestFileResult.js +0 -980
  101. package/build/__tests__/support/onTestFileResult.js.map +0 -1
  102. package/eslint.config.js +0 -3
  103. package/prettier.config.js +0 -3
  104. package/src/.spruce/settings.json +0 -4
  105. package/src/__tests__/MockFetch.ts +0 -100
  106. package/src/__tests__/behavioral/AbstractModuleTest.test.ts +0 -15
  107. package/src/__tests__/behavioral/utilities/AllHooksCalledEvenIfNotDefined.test.ts +0 -31
  108. package/src/__tests__/behavioral/utilities/Assert.test.ts +0 -826
  109. package/src/__tests__/behavioral/utilities/InstanceParentTestCanAccessParentMethods.test.ts +0 -14
  110. package/src/__tests__/behavioral/utilities/MockFetch.test.ts +0 -240
  111. package/src/__tests__/behavioral/utilities/StackCleaner.test.ts +0 -46
  112. package/src/__tests__/behavioral/utilities/StaticParentTestCanAccessParentMethods.test.ts +0 -34
  113. package/src/__tests__/behavioral/utilities/StaticTestInheritsAbstractSpruceTestProperly.test.ts +0 -11
  114. package/src/__tests__/behavioral/utilities/Stringify.test.ts +0 -169
  115. package/src/__tests__/behavioral/utilities/TestDecoratorResolver.test.ts +0 -51
  116. package/src/__tests__/behavioral/utilities/TestOnBasic.test.ts +0 -62
  117. package/src/__tests__/behavioral/utilities/TestOnInstance.test.ts +0 -439
  118. package/src/__tests__/behavioral/utilities/TestOnInstanceExtendsTest.test.ts +0 -237
  119. package/src/__tests__/behavioral/utilities/TestOnInstanceExtendsTestWithHooks.test.ts +0 -85
  120. package/src/__tests__/behavioral/utilities/TestOnInstanceWithParentBeforeAll.test.ts +0 -14
  121. package/src/__tests__/behavioral/utilities/TestOnInstanceWithTwoLevelsOfInheritence.test.ts +0 -16
  122. package/src/__tests__/behavioral/utilities/TestResolver.test.ts +0 -48
  123. package/src/__tests__/behavioral/utilities/TestResolverOnStatic.test.ts +0 -12
  124. package/src/__tests__/behavioral/workspace/JestJsonParser.test.ts +0 -357
  125. package/src/__tests__/behavioral/workspace/TestReporter.test.ts +0 -584
  126. package/src/__tests__/behavioral/workspace/TestRunner.test.ts +0 -87
  127. package/src/__tests__/behavioral/workspace/Widgets.test.ts +0 -131
  128. package/src/__tests__/mock-terminal-kit.ts +0 -115
  129. package/src/__tests__/support/AbstractForInstanceTest.ts +0 -12
  130. package/src/__tests__/support/AbstractLevelOneTest.ts +0 -3
  131. package/src/__tests__/support/AbstractLevelTwoTest.ts +0 -16
  132. package/src/__tests__/support/AbstractStaticTest.ts +0 -16
  133. package/src/__tests__/support/AbstractTestOnInstanceTest.ts +0 -30
  134. package/src/__tests__/support/AbstractTestOnInstanceWithHooks.ts +0 -138
  135. package/src/__tests__/support/jest.setup.ts +0 -2
  136. package/src/__tests__/support/onTestFileResult.ts +0 -1008
  137. package/src/impl/AbstractModuleTest.ts +0 -67
  138. package/src/index.ts +0 -12
  139. package/src/utilities/AssertionError.ts +0 -14
  140. package/src/utilities/StackCleaner.ts +0 -14
  141. package/src/utilities/TestDecoratorResolver.ts +0 -118
  142. package/src/utilities/assert.ts +0 -583
  143. package/src/utilities/assert.utility.ts +0 -295
  144. package/src/utilities/decorators.ts +0 -167
  145. package/src/workspace/CommandService.ts +0 -256
  146. package/src/workspace/JestJsonParser.ts +0 -255
  147. package/src/workspace/TKButtonWidget.ts +0 -54
  148. package/src/workspace/TestLogItemGenerator.ts +0 -184
  149. package/src/workspace/TestReporter.ts +0 -880
  150. package/src/workspace/TestRunner.ts +0 -128
  151. package/src/workspace/TkBaseWidget.ts +0 -249
  152. package/src/workspace/TkInputWidget.ts +0 -83
  153. package/src/workspace/TkLayoutCellWidget.ts +0 -46
  154. package/src/workspace/TkLayoutWidget.ts +0 -181
  155. package/src/workspace/TkMenuBarWidget.ts +0 -95
  156. package/src/workspace/TkPopupWidget.ts +0 -47
  157. package/src/workspace/TkProgressBarWidget.ts +0 -54
  158. package/src/workspace/TkTextWidget.ts +0 -167
  159. package/src/workspace/TkWindowWidget.ts +0 -122
  160. package/src/workspace/WidgetFactory.ts +0 -33
  161. package/src/workspace/button.types.ts +0 -19
  162. package/src/workspace/duration.utility.ts +0 -34
  163. package/src/workspace/factory.types.ts +0 -101
  164. package/src/workspace/input.types.ts +0 -22
  165. package/src/workspace/keySelectChoices.ts +0 -134
  166. package/src/workspace/layout.types.ts +0 -40
  167. package/src/workspace/menuBar.types.ts +0 -24
  168. package/src/workspace/popup.types.ts +0 -17
  169. package/src/workspace/progressBar.types.ts +0 -13
  170. package/src/workspace/table.types.ts +0 -9
  171. package/src/workspace/termKit.utility.ts +0 -130
  172. package/src/workspace/terminal-kit.d.ts +0 -28
  173. package/src/workspace/test.types.ts +0 -34
  174. package/src/workspace/testRunner.cli.ts +0 -166
  175. package/src/workspace/text.types.ts +0 -27
  176. package/src/workspace/widget.utilities.ts +0 -35
  177. package/src/workspace/widgets.types.ts +0 -102
  178. package/src/workspace/window.types.ts +0 -22
  179. package/tsconfig.json +0 -24
@@ -1,583 +0,0 @@
1
- import chalk from 'chalk'
2
- import deepEqual from 'deep-equal'
3
- import { printDiffOrStringify } from 'jest-matcher-utils'
4
- import { escapeRegExp, isObjectLike, cloneDeep, set } from 'lodash-es'
5
- import { expectType } from 'ts-expect'
6
- import diff from 'variable-diff'
7
- import assertUtil from './assert.utility.js'
8
- export * from './assert.utility.js'
9
-
10
- const stringify = assertUtil.stringify.bind(assertUtil)
11
-
12
- export type RecursivePartial<T> = {
13
- [P in keyof T]?: T[P] extends (infer U)[]
14
- ? RecursivePartial<U>[]
15
- : T[P] extends object
16
- ? RecursivePartial<T[P]>
17
- : T[P]
18
- }
19
-
20
- type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
21
- type IsAny<T> = IfAny<T, true, never>
22
-
23
- type TypeEqual<T, U> =
24
- IsAny<T> extends never
25
- ? Exclude<T, U> extends never
26
- ? Exclude<U, T> extends never
27
- ? true
28
- : false
29
- : false
30
- : false
31
-
32
- export function isExactType<T, E, Pass = TypeEqual<T, E>>(_: Pass) {}
33
-
34
- export interface Assert {
35
- isInstanceOf<T>(
36
- test: T,
37
- Test: new (...props: any[]) => T,
38
- message?: string
39
- ): void
40
- isNumber(actual: any, message?: string): asserts actual is number
41
- isType: typeof expectType
42
- isExactType: typeof isExactType
43
- isArray<T extends any[]>(actual: any, message?: string): asserts actual is T
44
- areSameType<T>(actual: T, expected: T): asserts actual is T
45
- isEqual<T>(actual: T, expected: T, message?: string): asserts actual is T
46
- isNotEqual<T>(actual: T, expected: T, message?: string): asserts actual is T
47
- isEqualDeep<T>(
48
- actual: T,
49
- expected: T,
50
- message?: string,
51
- shouldAppendDelta?: boolean
52
- ): asserts actual is T
53
- isNotEqualDeep<T>(actual: T, expected: T, message?: string): void
54
- isAbove<T>(actual: T, floor: T, message?: string): void
55
- isBelow<T>(actual: T, ceiling: T, message?: string): void
56
- isUndefined<T>(actual: T, message?: string): void
57
- isTruthy<T = any>(
58
- value: T,
59
- message?: string
60
- ): asserts value is NonNullable<T>
61
- isFalsy(value: any, message?: string): void
62
- isTrue(
63
- actual: boolean | undefined | null,
64
- message?: string
65
- ): asserts actual is true
66
- isFalse(
67
- actual: boolean | undefined | null,
68
- message?: string
69
- ): asserts actual is false
70
- isObject<T>(actual: T, message?: string): void
71
- isLength(
72
- actual: any[] | undefined | null,
73
- expected: number,
74
- message?: string
75
- ): void
76
- isNull(actual: any, message?: string): void
77
- doesNotInclude<T>(
78
- haystack: T,
79
- needle: RecursivePartial<T>,
80
- message?: string
81
- ): void
82
-
83
- doesNotInclude(haystack: string, needle: string, message?: string): void
84
- doesNotInclude(haystack: any, needle: string, message?: string): void
85
- doesNotInclude(haystack: any, needle: any, message?: string): void
86
-
87
- doesInclude<T>(
88
- haystack: T,
89
- needle: RecursivePartial<T>,
90
- message?: string
91
- ): void
92
-
93
- doesInclude(haystack: string, needle: string, message?: string): void
94
- doesInclude(haystack: any, needle: string, message?: string): void
95
- doesInclude(haystack: any, needle: any, message?: string): void
96
-
97
- isString(actual: any, message?: string): asserts actual is string
98
-
99
- isFunction(actual: any, message?: string): asserts actual is Function
100
- hasAllFunctions(obj: any, functionNames: string[]): void
101
- doesThrow(
102
- cb: () => any,
103
- matcher?: string | RegExp | undefined,
104
- msg?: string | undefined
105
- ): Error
106
- doesThrowAsync(
107
- cb: () => any | Promise<any>,
108
- matcher?: string | RegExp | undefined,
109
- msg?: string | undefined
110
- ): Promise<Error>
111
- fail(message?: string): void
112
- isBetween(
113
- actual: any,
114
- floor: number,
115
- ceiling: number,
116
- message?: string
117
- ): asserts actual is number
118
-
119
- isBetweenInclusive(
120
- actual: any,
121
- floor: number,
122
- ceiling: number,
123
- message?: string
124
- ): asserts actual is number
125
- }
126
-
127
- const assert: Assert = {
128
- areSameType() {},
129
-
130
- isType: expectType,
131
-
132
- isExactType,
133
-
134
- isNumber(actual, message) {
135
- if (typeof actual !== 'number') {
136
- this.fail(
137
- buildErrorMessage(
138
- `${stringify(actual)} is not a number!`,
139
- message
140
- )
141
- )
142
- }
143
- },
144
-
145
- isEqual(actual, expected, message) {
146
- if (actual !== expected) {
147
- const diff = printDiffOrStringify(
148
- expected,
149
- actual,
150
- 'Expected',
151
- 'Actual',
152
- false
153
- )
154
- this.fail(buildErrorMessage(`${diff}`, message))
155
- }
156
- },
157
-
158
- isNotEqual(actual, expected, message) {
159
- if (actual === expected) {
160
- this.fail(
161
- buildErrorMessage(
162
- `${stringify(actual)}\n\n should not equal ${stringify(expected)}\n\n`,
163
- message
164
- )
165
- )
166
- }
167
- },
168
-
169
- isEqualDeep(actual, expected, message, shouldAppendDelta = true) {
170
- if (!deepEqual(actual, expected, { strict: true })) {
171
- let result = diff(actual, expected)
172
- this.fail(
173
- buildErrorMessage(
174
- `${`Deep equal failed.\n\nActual would need the following changes to match expected:`}${shouldAppendDelta ? `\n\n${result.text}` : ``}`,
175
- message
176
- )
177
- )
178
- }
179
- },
180
-
181
- isNotEqualDeep(actual, expected, message) {
182
- this.doesThrow(
183
- () => this.isEqualDeep(actual, expected),
184
- undefined,
185
- buildErrorMessage(
186
- `The objects you passed are deep equal! They should not be!`,
187
- message
188
- )
189
- )
190
- },
191
-
192
- isAbove(actual, floor, message) {
193
- if (typeof actual !== 'number') {
194
- this.fail(
195
- buildErrorMessage(
196
- `${stringify(actual)} is not a number!`,
197
- message
198
- )
199
- )
200
- }
201
- if (actual <= floor) {
202
- this.fail(
203
- buildErrorMessage(
204
- `${stringify(actual)} is not above ${stringify(floor)}`,
205
- message
206
- )
207
- )
208
- }
209
- },
210
-
211
- isBelow(actual, ceiling, message) {
212
- if (typeof actual !== 'number') {
213
- this.fail(
214
- buildErrorMessage(
215
- `${stringify(actual)} is not a number!`,
216
- message
217
- )
218
- )
219
- }
220
-
221
- if (actual >= ceiling) {
222
- this.fail(
223
- buildErrorMessage(
224
- `${stringify(actual)} is not below ${stringify(ceiling)}`,
225
- message
226
- )
227
- )
228
- }
229
- },
230
-
231
- isUndefined(actual, message) {
232
- if (typeof actual !== 'undefined') {
233
- this.fail(
234
- buildErrorMessage(
235
- `${stringify(actual)} is not undefined`,
236
- message
237
- )
238
- )
239
- }
240
- },
241
-
242
- isTruthy(actual: any, message) {
243
- if (
244
- actual === false ||
245
- actual === null ||
246
- typeof actual === 'undefined' ||
247
- actual === 0
248
- ) {
249
- this.fail(
250
- buildErrorMessage(`${stringify(actual)} is not truthy`, message)
251
- )
252
- }
253
- },
254
-
255
- isFalsy(actual, message) {
256
- if (actual) {
257
- this.fail(
258
- buildErrorMessage(`${stringify(actual)} is not falsy`, message)
259
- )
260
- }
261
- },
262
-
263
- isNull(actual: any, message?) {
264
- if (actual !== null) {
265
- this.fail(
266
- buildErrorMessage(`${stringify(actual)} is not null`, message)
267
- )
268
- }
269
- },
270
-
271
- isString(actual, message) {
272
- assertUtil.assertTypeof(actual, 'string', message)
273
- },
274
-
275
- isFunction(actual, message) {
276
- assertUtil.assertTypeof(actual, 'function', message)
277
- },
278
-
279
- isTrue(actual, message) {
280
- //@ts-ignore
281
- this.isEqual(actual, true, message)
282
- },
283
-
284
- isFalse(actual, message) {
285
- //@ts-ignore
286
- this.isEqual(actual, false, message)
287
- },
288
-
289
- isObject(actual, message) {
290
- if (!isObjectLike(actual)) {
291
- throw this.fail(
292
- buildErrorMessage(
293
- `${stringify(actual)} is not an object`,
294
- message
295
- )
296
- )
297
- }
298
- },
299
-
300
- isArray(actual, message) {
301
- if (!Array.isArray(actual)) {
302
- throw this.fail(
303
- buildErrorMessage(
304
- `${stringify(actual)} is not an array`,
305
- message
306
- )
307
- )
308
- }
309
- },
310
-
311
- isLength(actual, expected, message) {
312
- if (!actual) {
313
- throw this.fail(
314
- buildErrorMessage(
315
- `Expected array of length ${expected}, but got ${stringify(actual)}`,
316
- message
317
- )
318
- )
319
- }
320
-
321
- //@ts-ignore
322
- this.isEqual(
323
- actual.length,
324
- expected,
325
- buildErrorMessage(`Your array is not the expected length!`, message)
326
- )
327
- },
328
-
329
- doesNotInclude(haystack: any, needle: any, message?: string) {
330
- let doesInclude = false
331
- try {
332
- this.doesInclude(haystack, needle, message)
333
- doesInclude = true
334
- } catch {
335
- doesInclude = false
336
- }
337
-
338
- if (doesInclude) {
339
- this.fail(
340
- buildErrorMessage(
341
- `${stringify(haystack)} should not include ${stringify(
342
- needle
343
- )}, but it does`,
344
- message
345
- )
346
- )
347
- }
348
- },
349
-
350
- doesInclude(haystack: any, needle: any, message?: string) {
351
- let msg = `Could not find \n\n${stringify(needle)}\n\n in \n\n${stringify(haystack)}\n\n`
352
-
353
- const isNeedleString = typeof needle === 'string'
354
- const isNeedleRegex = needle instanceof RegExp
355
-
356
- if (
357
- typeof haystack === 'string' &&
358
- (isNeedleString || isNeedleRegex) &&
359
- haystack.search(isNeedleString ? escapeRegExp(needle) : needle) > -1
360
- ) {
361
- return
362
- }
363
-
364
- const isHaystackObject = isObjectLike(haystack)
365
- const { needleHasArrayNotation, path, expected } =
366
- assertUtil.parseIncludeNeedle(needle)
367
-
368
- if (Array.isArray(haystack)) {
369
- let cleanedNeedle = needle
370
-
371
- if (path && path.substr(0, 3) === '[].') {
372
- cleanedNeedle = { [path.substr(3)]: expected }
373
- }
374
-
375
- const found = assertUtil.doHaystacksPassCheck(
376
- haystack,
377
- cleanedNeedle,
378
- this.doesInclude.bind(this)
379
- )
380
-
381
- if (found) {
382
- return
383
- }
384
- }
385
-
386
- if (isHaystackObject && isObjectLike(needle)) {
387
- try {
388
- //@ts-ignore
389
- this.isEqualDeep(haystack, needle, message)
390
- return
391
- } catch {}
392
- }
393
-
394
- if (
395
- assertUtil.foundUsing3rdPartyIncludes(
396
- haystack,
397
- needle,
398
- isHaystackObject
399
- )
400
- ) {
401
- return
402
- }
403
-
404
- if (
405
- !Array.isArray(haystack) &&
406
- isHaystackObject &&
407
- isObjectLike(needle) &&
408
- Object.keys(needle).length === 1 &&
409
- !needleHasArrayNotation &&
410
- path
411
- ) {
412
- const actual = assertUtil.valueAtPath(haystack, path)
413
-
414
- if (typeof actual === 'undefined') {
415
- msg = `The path ${stringify(path)} was not found in ${stringify(
416
- haystack
417
- )}`
418
- } else {
419
- // msg = `Expected:\n\n${chalk.green(
420
- // stringify(actual)
421
- // )}\n\nbut found:\n\n${chalk.red(stringify(actual))}\n\nat key:\n\n${stringify(
422
- // path
423
- // )}\n\nin:\n\n${stringify(haystack)}`
424
-
425
- msg = `Expected:\n\n${chalk.green(
426
- stringify(needle[path])
427
- )}\n\nbut found:\n\n${chalk.red(stringify(actual))}\n\nat key:\n\n${stringify(
428
- path
429
- )}`
430
-
431
- let clonedHaystack = cloneDeep(haystack)
432
- clonedHaystack = set(
433
- clonedHaystack,
434
- path,
435
- `${actual} -> ${expected}`
436
- )
437
- msg += `\n\nHere is the change:\n\n${stringify(clonedHaystack)}`
438
- }
439
-
440
- if (
441
- typeof expected === 'string' &&
442
- typeof actual === 'string' &&
443
- actual.search(expected) > -1
444
- ) {
445
- return
446
- } else if (expected instanceof RegExp && expected.exec(actual)) {
447
- return
448
- } else {
449
- //@ts-ignore
450
- this.isEqualDeep(
451
- expected,
452
- actual,
453
- buildErrorMessage(msg, message),
454
- false
455
- )
456
- }
457
-
458
- return
459
- }
460
-
461
- if (isHaystackObject && isObjectLike(needle) && path) {
462
- const { actualBeforeArray, pathAfterFirstArray } =
463
- assertUtil.splitPathBasedOnArrayNotation(path, haystack)
464
-
465
- if (!Array.isArray(actualBeforeArray)) {
466
- this.fail(buildErrorMessage(msg, message))
467
- }
468
-
469
- const found = assertUtil.doHaystacksPassCheck(
470
- actualBeforeArray,
471
- {
472
- [pathAfterFirstArray]: expected,
473
- },
474
- this.doesInclude.bind(this)
475
- )
476
-
477
- if (found) {
478
- return
479
- }
480
-
481
- msg = `Could not find match ${stringify(expected)} at ${stringify(
482
- pathAfterFirstArray
483
- )} in ${stringify(actualBeforeArray)}.`
484
- }
485
-
486
- this.fail(buildErrorMessage(msg, message))
487
- },
488
-
489
- hasAllFunctions(obj, functionNames, message?: string) {
490
- functionNames.forEach((name) => {
491
- if (typeof obj[name] !== 'function') {
492
- this.fail(
493
- buildErrorMessage(
494
- `A function named "${name}" does not exist on ${stringify(obj)}`,
495
- message
496
- )
497
- )
498
- }
499
- })
500
- },
501
-
502
- doesThrow(cb, matcher, msg) {
503
- try {
504
- cb()
505
- } catch (err: any) {
506
- assertUtil.assertErrorIncludes(matcher, err, msg)
507
- return err
508
- }
509
-
510
- this.fail(
511
- buildErrorMessage(
512
- 'Expected a thrown error, but never got one!',
513
- msg
514
- )
515
- )
516
- },
517
-
518
- async doesThrowAsync(cb, matcher, msg) {
519
- try {
520
- await cb()
521
- } catch (err: any) {
522
- assertUtil.assertErrorIncludes(matcher, err, msg)
523
-
524
- return err
525
- }
526
-
527
- this.fail(
528
- buildErrorMessage(
529
- 'Expected a thrown error, but never got one!',
530
- msg
531
- )
532
- )
533
- },
534
-
535
- fail: assertUtil.fail,
536
- isInstanceOf<T>(
537
- actual: T,
538
- Class: new (...props: any[]) => T,
539
- message?: string
540
- ): void {
541
- assert.isTrue(
542
- actual instanceof Class,
543
- buildErrorMessage(
544
- `${assertUtil.stringify(actual)} is not an instance of:\n\n${Class}`,
545
- message
546
- )
547
- )
548
- },
549
-
550
- isBetween(actual, floor, ceiling, message) {
551
- assert.isBelow(actual, ceiling, message)
552
- assert.isAbove(actual, floor, message)
553
- },
554
-
555
- isBetweenInclusive(actual, floor, ceiling, message) {
556
- //@ts-ignore
557
- this.isNumber(actual, message)
558
-
559
- if (actual >= floor && actual <= ceiling) {
560
- return
561
- }
562
-
563
- assert.fail(
564
- buildErrorMessage(
565
- `${actual} is not between ${floor} and ${ceiling} (inclusive)`,
566
- message
567
- )
568
- )
569
- },
570
- }
571
-
572
- export default assert
573
-
574
- function buildErrorMessage(
575
- defaultMessage: string,
576
- customMessage: string | undefined
577
- ) {
578
- return (
579
- (customMessage
580
- ? `${customMessage}\n\n${defaultMessage}`
581
- : defaultMessage) + '\n\n'
582
- )
583
- }