assertron 9.0.9 → 9.1.0

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 (197) hide show
  1. package/cjs/assert-order/AssertOrder.js +169 -98
  2. package/cjs/assert-order/AssertOrder.js.map +1 -0
  3. package/cjs/assert-order/InvalidOrder.js +37 -8
  4. package/cjs/assert-order/InvalidOrder.js.map +1 -0
  5. package/cjs/assert-order/StateMachine.js +147 -57
  6. package/cjs/assert-order/StateMachine.js.map +1 -0
  7. package/cjs/assert-order/index.js +18 -5
  8. package/cjs/assert-order/index.js.map +1 -0
  9. package/cjs/assert-order/types.js +1 -1
  10. package/cjs/assert-order/types.js.map +1 -0
  11. package/cjs/assertron/assertron.js +21 -21
  12. package/cjs/assertron/assertron.js.map +1 -0
  13. package/cjs/assertron/falsy.js +3 -3
  14. package/cjs/assertron/falsy.js.map +1 -0
  15. package/cjs/assertron/index.js +16 -3
  16. package/cjs/assertron/index.js.map +1 -0
  17. package/cjs/assertron/pathEqual.js +4 -4
  18. package/cjs/assertron/pathEqual.js.map +1 -0
  19. package/cjs/assertron/rejects.js +4 -4
  20. package/cjs/assertron/rejects.js.map +1 -0
  21. package/cjs/assertron/repeat.js +9 -7
  22. package/cjs/assertron/repeat.js.map +1 -0
  23. package/cjs/assertron/resolves.js +4 -4
  24. package/cjs/assertron/resolves.js.map +1 -0
  25. package/cjs/assertron/satisfies.js +4 -4
  26. package/cjs/assertron/satisfies.js.map +1 -0
  27. package/cjs/assertron/throws.js +13 -11
  28. package/cjs/assertron/throws.js.map +1 -0
  29. package/cjs/assertron/truthy.js +3 -3
  30. package/cjs/assertron/truthy.js.map +1 -0
  31. package/cjs/errors.js +32 -8
  32. package/cjs/errors.js.map +1 -0
  33. package/cjs/index.js +20 -7
  34. package/cjs/index.js.map +1 -0
  35. package/cjs/types.js +1 -1
  36. package/cjs/types.js.map +1 -0
  37. package/cjs/utils/index.js +21 -8
  38. package/cjs/utils/index.js.map +1 -0
  39. package/cjs/utils/isErrorConstructor.js +1 -1
  40. package/cjs/utils/isErrorConstructor.js.map +1 -0
  41. package/cjs/utils/notEqualMessage.js +1 -1
  42. package/cjs/utils/notEqualMessage.js.map +1 -0
  43. package/cjs/utils/notSatisfiedMessage.js +11 -3
  44. package/cjs/utils/notSatisfiedMessage.js.map +1 -0
  45. package/cjs/utils/notThrownMessage.js +1 -1
  46. package/cjs/utils/notThrownMessage.js.map +1 -0
  47. package/cjs/utils/promiseMessages.js +1 -1
  48. package/cjs/utils/promiseMessages.js.map +1 -0
  49. package/cjs/utils/unexpectedErrorMessage.js +3 -3
  50. package/cjs/utils/unexpectedErrorMessage.js.map +1 -0
  51. package/esm/assert-order/AssertOrder.js +9 -3
  52. package/esm/assert-order/AssertOrder.js.map +1 -0
  53. package/esm/assert-order/InvalidOrder.js +20 -5
  54. package/esm/assert-order/InvalidOrder.js.map +1 -0
  55. package/esm/assert-order/StateMachine.js +37 -4
  56. package/esm/assert-order/StateMachine.js.map +1 -0
  57. package/esm/assert-order/index.js +4 -4
  58. package/esm/assert-order/index.js.map +1 -0
  59. package/esm/assert-order/types.js +1 -1
  60. package/esm/assert-order/types.js.map +1 -0
  61. package/esm/assertron/assertron.js +11 -11
  62. package/esm/assertron/assertron.js.map +1 -0
  63. package/esm/assertron/falsy.js +2 -2
  64. package/esm/assertron/falsy.js.map +1 -0
  65. package/esm/assertron/index.js +2 -2
  66. package/esm/assertron/index.js.map +1 -0
  67. package/esm/assertron/pathEqual.js +3 -3
  68. package/esm/assertron/pathEqual.js.map +1 -0
  69. package/esm/assertron/rejects.js +3 -3
  70. package/esm/assertron/rejects.js.map +1 -0
  71. package/esm/assertron/repeat.js +2 -2
  72. package/esm/assertron/repeat.js.map +1 -0
  73. package/esm/assertron/resolves.js +3 -3
  74. package/esm/assertron/resolves.js.map +1 -0
  75. package/esm/assertron/satisfies.js +3 -3
  76. package/esm/assertron/satisfies.js.map +1 -0
  77. package/esm/assertron/throws.js +3 -3
  78. package/esm/assertron/throws.js.map +1 -0
  79. package/esm/assertron/truthy.js +2 -2
  80. package/esm/assertron/truthy.js.map +1 -0
  81. package/esm/errors.js +14 -4
  82. package/esm/errors.js.map +1 -0
  83. package/esm/index.js +5 -5
  84. package/esm/index.js.map +1 -0
  85. package/esm/types.js +1 -1
  86. package/esm/types.js.map +1 -0
  87. package/esm/utils/index.js +7 -7
  88. package/esm/utils/index.js.map +1 -0
  89. package/esm/utils/isErrorConstructor.js +1 -1
  90. package/esm/utils/isErrorConstructor.js.map +1 -0
  91. package/esm/utils/notEqualMessage.js +1 -1
  92. package/esm/utils/notEqualMessage.js.map +1 -0
  93. package/esm/utils/notSatisfiedMessage.js +1 -1
  94. package/esm/utils/notSatisfiedMessage.js.map +1 -0
  95. package/esm/utils/notThrownMessage.js +1 -1
  96. package/esm/utils/notThrownMessage.js.map +1 -0
  97. package/esm/utils/promiseMessages.js +1 -1
  98. package/esm/utils/promiseMessages.js.map +1 -0
  99. package/esm/utils/unexpectedErrorMessage.js +2 -2
  100. package/esm/utils/unexpectedErrorMessage.js.map +1 -0
  101. package/package.json +48 -46
  102. package/{src → ts}/assert-order/AssertOrder.ts +2 -2
  103. package/{src → ts}/assert-order/InvalidOrder.ts +2 -2
  104. package/{src → ts}/assert-order/StateMachine.ts +1 -1
  105. package/ts/assert-order/index.ts +4 -0
  106. package/{src → ts}/assert-order/internalInterfaces.ts +0 -0
  107. package/{src → ts}/assert-order/types.ts +0 -0
  108. package/ts/assertron/assertron.ts +29 -0
  109. package/{src → ts}/assertron/falsy.ts +1 -1
  110. package/ts/assertron/index.ts +1 -0
  111. package/{src → ts}/assertron/pathEqual.ts +2 -2
  112. package/{src → ts}/assertron/rejects.ts +2 -2
  113. package/{src → ts}/assertron/repeat.ts +2 -2
  114. package/{src → ts}/assertron/resolves.ts +2 -2
  115. package/{src → ts}/assertron/satisfies.ts +2 -2
  116. package/{src → ts}/assertron/throws.ts +5 -5
  117. package/{src → ts}/assertron/truthy.ts +1 -1
  118. package/{src → ts}/errors.ts +1 -1
  119. package/ts/index.ts +6 -0
  120. package/{src → ts}/testUtils.ts +3 -3
  121. package/{src → ts}/types.ts +0 -0
  122. package/ts/utils/index.ts +12 -0
  123. package/{src → ts}/utils/isErrorConstructor.ts +1 -1
  124. package/{src → ts}/utils/notEqualMessage.ts +0 -1
  125. package/{src → ts}/utils/notSatisfiedMessage.ts +2 -2
  126. package/{src → ts}/utils/notThrownMessage.ts +0 -0
  127. package/{src → ts}/utils/promiseMessages.ts +0 -0
  128. package/{src → ts}/utils/unexpectedErrorMessage.ts +3 -3
  129. package/cjs/assert-order/AssertOrder.d.ts +0 -41
  130. package/cjs/assert-order/AssertOrder.d.ts.map +0 -1
  131. package/cjs/assert-order/InvalidOrder.d.ts +0 -9
  132. package/cjs/assert-order/InvalidOrder.d.ts.map +0 -1
  133. package/cjs/assert-order/StateMachine.d.ts +0 -22
  134. package/cjs/assert-order/StateMachine.d.ts.map +0 -1
  135. package/cjs/assert-order/index.d.ts +0 -4
  136. package/cjs/assert-order/index.d.ts.map +0 -1
  137. package/cjs/assert-order/types.d.ts +0 -8
  138. package/cjs/assert-order/types.d.ts.map +0 -1
  139. package/cjs/assertron/assertron.d.ts +0 -21
  140. package/cjs/assertron/assertron.d.ts.map +0 -1
  141. package/cjs/assertron/falsy.d.ts +0 -2
  142. package/cjs/assertron/falsy.d.ts.map +0 -1
  143. package/cjs/assertron/index.d.ts +0 -2
  144. package/cjs/assertron/index.d.ts.map +0 -1
  145. package/cjs/assertron/pathEqual.d.ts +0 -2
  146. package/cjs/assertron/pathEqual.d.ts.map +0 -1
  147. package/cjs/assertron/rejects.d.ts +0 -2
  148. package/cjs/assertron/rejects.d.ts.map +0 -1
  149. package/cjs/assertron/repeat.d.ts +0 -6
  150. package/cjs/assertron/repeat.d.ts.map +0 -1
  151. package/cjs/assertron/resolves.d.ts +0 -2
  152. package/cjs/assertron/resolves.d.ts.map +0 -1
  153. package/cjs/assertron/satisfies.d.ts +0 -10
  154. package/cjs/assertron/satisfies.d.ts.map +0 -1
  155. package/cjs/assertron/throws.d.ts +0 -6
  156. package/cjs/assertron/throws.d.ts.map +0 -1
  157. package/cjs/assertron/truthy.d.ts +0 -2
  158. package/cjs/assertron/truthy.d.ts.map +0 -1
  159. package/cjs/errors.d.ts +0 -17
  160. package/cjs/errors.d.ts.map +0 -1
  161. package/cjs/index.d.ts +0 -6
  162. package/cjs/index.d.ts.map +0 -1
  163. package/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  164. package/cjs/types.d.ts +0 -3
  165. package/cjs/types.d.ts.map +0 -1
  166. package/cjs/utils/index.d.ts +0 -8
  167. package/cjs/utils/index.d.ts.map +0 -1
  168. package/cjs/utils/isErrorConstructor.d.ts +0 -3
  169. package/cjs/utils/isErrorConstructor.d.ts.map +0 -1
  170. package/cjs/utils/notEqualMessage.d.ts +0 -2
  171. package/cjs/utils/notEqualMessage.d.ts.map +0 -1
  172. package/cjs/utils/notSatisfiedMessage.d.ts +0 -3
  173. package/cjs/utils/notSatisfiedMessage.d.ts.map +0 -1
  174. package/cjs/utils/notThrownMessage.d.ts +0 -2
  175. package/cjs/utils/notThrownMessage.d.ts.map +0 -1
  176. package/cjs/utils/promiseMessages.d.ts +0 -3
  177. package/cjs/utils/promiseMessages.d.ts.map +0 -1
  178. package/cjs/utils/unexpectedErrorMessage.d.ts +0 -3
  179. package/cjs/utils/unexpectedErrorMessage.d.ts.map +0 -1
  180. package/esm/tsconfig.esm.tsbuildinfo +0 -1
  181. package/src/assert-order/AssertOrder.spec.ts +0 -446
  182. package/src/assert-order/InvalidOrder.spec.ts +0 -60
  183. package/src/assert-order/index.ts +0 -4
  184. package/src/assertron/assertron.spec.ts +0 -40
  185. package/src/assertron/assertron.ts +0 -29
  186. package/src/assertron/falsy.spec.ts +0 -20
  187. package/src/assertron/index.ts +0 -1
  188. package/src/assertron/pathEqual.spec.ts +0 -28
  189. package/src/assertron/rejects.spec.ts +0 -32
  190. package/src/assertron/repeat.spec.ts +0 -47
  191. package/src/assertron/resolves.spec.ts +0 -29
  192. package/src/assertron/satisfies.spec.ts +0 -159
  193. package/src/assertron/throws.spec.ts +0 -184
  194. package/src/assertron/truthy.spec.ts +0 -23
  195. package/src/index.ts +0 -6
  196. package/src/utils/index.ts +0 -12
  197. package/src/utils/notSatisfiedMessage.spec.ts +0 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assertron",
3
- "version": "9.0.9",
3
+ "version": "9.1.0",
4
4
  "description": "A supplementary assertion library",
5
5
  "homepage": "https://github.com/unional/assertron",
6
6
  "bugs": {
@@ -16,17 +16,21 @@
16
16
  "email": "homawong@gmail.com"
17
17
  },
18
18
  "sideEffects": false,
19
- "main": "cjs/index.js",
20
- "module": "esm/index.js",
21
- "jsnext:main": "esm/index.js",
19
+ "type": "module",
20
+ "exports": {
21
+ "import": "./esm/index.js",
22
+ "require": "./cjs/index.js"
23
+ },
24
+ "main": "./cjs/index.js",
22
25
  "browser": {
23
26
  "perf_hooks": false
24
27
  },
25
- "typings": "cjs/index.d.ts",
28
+ "types": "./esm/index.d.ts",
26
29
  "files": [
27
30
  "cjs",
28
31
  "esm",
29
- "src"
32
+ "ts",
33
+ "!ts/**/*.spec.ts"
30
34
  ],
31
35
  "scripts": {
32
36
  "build": "run-p build:cjs build:esm",
@@ -35,65 +39,63 @@
35
39
  "build:watch": "tsc --watch",
36
40
  "clean": "rimraf cjs esm coverage lib libm",
37
41
  "coverage": "jest --coverage",
38
- "depcheck": "yarn dependency-check",
39
- "dependency-check": "run-p dependency-check:unused dependency-check:missing",
40
- "dependency-check:missing": "dependency-check . --missing --no-dev",
41
- "dependency-check:unused": "dependency-check . --unused --no-dev -i type-plus -i global-store -i @types/node -i standard-log-color",
42
+ "depcheck": "depcheck",
42
43
  "lint": "eslint --ext=js,ts .",
44
+ "_postinstall": "husky install",
45
+ "prepack": "pinst --disable",
46
+ "postpack": "pinst --enable",
43
47
  "nuke": "yarn clean && rimraf node_modules",
44
- "release": "npx semantic-release",
48
+ "size": "size-limit",
45
49
  "test": "jest",
46
50
  "test:watch": "jest --watch",
47
- "verify": "run-p verify:build lint coverage",
48
- "verify:build": "npm-run-all clean build --parallel dependency-check",
51
+ "verify": "npm-run-all clean -p build depcheck lint -p coverage size",
49
52
  "watch": "yarn test:watch"
50
53
  },
51
- "husky": {
52
- "hooks": {
53
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
54
- }
55
- },
56
54
  "dependencies": {
57
55
  "is-node": "^1.0.2",
58
56
  "is-promise": "^4.0.0",
59
- "iso-error": "^4.1.2",
57
+ "iso-error": "^4.3.3",
60
58
  "path-equal": "^1.1.3",
61
59
  "satisfier": "^5.1.4",
62
- "tersify": "^3.8.3",
63
- "tslib": "^2.3.1",
64
- "type-plus": "^4.8.0"
60
+ "tersify": "^3.8.4",
61
+ "type-plus": "^4.9.1"
65
62
  },
66
63
  "devDependencies": {
67
- "@babel/core": "^7.17.7",
68
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
69
- "@babel/plugin-proposal-optional-chaining": "^7.16.7",
70
- "@babel/preset-env": "^7.16.11",
71
- "@babel/preset-typescript": "^7.16.7",
72
- "@commitlint/cli": "^16.2.3",
73
- "@commitlint/config-conventional": "^16.2.1",
64
+ "@commitlint/cli": "^17.0.0",
65
+ "@commitlint/config-conventional": "^17.0.0",
74
66
  "@semantic-release/changelog": "^6.0.1",
67
+ "@semantic-release/git": "^10.0.1",
68
+ "@semantic-release/github": "^8.0.4",
69
+ "@size-limit/preset-small-lib": "^7.0.8",
75
70
  "@types/jest": "^27.4.1",
76
71
  "@types/lodash": "^4.14.180",
77
72
  "@types/node": "^17.0.21",
78
- "@typescript-eslint/eslint-plugin": "^5.15.0",
79
- "@typescript-eslint/parser": "^5.15.0",
80
- "babel-jest": "^27.5.1",
81
- "dependency-check": "^4.1.0",
82
- "eslint": "^8.11.0",
83
- "eslint-plugin-harmony": "^6.0.0",
84
- "husky": "^7.0.4",
85
- "jest": "^27.5.1",
86
- "jest-junit": "^13.0.0",
87
- "jest-progress-tracker": "^3.0.3",
88
- "jest-validate": "^27.5.1",
89
- "jest-watch-repeat": "^2.0.0",
73
+ "@typescript-eslint/eslint-plugin": "^5.23.0",
74
+ "@typescript-eslint/parser": "^5.23.0",
75
+ "depcheck": "^1.4.3",
76
+ "eslint": "^8.16.0",
77
+ "eslint-config-prettier": "^8.5.0",
78
+ "eslint-plugin-harmony": "^7.1.0",
79
+ "husky": "^8.0.1",
80
+ "jest": "^28.1.0",
81
+ "jest-validate": "^28.1.0",
90
82
  "jest-watch-suspend": "^1.1.2",
91
83
  "jest-watch-toggle-config": "^2.0.1",
92
- "jest-watch-typeahead": "^1.0.0",
93
- "node-supported-releases": "^0.0.0",
84
+ "jest-watch-typeahead": "^1.1.0",
85
+ "lodash": "^4.17.21",
94
86
  "npm-run-all": "^4.1.5",
87
+ "pinst": "^3.0.0",
95
88
  "rimraf": "^3.0.2",
96
- "typescript": "^4.6.2",
97
- "update-notifier": "^5.1.0"
98
- }
89
+ "semantic-release": "^19.0.2",
90
+ "size-limit": "^7.0.8",
91
+ "ts-jest": "^28.0.3",
92
+ "typescript": "^4.7.2"
93
+ },
94
+ "packageManager": "yarn@3.2.1",
95
+ "size-limit": [
96
+ {
97
+ "path": "./esm/index.js",
98
+ "limit": "10 KB"
99
+ }
100
+ ]
99
101
  }
@@ -1,5 +1,5 @@
1
- import { InvalidOrder } from './InvalidOrder'
2
- import { StateMachine } from './StateMachine'
1
+ import { InvalidOrder } from './InvalidOrder.js'
2
+ import { StateMachine } from './StateMachine.js'
3
3
 
4
4
  // order.atLeast(step, count) // expected to be executed at least `count` times
5
5
  // order.atMost(step, count) // exected to be executed at most `count` times
@@ -1,5 +1,5 @@
1
- import { AssertionError } from '../errors'
2
- import { State } from './types'
1
+ import { AssertionError } from '../errors.js'
2
+ import { State } from './types.js'
3
3
 
4
4
  export class InvalidOrder extends AssertionError {
5
5
  constructor(public state: State, public method: string, public args: any[], options: AssertionError.Options) {
@@ -1,5 +1,5 @@
1
1
  import isNode from 'is-node'
2
- import { State } from './types'
2
+ import { State } from './types.js'
3
3
 
4
4
  // istanbul ignore next
5
5
  function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
@@ -0,0 +1,4 @@
1
+ export * from './AssertOrder.js'
2
+ export * from './InvalidOrder.js'
3
+ export * from './types.js'
4
+
File without changes
File without changes
@@ -0,0 +1,29 @@
1
+ import { AssertionError } from '../errors.js'
2
+ import { notEqualMessage } from '../utils/index.js'
3
+ import { falsy } from './falsy.js'
4
+ import { pathEqual } from './pathEqual.js'
5
+ import { rejects } from './rejects.js'
6
+ import { repeat } from './repeat.js'
7
+ import { resolves } from './resolves.js'
8
+ import { satisfies } from './satisfies.js'
9
+ import { throws } from './throws.js'
10
+ import { truthy } from './truthy.js'
11
+
12
+ export const assertron = {
13
+ false(value: any) {
14
+ if (value !== false)
15
+ throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
16
+ },
17
+ falsy,
18
+ pathEqual,
19
+ rejects,
20
+ repeat,
21
+ resolves,
22
+ satisfies,
23
+ throws,
24
+ true(value: any) {
25
+ if (value !== true)
26
+ throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
27
+ },
28
+ truthy
29
+ }
@@ -1,4 +1,4 @@
1
- import { AssertionError } from '../errors'
1
+ import { AssertionError } from '../errors.js'
2
2
 
3
3
  export function falsy(value: any) {
4
4
  if (value)
@@ -0,0 +1 @@
1
+ export * from './assertron.js'
@@ -1,6 +1,6 @@
1
1
  import { pathEqual as isPathEqual } from 'path-equal'
2
- import { AssertionError } from '../errors'
3
- import { notEqualMessage } from '../utils'
2
+ import { AssertionError } from '../errors.js'
3
+ import { notEqualMessage } from '../utils/index.js'
4
4
 
5
5
  export function pathEqual(actual: string, expected: string) {
6
6
  if (!isPathEqual(actual, expected))
@@ -1,5 +1,5 @@
1
- import { AssertionError } from '../errors'
2
- import { notRejectedMessage } from '../utils'
1
+ import { AssertionError } from '../errors.js'
2
+ import { notRejectedMessage } from '../utils/index.js'
3
3
 
4
4
  export function rejects(promise: Promise<any>) {
5
5
  return promise.then(
@@ -1,5 +1,5 @@
1
- import isPromise from 'is-promise';
2
- import { FailOnOccurrence } from '../errors';
1
+ import isPromise from 'is-promise'
2
+ import { FailOnOccurrence } from '../errors.js'
3
3
 
4
4
  /**
5
5
  * Repeat the specified function n times and return the last result.
@@ -1,5 +1,5 @@
1
- import { AssertionError } from '../errors'
2
- import { notResolvedMessage } from '../utils'
1
+ import { AssertionError } from '../errors.js'
2
+ import { notResolvedMessage } from '../utils/index.js'
3
3
 
4
4
  export function resolves(promise: Promise<any>) {
5
5
  return promise.then(
@@ -1,7 +1,7 @@
1
1
  import { createSatisfier } from 'satisfier'
2
2
  import { If, IsExtend, NonComposableTypes } from 'type-plus'
3
- import { AssertionError } from '../errors'
4
- import { notSatisfiedMessage } from '../utils'
3
+ import { AssertionError } from '../errors.js'
4
+ import { notSatisfiedMessage } from '../utils/index.js'
5
5
 
6
6
  export type SatisfyExpectation<T> = If<
7
7
  IsExtend<T, string>,
@@ -1,7 +1,7 @@
1
- import isPromise from 'is-promise';
2
- import { AssertionError } from '../errors';
3
- import { ErrorConstructor, ErrorValidator } from '../types';
4
- import { isErrorConstructor, notRejectedMessage, notThrownMessage, unexpectedErrorMessage } from '../utils';
1
+ import isPromise from 'is-promise'
2
+ import { AssertionError } from '../errors.js'
3
+ import { ErrorConstructor, ErrorValidator } from '../types.js'
4
+ import { isErrorConstructor, notRejectedMessage, notThrownMessage, unexpectedErrorMessage } from '../utils/index.js'
5
5
 
6
6
  export function throws<E extends Error>(value: PromiseLike<any>, error?: ErrorValidator | ErrorConstructor<E>): Promise<E>
7
7
  export function throws<E extends Error>(value: (...args: any[]) => never, error?: ErrorValidator | ErrorConstructor<E>): E
@@ -23,7 +23,7 @@ export function throws(value: PromiseLike<any> | (() => any | PromiseLike<any>),
23
23
  }
24
24
  return err
25
25
  }
26
- value = result;
26
+ value = result
27
27
  }
28
28
 
29
29
  if (isPromise(value)) {
@@ -1,4 +1,4 @@
1
- import { AssertionError } from '../errors';
1
+ import { AssertionError } from '../errors.js'
2
2
 
3
3
  export function truthy(value: any) {
4
4
  if (!value) throw new AssertionError(
@@ -1,6 +1,6 @@
1
1
  import { IsoError, ModuleError } from 'iso-error'
2
2
  import { RequiredPick } from 'type-plus'
3
- import { failOnOccurrence } from './utils'
3
+ import { failOnOccurrence } from './utils/index.js'
4
4
 
5
5
  /**
6
6
  * A base error for all assertion errors
package/ts/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { assertron } from './assertron/index.js'
2
+
3
+ export * from './assert-order/index.js'
4
+ export * from './assertron/index.js'
5
+ export * from './errors.js'
6
+ export default assertron
@@ -1,8 +1,8 @@
1
1
  // istanbul ignore file
2
2
  import t from 'assert'
3
3
  import isPromise from 'is-promise'
4
- import { isError } from 'lodash'
5
- import { ErrorConstructor } from './types'
4
+ import { escapeRegExp, isError } from 'lodash'
5
+ import { ErrorConstructor } from './types.js'
6
6
 
7
7
  export type AnyFunction = (...args: any[]) => any
8
8
 
@@ -79,6 +79,6 @@ export async function assertAsyncThrows<E extends Error>(fn: AnyFunction, ErrorT
79
79
 
80
80
 
81
81
  export function noStackTraceFor(filename: string, err: Error) {
82
- if (err.stack && RegExp(filename).test(err.stack))
82
+ if (err.stack && RegExp(escapeRegExp(filename)).test(err.stack))
83
83
  throw new Error(`contains internal stack: \n${err.stack}`)
84
84
  }
File without changes
@@ -0,0 +1,12 @@
1
+ import { tersify } from 'tersify'
2
+
3
+ export * from './isErrorConstructor.js'
4
+ export * from './notEqualMessage.js'
5
+ export * from './notSatisfiedMessage.js'
6
+ export * from './notThrownMessage.js'
7
+ export * from './promiseMessages.js'
8
+ export * from './unexpectedErrorMessage.js'
9
+
10
+ export function failOnOccurrence(occurrence: number, error: any) {
11
+ return `Failed on ${occurrence} occurrence: ${tersify(error, { maxLength: Infinity })}`
12
+ }
@@ -1,4 +1,4 @@
1
- import { ErrorConstructor } from '../types'
1
+ import { ErrorConstructor } from '../types.js'
2
2
 
3
3
  export function isErrorConstructor(validator: any): validator is ErrorConstructor<any> {
4
4
  return Object.prototype.isPrototypeOf.call(Error.prototype, validator.prototype)
@@ -1,4 +1,3 @@
1
-
2
1
  export function notEqualMessage(actual: any, expected: any) {
3
2
  return `Expected value to equal ${expected}, but received ${actual}`
4
3
  }
@@ -1,5 +1,5 @@
1
- import { Diff } from 'satisfier';
2
- import { tersify } from 'tersify';
1
+ import { Diff } from 'satisfier'
2
+ import { tersify } from 'tersify'
3
3
 
4
4
  export function notSatisfiedMessage(entries: Diff[]) {
5
5
  return entries.map(e => {
File without changes
File without changes
@@ -1,6 +1,6 @@
1
- import { tersify } from 'tersify';
2
- import { ErrorConstructor, ErrorValidator } from '../types';
3
- import { isErrorConstructor } from './isErrorConstructor';
1
+ import { tersify } from 'tersify'
2
+ import { ErrorConstructor, ErrorValidator } from '../types.js'
3
+ import { isErrorConstructor } from './isErrorConstructor.js'
4
4
 
5
5
  export function unexpectedErrorMessage(actual: any, expected: ErrorValidator | ErrorConstructor<any>) {
6
6
  return `Unexpected error. Expecting '${isErrorConstructor(expected) ?
@@ -1,41 +0,0 @@
1
- export declare class AssertOrder {
2
- /**
3
- * Gets the current expecting step.
4
- */
5
- get currentStep(): number;
6
- private state;
7
- constructor(plan?: number);
8
- /**
9
- * Asserts the current step is `step`.
10
- * @param step expected step.
11
- */
12
- is(step: number): void;
13
- /**
14
- * Asserts the current step is not `step`.
15
- * @param step not expected step.
16
- */
17
- not(step: number): void;
18
- /**
19
- * Reset to specified step.
20
- */
21
- jump(step: number): void;
22
- /**
23
- * Move to next step.
24
- */
25
- move(): void;
26
- /**
27
- * Asserts the specified step will run once.
28
- */
29
- once(step: number): void;
30
- on(step: number, assert: (step: number) => void): void;
31
- atLeastOnce(step: number): number;
32
- any(steps: number[]): number;
33
- onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>): void;
34
- end(timeout: number): Promise<number>;
35
- end(): number;
36
- exactly(step: number, times: number): number;
37
- wait(step: number): Promise<void>;
38
- wait(step: number, callback: () => void): void;
39
- private assert;
40
- }
41
- //# sourceMappingURL=AssertOrder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AssertOrder.d.ts","sourceRoot":"","sources":["../../src/assert-order/AssertOrder.ts"],"names":[],"mappings":"AAMA,qBAAa,WAAW;IACtB;;OAEG;IACH,IAAI,WAAW,WAEd;IAED,OAAO,CAAC,KAAK,CAAc;gBACf,IAAI,CAAC,EAAE,MAAM;IAIzB;;;OAGG;IACH,EAAE,CAAC,IAAI,EAAE,MAAM;IAIf;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM;IAMhB;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM;IAIjB;;OAEG;IACH,IAAI;IAIJ;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM;IAKjB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI;IAM/C,WAAW,CAAC,IAAI,EAAE,MAAM;IAaxB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE;IAQnB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,OAAO,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;IAoBjE,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACrC,GAAG,IAAI,MAAM;IAmBb,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAWnC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IACjC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAO9C,OAAO,CAAC,MAAM;CAKf"}
@@ -1,9 +0,0 @@
1
- import { AssertionError } from '../errors';
2
- import { State } from './types';
3
- export declare class InvalidOrder extends AssertionError {
4
- state: State;
5
- method: string;
6
- args: any[];
7
- constructor(state: State, method: string, args: any[], options: AssertionError.Options);
8
- }
9
- //# sourceMappingURL=InvalidOrder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InvalidOrder.d.ts","sourceRoot":"","sources":["../../src/assert-order/InvalidOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,qBAAa,YAAa,SAAQ,cAAc;IAC3B,KAAK,EAAE,KAAK;IAAS,MAAM,EAAE,MAAM;IAAS,IAAI,EAAE,GAAG,EAAE;gBAAvD,KAAK,EAAE,KAAK,EAAS,MAAM,EAAE,MAAM,EAAS,IAAI,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,cAAc,CAAC,OAAO;CAG5G"}
@@ -1,22 +0,0 @@
1
- import { State } from './types';
2
- export declare class StateMachine {
3
- listeners: Record<number, Array<() => void>>;
4
- step: number;
5
- maxStep?: number;
6
- subStep: number;
7
- minSubStep?: number;
8
- maxSubStep?: number;
9
- constructor(maxStep?: number);
10
- jump(step: number): number;
11
- move(): number;
12
- moveSubStep(): number;
13
- get(): State;
14
- on(step: number, listener: () => void): void;
15
- isNotValid(step: number): boolean;
16
- isValid(step: number): boolean;
17
- isMaxStepDefined(): boolean;
18
- stopAccepting(): void;
19
- isAccepting(): boolean;
20
- getTimeTaken(): number;
21
- }
22
- //# sourceMappingURL=StateMachine.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StateMachine.d.ts","sourceRoot":"","sources":["../../src/assert-order/StateMachine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AA4C/B,qBAAa,YAAY;IACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC,CAAK;IACjD,IAAI,SAAI;IACR,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,OAAO,SAAI;IACX,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;gBACP,OAAO,CAAC,EAAE,MAAM;IAI5B,IAAI,CAAC,IAAI,EAAE,MAAM;IAKjB,IAAI;IASJ,WAAW;IAMX,GAAG,IAAI,KAAK;IAUZ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI;IAGrC,UAAU,CAAC,IAAI,EAAE,MAAM;IAGvB,OAAO,CAAC,IAAI,EAAE,MAAM;IAGpB,gBAAgB;IAGhB,aAAa;IAGb,WAAW;IAIX,YAAY;CAGb"}
@@ -1,4 +0,0 @@
1
- export * from './AssertOrder';
2
- export * from './InvalidOrder';
3
- export * from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/assert-order/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,SAAS,CAAA"}
@@ -1,8 +0,0 @@
1
- export interface State {
2
- step: number;
3
- maxStep?: number;
4
- subStep: number;
5
- minSubStep?: number;
6
- maxSubStep?: number;
7
- }
8
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/assert-order/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -1,21 +0,0 @@
1
- import { falsy } from './falsy';
2
- import { pathEqual } from './pathEqual';
3
- import { rejects } from './rejects';
4
- import { repeat } from './repeat';
5
- import { resolves } from './resolves';
6
- import { satisfies } from './satisfies';
7
- import { throws } from './throws';
8
- import { truthy } from './truthy';
9
- export declare const assertron: {
10
- false(value: any): void;
11
- falsy: typeof falsy;
12
- pathEqual: typeof pathEqual;
13
- rejects: typeof rejects;
14
- repeat: typeof repeat;
15
- resolves: typeof resolves;
16
- satisfies: typeof satisfies;
17
- throws: typeof throws;
18
- true(value: any): void;
19
- truthy: typeof truthy;
20
- };
21
- //# sourceMappingURL=assertron.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assertron.d.ts","sourceRoot":"","sources":["../../src/assertron/assertron.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,eAAO,MAAM,SAAS;iBACP,GAAG;;;;;;;;gBAWJ,GAAG;;CAKhB,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare function falsy(value: any): void;
2
- //# sourceMappingURL=falsy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"falsy.d.ts","sourceRoot":"","sources":["../../src/assertron/falsy.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,CAAC,KAAK,EAAE,GAAG,QAG/B"}
@@ -1,2 +0,0 @@
1
- export * from './assertron';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/assertron/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare function pathEqual(actual: string, expected: string): void;
2
- //# sourceMappingURL=pathEqual.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pathEqual.d.ts","sourceRoot":"","sources":["../../src/assertron/pathEqual.ts"],"names":[],"mappings":"AAIA,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAGzD"}
@@ -1,2 +0,0 @@
1
- export declare function rejects(promise: Promise<any>): Promise<void>;
2
- //# sourceMappingURL=rejects.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rejects.d.ts","sourceRoot":"","sources":["../../src/assertron/rejects.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,iBAK5C"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Repeat the specified function n times and return the last result.
3
- * If the result is a promise, it will run the function sequentially.
4
- */
5
- export declare function repeat<R>(fn: () => R | (() => Promise<R>), times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R;
6
- //# sourceMappingURL=repeat.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/assertron/repeat.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAEpI"}
@@ -1,2 +0,0 @@
1
- export declare function resolves(promise: Promise<any>): Promise<void>;
2
- //# sourceMappingURL=resolves.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolves.d.ts","sourceRoot":"","sources":["../../src/assertron/resolves.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,iBAK7C"}
@@ -1,10 +0,0 @@
1
- import { If, IsExtend, NonComposableTypes } from 'type-plus';
2
- export declare type SatisfyExpectation<T> = If<IsExtend<T, string>, T | RegExp, If<IsExtend<T, NonComposableTypes>, T, If<IsExtend<T, Array<any>>, T extends Array<infer E> ? Array<SatisfyExpectation<E>> : never, {
3
- [P in keyof T]?: T[P] extends string ? SatisfyExpectation<T[P]> | RegExp : SatisfyExpectation<T[P]>;
4
- }>>> | ((v: T) => boolean);
5
- /**
6
- * Check if `actual` satisfies criteria in `expected`.
7
- * @param expected All properties can be a value which will be compared to the same property in `actual`, RegExp, or a predicate function that will be used to check against the property.
8
- */
9
- export declare function satisfies<Actual, Expected extends Actual>(actual: Actual, expected: SatisfyExpectation<Expected>): void;
10
- //# sourceMappingURL=satisfies.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"satisfies.d.ts","sourceRoot":"","sources":["../../src/assertron/satisfies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAI5D,oBAAY,kBAAkB,CAAC,CAAC,IAAI,EAAE,CACpC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,EACnB,CAAC,GAAG,MAAM,EACV,EAAE,CACA,QAAQ,CAAC,CAAC,EAAE,kBAAkB,CAAC,EAC/B,CAAC,EACD,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EACxB,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,EAC/D;KACG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAClC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,GACjC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC3B,CACF,CAAC,CACL,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAA;AAEvB;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,CAAC,QAAQ,CAAC,QAKhH"}
@@ -1,6 +0,0 @@
1
- import { ErrorConstructor, ErrorValidator } from '../types';
2
- export declare function throws<E extends Error>(value: PromiseLike<any>, error?: ErrorValidator | ErrorConstructor<E>): Promise<E>;
3
- export declare function throws<E extends Error>(value: (...args: any[]) => never, error?: ErrorValidator | ErrorConstructor<E>): E;
4
- export declare function throws<E extends Error, R = any>(value: (...args: any[]) => R, error?: ErrorValidator | ErrorConstructor<E>): R extends Promise<any> ? Promise<E> : E;
5
- export declare function throws<T, R = any>(value: (...args: any[]) => R, validator?: ErrorValidator): R extends Promise<any> ? Promise<T> : T;
6
- //# sourceMappingURL=throws.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"throws.d.ts","sourceRoot":"","sources":["../../src/assertron/throws.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG5D,wBAAgB,MAAM,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;AAC1H,wBAAgB,MAAM,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,EAAE,KAAK,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAC1H,wBAAgB,MAAM,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AACrK,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,EAAE,cAAc,GAAG,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare function truthy(value: any): void;
2
- //# sourceMappingURL=truthy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"truthy.d.ts","sourceRoot":"","sources":["../../src/assertron/truthy.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,QAKhC"}