assertron 11.1.4 → 11.2.1

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 (155) hide show
  1. package/cjs/assert-order/AssertOrder.d.ts.map +1 -1
  2. package/cjs/assert-order/AssertOrder.js +3 -1
  3. package/cjs/assert-order/AssertOrder.js.map +1 -1
  4. package/cjs/assert-order/InvalidOrder.d.ts +1 -1
  5. package/cjs/assert-order/InvalidOrder.d.ts.map +1 -1
  6. package/cjs/assert-order/InvalidOrder.js +4 -2
  7. package/cjs/assert-order/InvalidOrder.js.map +1 -1
  8. package/cjs/assert-order/StateMachine.d.ts +1 -1
  9. package/cjs/assert-order/StateMachine.d.ts.map +1 -1
  10. package/cjs/assert-order/StateMachine.js +17 -8
  11. package/cjs/assert-order/StateMachine.js.map +1 -1
  12. package/cjs/assert-order/types.d.ts.map +1 -1
  13. package/cjs/assertron/assertron.d.ts +1 -1
  14. package/cjs/assertron/assertron.d.ts.map +1 -1
  15. package/cjs/assertron/assertron.js.map +1 -1
  16. package/cjs/assertron/falsy.d.ts.map +1 -1
  17. package/cjs/assertron/falsy.js.map +1 -1
  18. package/cjs/assertron/isInstanceof.d.ts.map +1 -1
  19. package/cjs/assertron/isInstanceof.js.map +1 -1
  20. package/cjs/assertron/pathEqual.js.map +1 -1
  21. package/cjs/assertron/rejects.d.ts.map +1 -1
  22. package/cjs/assertron/rejects.js +3 -1
  23. package/cjs/assertron/rejects.js.map +1 -1
  24. package/cjs/assertron/repeat.d.ts.map +1 -1
  25. package/cjs/assertron/repeat.js +3 -1
  26. package/cjs/assertron/repeat.js.map +1 -1
  27. package/cjs/assertron/resolves.d.ts.map +1 -1
  28. package/cjs/assertron/resolves.js +3 -1
  29. package/cjs/assertron/resolves.js.map +1 -1
  30. package/cjs/assertron/satisfies.d.ts +1 -1
  31. package/cjs/assertron/satisfies.d.ts.map +1 -1
  32. package/cjs/assertron/satisfies.js.map +1 -1
  33. package/cjs/assertron/throws.d.ts +1 -1
  34. package/cjs/assertron/throws.d.ts.map +1 -1
  35. package/cjs/assertron/throws.js +7 -3
  36. package/cjs/assertron/throws.js.map +1 -1
  37. package/cjs/assertron/truthy.d.ts.map +1 -1
  38. package/cjs/assertron/truthy.js.map +1 -1
  39. package/cjs/errors.d.ts +3 -3
  40. package/cjs/errors.d.ts.map +1 -1
  41. package/cjs/errors.js.map +1 -1
  42. package/cjs/index.d.ts +2 -1
  43. package/cjs/index.d.ts.map +1 -1
  44. package/cjs/index.js +15 -1
  45. package/cjs/index.js.map +1 -1
  46. package/cjs/package.json +1 -1
  47. package/cjs/types.d.ts.map +1 -1
  48. package/cjs/utils/index.js.map +1 -1
  49. package/cjs/utils/isErrorConstructor.d.ts +1 -1
  50. package/cjs/utils/isErrorConstructor.d.ts.map +1 -1
  51. package/cjs/utils/isErrorConstructor.js.map +1 -1
  52. package/cjs/utils/notEqualMessage.js.map +1 -1
  53. package/cjs/utils/notSatisfiedMessage.d.ts +1 -1
  54. package/cjs/utils/notSatisfiedMessage.d.ts.map +1 -1
  55. package/cjs/utils/notSatisfiedMessage.js +8 -3
  56. package/cjs/utils/notSatisfiedMessage.js.map +1 -1
  57. package/cjs/utils/notThrownMessage.js.map +1 -1
  58. package/cjs/utils/promiseMessages.d.ts.map +1 -1
  59. package/cjs/utils/promiseMessages.js +8 -4
  60. package/cjs/utils/promiseMessages.js.map +1 -1
  61. package/cjs/utils/unexpectedErrorMessage.d.ts +1 -1
  62. package/cjs/utils/unexpectedErrorMessage.d.ts.map +1 -1
  63. package/cjs/utils/unexpectedErrorMessage.js +1 -2
  64. package/cjs/utils/unexpectedErrorMessage.js.map +1 -1
  65. package/esm/assert-order/AssertOrder.d.ts.map +1 -1
  66. package/esm/assert-order/AssertOrder.js +3 -1
  67. package/esm/assert-order/AssertOrder.js.map +1 -1
  68. package/esm/assert-order/InvalidOrder.d.ts +1 -1
  69. package/esm/assert-order/InvalidOrder.d.ts.map +1 -1
  70. package/esm/assert-order/InvalidOrder.js +4 -2
  71. package/esm/assert-order/InvalidOrder.js.map +1 -1
  72. package/esm/assert-order/StateMachine.d.ts +1 -1
  73. package/esm/assert-order/StateMachine.d.ts.map +1 -1
  74. package/esm/assert-order/StateMachine.js +17 -8
  75. package/esm/assert-order/StateMachine.js.map +1 -1
  76. package/esm/assert-order/types.d.ts.map +1 -1
  77. package/esm/assertron/assertron.d.ts +1 -1
  78. package/esm/assertron/assertron.d.ts.map +1 -1
  79. package/esm/assertron/assertron.js.map +1 -1
  80. package/esm/assertron/falsy.d.ts.map +1 -1
  81. package/esm/assertron/falsy.js.map +1 -1
  82. package/esm/assertron/isInstanceof.d.ts.map +1 -1
  83. package/esm/assertron/isInstanceof.js.map +1 -1
  84. package/esm/assertron/pathEqual.js.map +1 -1
  85. package/esm/assertron/rejects.d.ts.map +1 -1
  86. package/esm/assertron/rejects.js +3 -1
  87. package/esm/assertron/rejects.js.map +1 -1
  88. package/esm/assertron/repeat.d.ts.map +1 -1
  89. package/esm/assertron/repeat.js +3 -1
  90. package/esm/assertron/repeat.js.map +1 -1
  91. package/esm/assertron/resolves.d.ts.map +1 -1
  92. package/esm/assertron/resolves.js +3 -1
  93. package/esm/assertron/resolves.js.map +1 -1
  94. package/esm/assertron/satisfies.d.ts +1 -1
  95. package/esm/assertron/satisfies.d.ts.map +1 -1
  96. package/esm/assertron/satisfies.js.map +1 -1
  97. package/esm/assertron/throws.d.ts +1 -1
  98. package/esm/assertron/throws.d.ts.map +1 -1
  99. package/esm/assertron/throws.js +7 -3
  100. package/esm/assertron/throws.js.map +1 -1
  101. package/esm/assertron/truthy.d.ts.map +1 -1
  102. package/esm/assertron/truthy.js.map +1 -1
  103. package/esm/errors.d.ts +3 -3
  104. package/esm/errors.d.ts.map +1 -1
  105. package/esm/errors.js.map +1 -1
  106. package/esm/index.d.ts +2 -1
  107. package/esm/index.d.ts.map +1 -1
  108. package/esm/index.js +2 -1
  109. package/esm/index.js.map +1 -1
  110. package/esm/types.d.ts.map +1 -1
  111. package/esm/utils/index.js.map +1 -1
  112. package/esm/utils/isErrorConstructor.d.ts +1 -1
  113. package/esm/utils/isErrorConstructor.d.ts.map +1 -1
  114. package/esm/utils/isErrorConstructor.js.map +1 -1
  115. package/esm/utils/notEqualMessage.js.map +1 -1
  116. package/esm/utils/notSatisfiedMessage.d.ts +1 -1
  117. package/esm/utils/notSatisfiedMessage.d.ts.map +1 -1
  118. package/esm/utils/notSatisfiedMessage.js +8 -3
  119. package/esm/utils/notSatisfiedMessage.js.map +1 -1
  120. package/esm/utils/notThrownMessage.js.map +1 -1
  121. package/esm/utils/promiseMessages.d.ts.map +1 -1
  122. package/esm/utils/promiseMessages.js +8 -4
  123. package/esm/utils/promiseMessages.js.map +1 -1
  124. package/esm/utils/unexpectedErrorMessage.d.ts +1 -1
  125. package/esm/utils/unexpectedErrorMessage.d.ts.map +1 -1
  126. package/esm/utils/unexpectedErrorMessage.js +1 -2
  127. package/esm/utils/unexpectedErrorMessage.js.map +1 -1
  128. package/package.json +3 -3
  129. package/ts/assert-order/AssertOrder.ts +138 -143
  130. package/ts/assert-order/InvalidOrder.ts +23 -19
  131. package/ts/assert-order/StateMachine.ts +96 -89
  132. package/ts/assert-order/index.ts +0 -1
  133. package/ts/assert-order/internalInterfaces.ts +3 -3
  134. package/ts/assert-order/types.ts +5 -5
  135. package/ts/assertron/assertron.ts +39 -32
  136. package/ts/assertron/falsy.ts +1 -2
  137. package/ts/assertron/isInstanceof.ts +6 -3
  138. package/ts/assertron/pathEqual.ts +2 -2
  139. package/ts/assertron/rejects.ts +6 -4
  140. package/ts/assertron/repeat.ts +27 -21
  141. package/ts/assertron/resolves.ts +6 -4
  142. package/ts/assertron/satisfies.ts +28 -21
  143. package/ts/assertron/throws.ts +76 -55
  144. package/ts/assertron/truthy.ts +1 -4
  145. package/ts/errors.ts +9 -9
  146. package/ts/index.ts +17 -1
  147. package/ts/testUtils.ts +52 -55
  148. package/ts/types.ts +0 -1
  149. package/ts/utils/index.ts +1 -1
  150. package/ts/utils/isErrorConstructor.ts +2 -2
  151. package/ts/utils/notEqualMessage.ts +1 -1
  152. package/ts/utils/notSatisfiedMessage.ts +18 -14
  153. package/ts/utils/notThrownMessage.ts +1 -1
  154. package/ts/utils/promiseMessages.ts +12 -5
  155. package/ts/utils/unexpectedErrorMessage.ts +4 -3
package/ts/errors.ts CHANGED
@@ -1,22 +1,22 @@
1
- import { IsoError, ModuleError } from 'iso-error'
2
- import { RequiredPick } from 'type-plus'
1
+ import { ModuleError } from 'iso-error'
2
+ import type { RequiredPick } from 'type-plus'
3
3
  import { failOnOccurrence } from './utils/index.js'
4
4
 
5
5
  /**
6
6
  * A base error for all assertion errors
7
7
  */
8
8
  export class AssertionError extends ModuleError {
9
- constructor(message: string, options: AssertionError.Options) {
10
- super('assertron', message, options)
11
- }
9
+ constructor(message: string, options: AssertionError.Options) {
10
+ super('assertron', message, options)
11
+ }
12
12
  }
13
13
 
14
14
  export namespace AssertionError {
15
- export type Options = RequiredPick<IsoError.Options, 'ssf'>
15
+ export type Options = RequiredPick<ModuleError.Options, 'ssf'>
16
16
  }
17
17
 
18
18
  export class FailOnOccurrence extends AssertionError {
19
- constructor(public occurrence: number, public error: any, options: AssertionError.Options) {
20
- super(failOnOccurrence(occurrence, error), options)
21
- }
19
+ constructor(public occurrence: number, public error: any, options: AssertionError.Options) {
20
+ super(failOnOccurrence(occurrence, error), options)
21
+ }
22
22
  }
package/ts/index.ts CHANGED
@@ -1,7 +1,23 @@
1
1
  import { assertron } from './assertron/index.js'
2
2
 
3
+ export {
4
+ anything,
5
+ has,
6
+ every,
7
+ hasAll,
8
+ isInClosedInterval,
9
+ isInLeftClosedInterval,
10
+ isInOpenInterval,
11
+ isInRange,
12
+ isInRightClosedInterval,
13
+ isTypeOf,
14
+ none,
15
+ some,
16
+ startsWith
17
+ } from 'satisfier'
3
18
  export * from './assert-order/index.js'
4
19
  export * from './assertron/index.js'
5
20
  export * from './errors.js'
6
- export default assertron
7
21
  export { assertron as a }
22
+
23
+ export default assertron
package/ts/testUtils.ts CHANGED
@@ -2,83 +2,80 @@
2
2
  import t from 'assert'
3
3
  import isPromise from 'is-promise'
4
4
  import { escapeRegExp, isError } from 'lodash'
5
- import { ErrorConstructor } from './types.js'
5
+ import type { ErrorConstructor } from './types.js'
6
6
 
7
7
  export type AnyFunction = (...args: any[]) => any
8
8
 
9
9
  export function runAsync(fn: AnyFunction) {
10
- return new Promise((resolve, reject) => {
11
- setTimeout(() => {
12
- try {
13
- resolve(fn())
14
- }
15
- catch (err) {
16
- reject(err)
17
- }
18
- }, 1)
19
- })
10
+ return new Promise((resolve, reject) => {
11
+ setTimeout(() => {
12
+ try {
13
+ resolve(fn())
14
+ } catch (err) {
15
+ reject(err)
16
+ }
17
+ }, 1)
18
+ })
20
19
  }
21
20
 
22
21
  export function runSequentialAsync(...fns: AnyFunction[]) {
23
- return new Promise((resolve, reject) => {
24
- setTimeout(() => {
25
- try {
26
- let i = 0
27
- for (; i < fns.length - 1; i++) {
28
- fns[i]()
29
- }
30
- resolve(fns[i]())
31
- }
32
- catch (err) {
33
- reject(err)
34
- }
35
- }, 1)
36
- })
22
+ return new Promise((resolve, reject) => {
23
+ setTimeout(() => {
24
+ try {
25
+ let i = 0
26
+ for (; i < fns.length - 1; i++) {
27
+ fns[i]()
28
+ }
29
+ resolve(fns[i]())
30
+ } catch (err) {
31
+ reject(err)
32
+ }
33
+ }, 1)
34
+ })
37
35
  }
38
36
 
39
37
  export function runParallelAsync(...fns: AnyFunction[]) {
40
- return Promise.all(fns.map(fn => runAsync(fn)))
38
+ return Promise.all(fns.map(fn => runAsync(fn)))
41
39
  }
42
40
 
43
-
44
41
  export function assertIsPromise(promiseError: Promise<any>) {
45
- t(isPromise(promiseError))
42
+ t(isPromise(promiseError))
46
43
  }
47
44
 
48
45
  export function assertIsError(err: Error) {
49
- t(isError(err))
46
+ t(isError(err))
50
47
  }
51
48
 
52
49
  export function assertThrows<E extends Error>(fn: AnyFunction, ErrorType?: ErrorConstructor<E>): E {
53
- try {
54
- fn()
55
- }
56
- catch (e: any) {
57
- if (ErrorType && !(e instanceof ErrorType)) {
58
- throw new Error(`thrown error ${e} is not of expected type ${ErrorType}`)
59
- }
60
- return e
61
- }
62
- throw new Error(`${fn} does not throw as expected`)
50
+ try {
51
+ fn()
52
+ } catch (e: any) {
53
+ if (ErrorType && !(e instanceof ErrorType)) {
54
+ throw new Error(`thrown error ${e} is not of expected type ${ErrorType}`)
55
+ }
56
+ return e
57
+ }
58
+ throw new Error(`${fn} does not throw as expected`)
63
59
  }
64
60
 
65
- export async function assertAsyncThrows<E extends Error>(fn: AnyFunction, ErrorType?: ErrorConstructor<E>): Promise<E> {
66
- try {
67
- await fn()
68
- }
69
- catch (e: any) {
70
- // console.log('catch clause', e)
71
- if (ErrorType && !(e instanceof ErrorType)) {
72
- throw new Error(`thrown error ${e} is not of expected type ${ErrorType}`)
73
- }
74
- // console.log('returning e')
75
- return e
76
- }
77
- throw new Error(`${fn} does not throw as expected`)
61
+ export async function assertAsyncThrows<E extends Error>(
62
+ fn: AnyFunction,
63
+ ErrorType?: ErrorConstructor<E>
64
+ ): Promise<E> {
65
+ try {
66
+ await fn()
67
+ } catch (e: any) {
68
+ // console.log('catch clause', e)
69
+ if (ErrorType && !(e instanceof ErrorType)) {
70
+ throw new Error(`thrown error ${e} is not of expected type ${ErrorType}`)
71
+ }
72
+ // console.log('returning e')
73
+ return e
74
+ }
75
+ throw new Error(`${fn} does not throw as expected`)
78
76
  }
79
77
 
80
-
81
78
  export function noStackTraceFor(filename: string, err: Error) {
82
- if (err.stack && RegExp(escapeRegExp(filename)).test(err.stack))
83
- throw new Error(`contains internal stack: \n${err.stack}`)
79
+ if (err.stack && RegExp(escapeRegExp(filename)).test(err.stack))
80
+ throw new Error(`contains internal stack: \n${err.stack}`)
84
81
  }
package/ts/types.ts CHANGED
@@ -1,3 +1,2 @@
1
-
2
1
  export type ErrorValidator = (value: any) => boolean
3
2
  export type ErrorConstructor<E extends Error> = new (...args: any[]) => E
package/ts/utils/index.ts CHANGED
@@ -8,5 +8,5 @@ export * from './promiseMessages.js'
8
8
  export * from './unexpectedErrorMessage.js'
9
9
 
10
10
  export function failOnOccurrence(occurrence: number, error: any) {
11
- return `Failed on ${occurrence} occurrence: ${tersify(error, { maxLength: Infinity })}`
11
+ return `Failed on ${occurrence} occurrence: ${tersify(error, { maxLength: Infinity })}`
12
12
  }
@@ -1,5 +1,5 @@
1
- import { ErrorConstructor } from '../types.js'
1
+ import type { ErrorConstructor } from '../types.js'
2
2
 
3
3
  export function isErrorConstructor(validator: any): validator is ErrorConstructor<any> {
4
- return Object.prototype.isPrototypeOf.call(Error.prototype, validator.prototype)
4
+ return Object.prototype.isPrototypeOf.call(Error.prototype, validator.prototype)
5
5
  }
@@ -1,3 +1,3 @@
1
1
  export function notEqualMessage(actual: any, expected: any) {
2
- return `Expected value to equal ${expected}, but received ${actual}`
2
+ return `Expected value to equal ${expected}, but received ${actual}`
3
3
  }
@@ -1,27 +1,31 @@
1
- import { Diff } from 'satisfier'
1
+ import type { Diff } from 'satisfier'
2
2
  import { tersify } from 'tersify'
3
3
 
4
4
  export function notSatisfiedMessage(entries: Diff[]) {
5
- return entries.map(e => {
6
- const path = formatPath(e.path)
7
- return `Expect ${path} to satisfy ${formatValue(e.expected)}, but received ${formatValue(e.actual)}`
8
- }).join('\n')
5
+ return entries
6
+ .map(e => {
7
+ const path = formatPath(e.path)
8
+ return `Expect ${path} to satisfy ${formatValue(e.expected)}, but received ${formatValue(e.actual)}`
9
+ })
10
+ .join('\n')
9
11
  }
10
12
 
11
13
  function formatPath(entries: (string | number)[]) {
12
- if (entries.length === 0)
13
- return 'actual'
14
- const nodes = [...entries]
15
- if (isIndice(nodes[0])) {
16
- nodes.unshift('actual')
17
- }
18
- return nodes.map(n => isIndice(n) ? `[${n}]` : '.' + n).join('').slice(1)
14
+ if (entries.length === 0) return 'actual'
15
+ const nodes = [...entries]
16
+ if (isIndice(nodes[0])) {
17
+ nodes.unshift('actual')
18
+ }
19
+ return nodes
20
+ .map(n => (isIndice(n) ? `[${n}]` : '.' + n))
21
+ .join('')
22
+ .slice(1)
19
23
  }
20
24
 
21
25
  function isIndice(node: string | number): node is number {
22
- return typeof node === 'number'
26
+ return typeof node === 'number'
23
27
  }
24
28
 
25
29
  function formatValue(value: any) {
26
- return tersify(value)
30
+ return tersify(value)
27
31
  }
@@ -1,5 +1,5 @@
1
1
  import { tersify } from 'tersify'
2
2
 
3
3
  export function notThrownMessage(value: any) {
4
- return `Expect function to throw, but it returned '${tersify(value)}' instead.`
4
+ return `Expect function to throw, but it returned '${tersify(value)}' instead.`
5
5
  }
@@ -1,12 +1,19 @@
1
1
  import { tersify } from 'tersify'
2
2
 
3
3
  export function notRejectedMessage(value: any) {
4
- return `Expected promise to reject, but it resolves with ` + (typeof value === 'string'
5
- ? `'${value}'` : tersify(value, { maxLength: Infinity }))
4
+ return (
5
+ `Expected promise to reject, but it resolves with ` +
6
+ (typeof value === 'string' ? `'${value}'` : tersify(value, { maxLength: Infinity }))
7
+ )
6
8
  }
7
9
 
8
10
  export function notResolvedMessage(error: any) {
9
- return `Expected promise to resolve, but it rejects with ` + (typeof error === 'string'
10
- ? `'${error}'` : error instanceof Error ? error : tersify(error, { maxLength: Infinity }))
11
+ return (
12
+ `Expected promise to resolve, but it rejects with ` +
13
+ (typeof error === 'string'
14
+ ? `'${error}'`
15
+ : error instanceof Error
16
+ ? error
17
+ : tersify(error, { maxLength: Infinity }))
18
+ )
11
19
  }
12
-
@@ -1,8 +1,9 @@
1
1
  import { tersify } from 'tersify'
2
- import { ErrorConstructor, ErrorValidator } from '../types.js'
2
+ import type { ErrorConstructor, ErrorValidator } from '../types.js'
3
3
  import { isErrorConstructor } from './isErrorConstructor.js'
4
4
 
5
5
  export function unexpectedErrorMessage(actual: any, expected: ErrorValidator | ErrorConstructor<any>) {
6
- return `Unexpected error. Expecting '${isErrorConstructor(expected) ?
7
- expected.name : tersify(expected)}' but received ${tersify(actual)}`
6
+ return `Unexpected error. Expecting '${
7
+ isErrorConstructor(expected) ? expected.name : tersify(expected)
8
+ }' but received ${tersify(actual)}`
8
9
  }