assertron 7.1.1 → 9.0.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 (279) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +61 -46
  3. package/{dist-es2015 → cjs}/assert-order/AssertOrder.d.ts +3 -2
  4. package/cjs/assert-order/AssertOrder.d.ts.map +1 -0
  5. package/cjs/assert-order/AssertOrder.js +148 -0
  6. package/cjs/assert-order/InvalidOrder.d.ts +9 -0
  7. package/cjs/assert-order/InvalidOrder.d.ts.map +1 -0
  8. package/cjs/assert-order/InvalidOrder.js +39 -0
  9. package/{dist-es5 → cjs}/assert-order/StateMachine.d.ts +5 -6
  10. package/cjs/assert-order/StateMachine.d.ts.map +1 -0
  11. package/cjs/assert-order/StateMachine.js +111 -0
  12. package/cjs/assert-order/index.d.ts +4 -0
  13. package/cjs/assert-order/index.d.ts.map +1 -0
  14. package/cjs/assert-order/index.js +7 -0
  15. package/{dist-es2015/assert-order/interfaces.d.ts → cjs/assert-order/types.d.ts} +1 -0
  16. package/cjs/assert-order/types.d.ts.map +1 -0
  17. package/cjs/assert-order/types.js +3 -0
  18. package/{dist-es2015 → cjs}/assertron/assertron.d.ts +1 -0
  19. package/cjs/assertron/assertron.d.ts.map +1 -0
  20. package/cjs/assertron/assertron.js +32 -0
  21. package/{dist-es2015 → cjs}/assertron/falsy.d.ts +1 -0
  22. package/cjs/assertron/falsy.d.ts.map +1 -0
  23. package/cjs/assertron/falsy.js +10 -0
  24. package/cjs/assertron/index.d.ts +2 -0
  25. package/cjs/assertron/index.d.ts.map +1 -0
  26. package/cjs/assertron/index.js +5 -0
  27. package/{dist-es2015 → cjs}/assertron/pathEqual.d.ts +1 -0
  28. package/cjs/assertron/pathEqual.d.ts.map +1 -0
  29. package/cjs/assertron/pathEqual.js +12 -0
  30. package/{dist-es2015 → cjs}/assertron/rejects.d.ts +1 -0
  31. package/cjs/assertron/rejects.d.ts.map +1 -0
  32. package/cjs/assertron/rejects.js +10 -0
  33. package/{dist-es2015 → cjs}/assertron/repeat.d.ts +1 -6
  34. package/cjs/assertron/repeat.d.ts.map +1 -0
  35. package/cjs/assertron/repeat.js +33 -0
  36. package/{dist-es2015 → cjs}/assertron/resolves.d.ts +1 -0
  37. package/cjs/assertron/resolves.d.ts.map +1 -0
  38. package/cjs/assertron/resolves.js +10 -0
  39. package/cjs/assertron/satisfies.d.ts +10 -0
  40. package/cjs/assertron/satisfies.d.ts.map +1 -0
  41. package/cjs/assertron/satisfies.js +18 -0
  42. package/{dist-es2015 → cjs}/assertron/throws.d.ts +3 -1
  43. package/cjs/assertron/throws.d.ts.map +1 -0
  44. package/cjs/assertron/throws.js +56 -0
  45. package/{dist-es2015 → cjs}/assertron/truthy.d.ts +1 -0
  46. package/cjs/assertron/truthy.d.ts.map +1 -0
  47. package/cjs/assertron/truthy.js +10 -0
  48. package/cjs/errors.d.ts +17 -0
  49. package/cjs/errors.d.ts.map +1 -0
  50. package/cjs/errors.js +29 -0
  51. package/{dist-es5 → cjs}/index.d.ts +3 -1
  52. package/cjs/index.d.ts.map +1 -0
  53. package/cjs/index.js +9 -0
  54. package/{dist-es2015/errors/interfaces.d.ts → cjs/types.d.ts} +1 -0
  55. package/cjs/types.d.ts.map +1 -0
  56. package/cjs/types.js +3 -0
  57. package/cjs/utils/index.d.ts +8 -0
  58. package/cjs/utils/index.d.ts.map +1 -0
  59. package/cjs/utils/index.js +16 -0
  60. package/{dist-es2015/errors/util.d.ts → cjs/utils/isErrorConstructor.d.ts} +2 -1
  61. package/cjs/utils/isErrorConstructor.d.ts.map +1 -0
  62. package/cjs/utils/isErrorConstructor.js +8 -0
  63. package/{dist-es2015/errors → cjs/utils}/notEqualMessage.d.ts +1 -0
  64. package/cjs/utils/notEqualMessage.d.ts.map +1 -0
  65. package/cjs/utils/notEqualMessage.js +8 -0
  66. package/{dist-es2015/errors/NotSatisfied.d.ts → cjs/utils/notSatisfiedMessage.d.ts} +1 -0
  67. package/cjs/utils/notSatisfiedMessage.d.ts.map +1 -0
  68. package/cjs/utils/notSatisfiedMessage.js +28 -0
  69. package/{dist-es2015/errors → cjs/utils}/notThrownMessage.d.ts +1 -0
  70. package/cjs/utils/notThrownMessage.d.ts.map +1 -0
  71. package/cjs/utils/notThrownMessage.js +9 -0
  72. package/cjs/utils/promiseMessages.d.ts +3 -0
  73. package/cjs/utils/promiseMessages.d.ts.map +1 -0
  74. package/cjs/utils/promiseMessages.js +15 -0
  75. package/{dist-es2015/errors → cjs/utils}/unexpectedErrorMessage.d.ts +2 -1
  76. package/cjs/utils/unexpectedErrorMessage.d.ts.map +1 -0
  77. package/cjs/utils/unexpectedErrorMessage.js +11 -0
  78. package/esm/assert-order/AssertOrder.js +132 -0
  79. package/esm/assert-order/InvalidOrder.js +31 -0
  80. package/esm/assert-order/StateMachine.js +103 -0
  81. package/esm/assert-order/index.js +4 -0
  82. package/esm/assert-order/types.js +2 -0
  83. package/esm/assertron/assertron.js +29 -0
  84. package/esm/assertron/falsy.js +6 -0
  85. package/esm/assertron/index.js +2 -0
  86. package/esm/assertron/pathEqual.js +8 -0
  87. package/esm/assertron/rejects.js +6 -0
  88. package/esm/assertron/repeat.js +28 -0
  89. package/esm/assertron/resolves.js +6 -0
  90. package/esm/assertron/satisfies.js +14 -0
  91. package/esm/assertron/throws.js +51 -0
  92. package/esm/assertron/truthy.js +6 -0
  93. package/esm/errors.js +18 -0
  94. package/esm/index.js +6 -0
  95. package/esm/types.js +2 -0
  96. package/esm/utils/index.js +11 -0
  97. package/esm/utils/isErrorConstructor.js +4 -0
  98. package/esm/utils/notEqualMessage.js +4 -0
  99. package/esm/utils/notSatisfiedMessage.js +23 -0
  100. package/esm/utils/notThrownMessage.js +5 -0
  101. package/esm/utils/promiseMessages.js +10 -0
  102. package/esm/utils/unexpectedErrorMessage.js +7 -0
  103. package/package.json +62 -24
  104. package/src/assert-order/AssertOrder.spec.ts +10 -12
  105. package/src/assert-order/AssertOrder.ts +8 -8
  106. package/src/assert-order/InvalidOrder.ts +7 -12
  107. package/src/assert-order/StateMachine.ts +26 -31
  108. package/src/assert-order/index.ts +3 -1
  109. package/src/assert-order/internalInterfaces.ts +3 -3
  110. package/src/assert-order/types.ts +7 -0
  111. package/src/assertron/assertron.spec.ts +2 -4
  112. package/src/assertron/assertron.ts +13 -14
  113. package/src/assertron/falsy.spec.ts +2 -3
  114. package/src/assertron/falsy.ts +2 -6
  115. package/src/assertron/pathEqual.spec.ts +2 -3
  116. package/src/assertron/pathEqual.ts +4 -7
  117. package/src/assertron/rejects.spec.ts +7 -8
  118. package/src/assertron/rejects.ts +3 -11
  119. package/src/assertron/repeat.spec.ts +8 -10
  120. package/src/assertron/repeat.ts +4 -9
  121. package/src/assertron/resolves.spec.ts +3 -4
  122. package/src/assertron/resolves.ts +3 -13
  123. package/src/assertron/satisfies.spec.ts +57 -26
  124. package/src/assertron/satisfies.ts +23 -10
  125. package/src/assertron/throws.spec.ts +63 -39
  126. package/src/assertron/throws.ts +32 -55
  127. package/src/assertron/truthy.spec.ts +2 -3
  128. package/src/assertron/truthy.ts +2 -3
  129. package/src/errors.ts +22 -0
  130. package/src/index.ts +2 -1
  131. package/src/testUtils.ts +16 -13
  132. package/src/{errors/interfaces.ts → types.ts} +1 -1
  133. package/src/utils/index.ts +12 -0
  134. package/src/utils/isErrorConstructor.ts +5 -0
  135. package/src/utils/notEqualMessage.ts +4 -0
  136. package/src/{errors → utils}/notSatisfiedMessage.spec.ts +0 -0
  137. package/src/{errors/NotSatisfied.ts → utils/notSatisfiedMessage.ts} +1 -1
  138. package/src/utils/notThrownMessage.ts +5 -0
  139. package/src/utils/promiseMessages.ts +12 -0
  140. package/src/{errors → utils}/unexpectedErrorMessage.ts +4 -3
  141. package/dist-es2015/assert-order/AssertOrder.js +0 -132
  142. package/dist-es2015/assert-order/AssertOrder.js.map +0 -1
  143. package/dist-es2015/assert-order/InvalidOrder.d.ts +0 -8
  144. package/dist-es2015/assert-order/InvalidOrder.js +0 -31
  145. package/dist-es2015/assert-order/InvalidOrder.js.map +0 -1
  146. package/dist-es2015/assert-order/StateMachine.d.ts +0 -23
  147. package/dist-es2015/assert-order/StateMachine.js +0 -106
  148. package/dist-es2015/assert-order/StateMachine.js.map +0 -1
  149. package/dist-es2015/assert-order/index.d.ts +0 -2
  150. package/dist-es2015/assert-order/index.js +0 -2
  151. package/dist-es2015/assert-order/index.js.map +0 -1
  152. package/dist-es2015/assert-order/interfaces.js +0 -1
  153. package/dist-es2015/assert-order/interfaces.js.map +0 -1
  154. package/dist-es2015/assertron/assertron.js +0 -28
  155. package/dist-es2015/assertron/assertron.js.map +0 -1
  156. package/dist-es2015/assertron/falsy.js +0 -6
  157. package/dist-es2015/assertron/falsy.js.map +0 -1
  158. package/dist-es2015/assertron/index.d.ts +0 -1
  159. package/dist-es2015/assertron/index.js +0 -2
  160. package/dist-es2015/assertron/index.js.map +0 -1
  161. package/dist-es2015/assertron/pathEqual.js +0 -8
  162. package/dist-es2015/assertron/pathEqual.js.map +0 -1
  163. package/dist-es2015/assertron/rejects.js +0 -10
  164. package/dist-es2015/assertron/rejects.js.map +0 -1
  165. package/dist-es2015/assertron/repeat.js +0 -35
  166. package/dist-es2015/assertron/repeat.js.map +0 -1
  167. package/dist-es2015/assertron/resolves.js +0 -12
  168. package/dist-es2015/assertron/resolves.js.map +0 -1
  169. package/dist-es2015/assertron/satisfies.d.ts +0 -5
  170. package/dist-es2015/assertron/satisfies.js +0 -14
  171. package/dist-es2015/assertron/satisfies.js.map +0 -1
  172. package/dist-es2015/assertron/throws.js +0 -55
  173. package/dist-es2015/assertron/throws.js.map +0 -1
  174. package/dist-es2015/assertron/truthy.js +0 -6
  175. package/dist-es2015/assertron/truthy.js.map +0 -1
  176. package/dist-es2015/errors/NotSatisfied.js +0 -23
  177. package/dist-es2015/errors/NotSatisfied.js.map +0 -1
  178. package/dist-es2015/errors/index.d.ts +0 -7
  179. package/dist-es2015/errors/index.js +0 -7
  180. package/dist-es2015/errors/index.js.map +0 -1
  181. package/dist-es2015/errors/interfaces.js +0 -1
  182. package/dist-es2015/errors/interfaces.js.map +0 -1
  183. package/dist-es2015/errors/notEqualMessage.js +0 -4
  184. package/dist-es2015/errors/notEqualMessage.js.map +0 -1
  185. package/dist-es2015/errors/notRejectedMessage.d.ts +0 -1
  186. package/dist-es2015/errors/notRejectedMessage.js +0 -4
  187. package/dist-es2015/errors/notRejectedMessage.js.map +0 -1
  188. package/dist-es2015/errors/notThrownMessage.js +0 -4
  189. package/dist-es2015/errors/notThrownMessage.js.map +0 -1
  190. package/dist-es2015/errors/returnNotRejectedMessage.d.ts +0 -1
  191. package/dist-es2015/errors/returnNotRejectedMessage.js +0 -4
  192. package/dist-es2015/errors/returnNotRejectedMessage.js.map +0 -1
  193. package/dist-es2015/errors/unexpectedErrorMessage.js +0 -6
  194. package/dist-es2015/errors/unexpectedErrorMessage.js.map +0 -1
  195. package/dist-es2015/errors/util.js +0 -4
  196. package/dist-es2015/errors/util.js.map +0 -1
  197. package/dist-es2015/index.d.ts +0 -4
  198. package/dist-es2015/index.js +0 -5
  199. package/dist-es2015/index.js.map +0 -1
  200. package/dist-es5/assert-order/AssertOrder.d.ts +0 -40
  201. package/dist-es5/assert-order/AssertOrder.js +0 -147
  202. package/dist-es5/assert-order/AssertOrder.js.map +0 -1
  203. package/dist-es5/assert-order/InvalidOrder.d.ts +0 -8
  204. package/dist-es5/assert-order/InvalidOrder.js +0 -58
  205. package/dist-es5/assert-order/InvalidOrder.js.map +0 -1
  206. package/dist-es5/assert-order/StateMachine.js +0 -115
  207. package/dist-es5/assert-order/StateMachine.js.map +0 -1
  208. package/dist-es5/assert-order/index.d.ts +0 -2
  209. package/dist-es5/assert-order/index.js +0 -7
  210. package/dist-es5/assert-order/index.js.map +0 -1
  211. package/dist-es5/assert-order/interfaces.d.ts +0 -7
  212. package/dist-es5/assert-order/interfaces.js +0 -3
  213. package/dist-es5/assert-order/interfaces.js.map +0 -1
  214. package/dist-es5/assertron/assertron.d.ts +0 -20
  215. package/dist-es5/assertron/assertron.js +0 -33
  216. package/dist-es5/assertron/assertron.js.map +0 -1
  217. package/dist-es5/assertron/falsy.d.ts +0 -1
  218. package/dist-es5/assertron/falsy.js +0 -12
  219. package/dist-es5/assertron/falsy.js.map +0 -1
  220. package/dist-es5/assertron/index.d.ts +0 -1
  221. package/dist-es5/assertron/index.js +0 -7
  222. package/dist-es5/assertron/index.js.map +0 -1
  223. package/dist-es5/assertron/pathEqual.d.ts +0 -1
  224. package/dist-es5/assertron/pathEqual.js +0 -14
  225. package/dist-es5/assertron/pathEqual.js.map +0 -1
  226. package/dist-es5/assertron/rejects.d.ts +0 -1
  227. package/dist-es5/assertron/rejects.js +0 -16
  228. package/dist-es5/assertron/rejects.js.map +0 -1
  229. package/dist-es5/assertron/repeat.d.ts +0 -11
  230. package/dist-es5/assertron/repeat.js +0 -58
  231. package/dist-es5/assertron/repeat.js.map +0 -1
  232. package/dist-es5/assertron/resolves.d.ts +0 -1
  233. package/dist-es5/assertron/resolves.js +0 -18
  234. package/dist-es5/assertron/resolves.js.map +0 -1
  235. package/dist-es5/assertron/satisfies.d.ts +0 -5
  236. package/dist-es5/assertron/satisfies.js +0 -20
  237. package/dist-es5/assertron/satisfies.js.map +0 -1
  238. package/dist-es5/assertron/throws.d.ts +0 -4
  239. package/dist-es5/assertron/throws.js +0 -61
  240. package/dist-es5/assertron/throws.js.map +0 -1
  241. package/dist-es5/assertron/truthy.d.ts +0 -1
  242. package/dist-es5/assertron/truthy.js +0 -12
  243. package/dist-es5/assertron/truthy.js.map +0 -1
  244. package/dist-es5/errors/NotSatisfied.d.ts +0 -2
  245. package/dist-es5/errors/NotSatisfied.js +0 -26
  246. package/dist-es5/errors/NotSatisfied.js.map +0 -1
  247. package/dist-es5/errors/index.d.ts +0 -7
  248. package/dist-es5/errors/index.js +0 -12
  249. package/dist-es5/errors/index.js.map +0 -1
  250. package/dist-es5/errors/interfaces.d.ts +0 -2
  251. package/dist-es5/errors/interfaces.js +0 -3
  252. package/dist-es5/errors/interfaces.js.map +0 -1
  253. package/dist-es5/errors/notEqualMessage.d.ts +0 -1
  254. package/dist-es5/errors/notEqualMessage.js +0 -7
  255. package/dist-es5/errors/notEqualMessage.js.map +0 -1
  256. package/dist-es5/errors/notRejectedMessage.d.ts +0 -1
  257. package/dist-es5/errors/notRejectedMessage.js +0 -7
  258. package/dist-es5/errors/notRejectedMessage.js.map +0 -1
  259. package/dist-es5/errors/notThrownMessage.d.ts +0 -1
  260. package/dist-es5/errors/notThrownMessage.js +0 -7
  261. package/dist-es5/errors/notThrownMessage.js.map +0 -1
  262. package/dist-es5/errors/returnNotRejectedMessage.d.ts +0 -1
  263. package/dist-es5/errors/returnNotRejectedMessage.js +0 -7
  264. package/dist-es5/errors/returnNotRejectedMessage.js.map +0 -1
  265. package/dist-es5/errors/unexpectedErrorMessage.d.ts +0 -2
  266. package/dist-es5/errors/unexpectedErrorMessage.js +0 -9
  267. package/dist-es5/errors/unexpectedErrorMessage.js.map +0 -1
  268. package/dist-es5/errors/util.d.ts +0 -2
  269. package/dist-es5/errors/util.js +0 -7
  270. package/dist-es5/errors/util.js.map +0 -1
  271. package/dist-es5/index.js +0 -10
  272. package/dist-es5/index.js.map +0 -1
  273. package/src/assert-order/interfaces.ts +0 -7
  274. package/src/errors/index.ts +0 -7
  275. package/src/errors/notEqualMessage.ts +0 -3
  276. package/src/errors/notRejectedMessage.ts +0 -3
  277. package/src/errors/notThrownMessage.ts +0 -3
  278. package/src/errors/returnNotRejectedMessage.ts +0 -3
  279. package/src/errors/util.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assertron",
3
- "version": "7.1.1",
3
+ "version": "9.0.0",
4
4
  "description": "A supplementary assertion library",
5
5
  "homepage": "https://github.com/unional/assertron",
6
6
  "bugs": {
@@ -15,41 +15,79 @@
15
15
  "name": "Homa Wong",
16
16
  "email": "homawong@gmail.com"
17
17
  },
18
+ "sideEffects": false,
19
+ "main": "cjs/index.js",
20
+ "module": "esm/index.js",
21
+ "jsnext:main": "esm/index.js",
22
+ "browser": {
23
+ "perf_hooks": false
24
+ },
25
+ "typings": "cjs/index.d.ts",
18
26
  "files": [
19
- "dist",
20
- "dist-es5",
21
- "dist-es2015",
27
+ "cjs",
28
+ "esm",
22
29
  "src"
23
30
  ],
24
- "main": "dist-es5/index.js",
25
- "module": "dist-es2015/index.js",
26
- "typings": "dist-es5/index.d.ts",
27
31
  "scripts": {
28
- "build": "npm run build-es5 && npm run build-es2015",
29
- "build-es2015": "tsc -p tsconfig.es2015.json",
30
- "build-es5": "tsc -p tsconfig.es5.json",
31
- "clean": "rimraf dist dist-es5 dist-es2015",
32
+ "build": "yarn build:esm && yarn build:cjs",
33
+ "build:cjs": "tsc -p tsconfig.cjs.json",
34
+ "build:esm": "tsc -p tsconfig.esm.json",
35
+ "build:watch": "tsc --watch",
36
+ "clean": "rimraf .nyc_output .ts coverage cjs esm",
32
37
  "coverage": "jest --coverage",
33
- "dependency-check": "dependency-check . --unused --no-dev && dependency-check . --missing --no-dev -i perf_hooks",
34
- "lint": "tslint -p tsconfig.json",
38
+ "depcheck": "yarn dependency-check",
39
+ "dependency-check": "dependency-check . --unused --no-dev -i type-plus -i global-store -i @types/node -i standard-log-color && dependency-check . --missing --no-dev",
40
+ "lint": "eslint --ext=js,ts .",
41
+ "nuke": "yarn clean && rimraf node_modules",
35
42
  "test": "jest",
36
- "verify": "npm run lint && npm run build && npm run dependency-check && npm run coverage",
37
- "watch": "jest --watch"
43
+ "test:watch": "jest --watch",
44
+ "verify": "yarn lint && yarn build && yarn dependency-check && yarn coverage",
45
+ "watch": "yarn test:watch"
38
46
  },
39
- "browser": {
40
- "perf_hooks": false
47
+ "husky": {
48
+ "hooks": {
49
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
50
+ }
41
51
  },
42
52
  "dependencies": {
43
- "assertion-error": "^1.1.0",
44
53
  "is-node": "^1.0.2",
45
- "is-promise": "^2.1.0",
54
+ "is-promise": "^4.0.0",
55
+ "iso-error": "^4.1.0",
46
56
  "path-equal": "^1.1.1",
47
- "satisfier": "^5.0.2",
48
- "tersify": "^3.0.1"
57
+ "satisfier": "^5.1.1",
58
+ "tersify": "^3.7.9",
59
+ "tslib": "^2.3.1",
60
+ "type-plus": "^3.14.0"
49
61
  },
50
62
  "devDependencies": {
51
- "@types/lodash": "^4.14.126",
52
- "@unional/devpkg-node": "^1.3.0",
53
- "lodash": "^4.17.11"
63
+ "@babel/core": "^7.16.5",
64
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
65
+ "@babel/plugin-proposal-optional-chaining": "^7.16.5",
66
+ "@babel/preset-env": "^7.16.5",
67
+ "@babel/preset-typescript": "^7.16.5",
68
+ "@commitlint/cli": "^15.0.0",
69
+ "@commitlint/config-conventional": "^15.0.0",
70
+ "@types/jest": "^27.0.3",
71
+ "@types/lodash": "^4.14.178",
72
+ "@types/node": "^17.0.4",
73
+ "@typescript-eslint/eslint-plugin": "^5.8.0",
74
+ "@typescript-eslint/parser": "^5.8.0",
75
+ "babel-jest": "^27.4.5",
76
+ "dependency-check": "^4.1.0",
77
+ "eslint": "^8.5.0",
78
+ "eslint-plugin-harmony": "^6.0.0",
79
+ "husky": "^7.0.4",
80
+ "jest": "^27.4.5",
81
+ "jest-junit": "^13.0.0",
82
+ "jest-progress-tracker": "^3.0.1",
83
+ "jest-validate": "^27.4.2",
84
+ "jest-watch-repeat": "^2.0.0",
85
+ "jest-watch-suspend": "^1.1.2",
86
+ "jest-watch-toggle-config": "^2.0.1",
87
+ "jest-watch-typeahead": "^1.0.0",
88
+ "node-supported-releases": "^0.0.0",
89
+ "rimraf": "^3.0.2",
90
+ "typescript": "^4.5.4",
91
+ "update-notifier": "^5.1.0"
54
92
  }
55
93
  }
@@ -1,7 +1,5 @@
1
-
2
1
  import t from 'assert';
3
- import AssertionError from 'assertion-error';
4
- import a, { AssertOrder, State } from '..';
2
+ import a, { AssertOrder, InvalidOrder, State } from '..';
5
3
 
6
4
  test('is() expecting 1', () => {
7
5
  const order = new AssertOrder()
@@ -256,7 +254,7 @@ test(`onAny() throws if all assert functions throws`, () => {
256
254
  test('AssertOrder(0) accepts no step >= 1', () => {
257
255
  const order = new AssertOrder(0)
258
256
 
259
- const err = a.throws(() => order.once(1)) as AssertionError<{ state: any }>
257
+ const err = a.throws(() => order.once(1), InvalidOrder)
260
258
 
261
259
  t.strictEqual(err.state.maxStep, 0)
262
260
  })
@@ -266,7 +264,7 @@ test('AssertOrder(1) accepts step 1 but not 2', () => {
266
264
 
267
265
  order.once(1)
268
266
 
269
- const err = a.throws(() => order.once(2)) as AssertionError<{ state: any }>
267
+ const err = a.throws(() => order.once(2), InvalidOrder)
270
268
 
271
269
  t.strictEqual(err.state.maxStep, 1)
272
270
  })
@@ -287,7 +285,7 @@ test('end() would mark to not accepting more steps if plan is not defined', () =
287
285
  let order = new AssertOrder()
288
286
  order.end()
289
287
 
290
- let err = a.throws(() => order.once(1)) as AssertionError<{ state: any }>
288
+ let err = a.throws(() => order.once(1), InvalidOrder)
291
289
 
292
290
  t.strictEqual(err.state.maxStep, 0)
293
291
 
@@ -295,7 +293,7 @@ test('end() would mark to not accepting more steps if plan is not defined', () =
295
293
  order.once(1)
296
294
  order.end()
297
295
 
298
- err = a.throws(() => order.once(2)) as AssertionError<{ state: any }>
296
+ err = a.throws(() => order.once(2), InvalidOrder)
299
297
 
300
298
  t.strictEqual(err.state.maxStep, 1)
301
299
  })
@@ -311,7 +309,7 @@ test('end() throws if planned step not met', () => {
311
309
  const order = new AssertOrder(2)
312
310
  order.once(1)
313
311
 
314
- const err = a.throws(() => order.end()) as AssertionError<{ state: any }>
312
+ const err = a.throws(() => order.end(), InvalidOrder)
315
313
 
316
314
  t.strictEqual(err.state.maxStep, 2)
317
315
  })
@@ -332,7 +330,7 @@ test('end(n) waits n milliseconds and fail when step not met', async () => {
332
330
  setTimeout(() => {
333
331
  order.once(1)
334
332
  }, 10)
335
- const err = await a.throws(order.end(1)) as AssertionError<{ state: any }>
333
+ const err = await a.throws(order.end(1), InvalidOrder)
336
334
 
337
335
  t.strictEqual(err.state.maxStep, 1)
338
336
  })
@@ -422,7 +420,7 @@ test('wait(step, callback) will execute the async callback but not wait for it a
422
420
  const o2 = new AssertOrder(1)
423
421
 
424
422
  order.wait(1, () => {
425
- return new Promise(a => {
423
+ return new Promise<void>(a => {
426
424
  setImmediate(() => {
427
425
  o2.once(1)
428
426
  a()
@@ -435,8 +433,8 @@ test('wait(step, callback) will execute the async callback but not wait for it a
435
433
  return o2.end(100)
436
434
  })
437
435
 
438
- async function assertOrderThrows(fn, state: Partial<State>, method, ...args) {
439
- const err = await a.throws(fn) as AssertionError<{ state: any, method: string, args: any[] }>
436
+ async function assertOrderThrows(fn: () => any, state: Partial<State>, method: string, ...args: any[]) {
437
+ const err = await a.throws(fn, InvalidOrder)
440
438
  t.strictEqual(err.method, method)
441
439
  t.deepStrictEqual(err.args, args)
442
440
  if (state.step) {
@@ -31,7 +31,7 @@ export class AssertOrder {
31
31
  */
32
32
  not(step: number) {
33
33
  if (this.state.isValid(step)) {
34
- throw new InvalidOrder(this.state.get(), 'not', this.not, step)
34
+ throw new InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not })
35
35
  }
36
36
  }
37
37
 
@@ -73,21 +73,21 @@ export class AssertOrder {
73
73
  return this.state.moveSubStep()
74
74
  }
75
75
  else
76
- throw new InvalidOrder(this.state.get(), 'atLeastOnce', this.atLeastOnce, step)
76
+ throw new InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce })
77
77
  }
78
78
 
79
79
  any(steps: number[]) {
80
80
  const index = steps.indexOf(this.state.step)
81
81
  if (index === -1)
82
- throw new InvalidOrder(this.state.get(), 'any', this.any, steps)
82
+ throw new InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any })
83
83
 
84
84
  this.state.move()
85
85
  return steps[index]
86
86
  }
87
- onAny(steps: number[], ...asserts: Function[]) {
87
+ onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>) {
88
88
  steps.forEach(step => {
89
89
  this.state.on(step, () => {
90
- let firstError
90
+ let firstError: any
91
91
  let hasPass = false
92
92
  asserts.forEach(assert => {
93
93
  try {
@@ -121,12 +121,12 @@ export class AssertOrder {
121
121
  }
122
122
 
123
123
  if (this.state.isAccepting()) {
124
- throw new InvalidOrder(this.state.get(), 'end', this.end)
124
+ throw new InvalidOrder(this.state.get(), 'end', [], { ssf: this.end })
125
125
  }
126
126
  }
127
127
  exactly(step: number, times: number) {
128
128
  if (this.state.isNotValid(step))
129
- throw new InvalidOrder(this.state.get(), 'exactly', this.exactly, step, times)
129
+ throw new InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly })
130
130
 
131
131
  if (this.state.maxSubStep === undefined) {
132
132
  this.state.maxSubStep = times
@@ -145,7 +145,7 @@ export class AssertOrder {
145
145
  }
146
146
  private assert(method: string, step: number) {
147
147
  if (this.state.isNotValid(step)) {
148
- throw new InvalidOrder(this.state.get(), method, this[method], step)
148
+ throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
149
149
  }
150
150
  }
151
151
  }
@@ -1,13 +1,9 @@
1
- import AssertionError from 'assertion-error';
2
- import { State } from './interfaces';
1
+ import { AssertionError } from '../errors'
2
+ import { State } from './types'
3
3
 
4
4
  export class InvalidOrder extends AssertionError {
5
- method: string
6
- args: any[]
7
- state: State
8
- constructor(state: State, method: string, ssf: Function, ...args: any[]) {
9
- const message = method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args)
10
- super(message, { method, state, args }, ssf)
5
+ constructor(public state: State, public method: string, public args: any[], options: AssertionError.Options) {
6
+ super(method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args), options)
11
7
  }
12
8
  }
13
9
 
@@ -15,7 +11,7 @@ function getEndMessage(state: State) {
15
11
  return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
16
12
  }
17
13
 
18
- function getExpectingMessage(state, method, args) {
14
+ function getExpectingMessage(state: State, method: string, args: any[]) {
19
15
  return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
20
16
  }
21
17
 
@@ -23,9 +19,8 @@ function getExpectingCalls(state: State) {
23
19
  let message: string
24
20
  if (state.subStep === 0) {
25
21
  const methods = ['is', 'once', 'any']
26
- message = methods.map(m => ['any'].indexOf(m) === -1 ?
27
- `'${m}(${state.step})'` :
28
- `'${m}([${state.step}])'`
22
+ message = methods.map(
23
+ m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`
29
24
  ).join(', ')
30
25
  }
31
26
  else {
@@ -1,11 +1,10 @@
1
1
  import isNode from 'is-node'
2
- import { State } from './interfaces'
2
+ import { State } from './types'
3
3
 
4
4
  // istanbul ignore next
5
5
  function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
6
- // without this, systemjs will complain `process is not defined`
7
- if (!global.process)
8
- return false
6
+ // without this, systemJS will complain `process is not defined`
7
+ if (!global.process) return false
9
8
  const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version
10
9
  const [actualMajor, actualMinor, actualPatch] = versionString.split('.').map(s => parseInt(s, 10))
11
10
  const checking = major * 1000 * 1000 + minor * 1000 + patch
@@ -14,48 +13,47 @@ function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
14
13
  }
15
14
 
16
15
  // istanbul ignore next
16
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
17
17
  const performance = isNode && nodeVersionIsOrAbove(8, 5) ? require('perf_hooks').performance : undefined
18
18
 
19
- let startTick
20
- let timeTaken
19
+ let timeTracker: { start(): void, taken(): number }
21
20
  // istanbul ignore else
22
- // tslint:disable-next-line
23
21
  if (process && typeof process.hrtime === 'function') {
24
- startTick = process.hrtime
25
- timeTaken = function (startTick) {
26
- const [second, nanoSecond] = process.hrtime(startTick)
27
- return second * 1000 + nanoSecond / 1e6
22
+ let tick: [number, number]
23
+ timeTracker = {
24
+ start() { tick = process.hrtime() },
25
+ taken() {
26
+ const [second, nanoSecond] = process.hrtime(tick)
27
+ return second * 1000 + nanoSecond / 1e6
28
+ }
28
29
  }
29
30
  }
30
- // tslint:disable-next-line
31
31
  else if (performance && typeof performance.now === 'function') {
32
- startTick = performance.now
33
- timeTaken = function (startTick) {
34
- const end = performance.now()
35
- return end - startTick
32
+ let tick: number
33
+ timeTracker = {
34
+ start() { tick = performance.now() },
35
+ taken() { return performance.now() - tick }
36
36
  }
37
37
  }
38
38
  else {
39
- startTick = function () {
40
- return new Date().valueOf()
41
- }
42
- timeTaken = function (startTick) {
43
- return new Date().valueOf() - startTick
39
+ let tick: number
40
+ timeTracker = {
41
+ start() { tick = new Date().valueOf() },
42
+ taken() { return new Date().valueOf() - tick }
44
43
  }
45
44
  }
46
45
 
47
46
  export class StateMachine {
48
- listeners = {}
49
- step: number = 1
47
+ listeners: Record<number, Array<() => void>> = {}
48
+ step = 1
50
49
  maxStep?: number
51
50
 
52
- subStep: number = 0
51
+ subStep = 0
53
52
  minSubStep?: number
54
53
  maxSubStep?: number
55
- private startTick: [number, number] | number
56
54
  constructor(maxStep?: number) {
57
55
  this.maxStep = maxStep
58
- this.startTick = this.getStartTick()
56
+ timeTracker.start()
59
57
  }
60
58
  jump(step: number) {
61
59
  this.step = step
@@ -87,7 +85,7 @@ export class StateMachine {
87
85
  maxSubStep
88
86
  }
89
87
  }
90
- on(step: number, listener) {
88
+ on(step: number, listener: () => void) {
91
89
  this.listeners[step] = [listener]
92
90
  }
93
91
  isNotValid(step: number) {
@@ -107,9 +105,6 @@ export class StateMachine {
107
105
  return this.maxStep ? this.maxStep >= this.step : true
108
106
  }
109
107
  getTimeTaken() {
110
- return timeTaken(this.startTick)
111
- }
112
- private getStartTick() {
113
- return startTick()
108
+ return timeTracker.taken()
114
109
  }
115
110
  }
@@ -1,2 +1,4 @@
1
1
  export * from './AssertOrder'
2
- export * from './interfaces'
2
+ export * from './InvalidOrder'
3
+ export * from './types'
4
+
@@ -1,5 +1,5 @@
1
1
  export interface Steps {
2
- once?: number[]
3
- some?: number[]
4
- all?: number[]
2
+ once?: number[],
3
+ some?: number[],
4
+ all?: number[],
5
5
  }
@@ -0,0 +1,7 @@
1
+ export interface State {
2
+ step: number,
3
+ maxStep?: number,
4
+ subStep: number,
5
+ minSubStep?: number,
6
+ maxSubStep?: number,
7
+ }
@@ -1,6 +1,5 @@
1
- import AssertionError from 'assertion-error';
2
- import a from '..';
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import a, { AssertionError } from '..'
2
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
3
 
5
4
  describe('false()', () => {
6
5
  test('non-false statement throws', () => {
@@ -21,7 +20,6 @@ describe('false()', () => {
21
20
  })
22
21
  })
23
22
 
24
-
25
23
  describe('true()', () => {
26
24
  test('non-true statement throws', () => {
27
25
  assertThrows(() => a.true(false), AssertionError)
@@ -1,20 +1,18 @@
1
- import AssertionError from 'assertion-error';
2
- import { falsy } from './falsy';
3
- import { pathEqual } from './pathEqual';
4
- import { rejects } from './rejects';
5
- import { repeat } from './repeat';
6
- import { resolves } from './resolves';
7
- import { satisfies } from './satisfies';
8
- import { throws } from './throws';
9
- import { truthy } from './truthy';
1
+ import { AssertionError } from '../errors'
2
+ import { notEqualMessage } from '../utils'
3
+ import { falsy } from './falsy'
4
+ import { pathEqual } from './pathEqual'
5
+ import { rejects } from './rejects'
6
+ import { repeat } from './repeat'
7
+ import { resolves } from './resolves'
8
+ import { satisfies } from './satisfies'
9
+ import { throws } from './throws'
10
+ import { truthy } from './truthy'
10
11
 
11
12
  export const assertron = {
12
13
  false(value: any) {
13
14
  if (value !== false)
14
- throw new AssertionError(
15
- `Expected value to equal false, but received ${value}`,
16
- { value },
17
- assertron.false)
15
+ throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
18
16
  },
19
17
  falsy,
20
18
  pathEqual,
@@ -24,7 +22,8 @@ export const assertron = {
24
22
  satisfies,
25
23
  throws,
26
24
  true(value: any) {
27
- if (value !== true) throw new AssertionError(`Expected value to equal true, but received ${value}`, { value }, assertron.true)
25
+ if (value !== true)
26
+ throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
28
27
  },
29
28
  truthy
30
29
  }
@@ -1,6 +1,5 @@
1
- import a from '..';
2
- import AssertionError from 'assertion-error'
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import a, { AssertionError } from '..'
2
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
3
 
5
4
  test('non-false statement throws', () => {
6
5
  assertThrows(() => a.falsy(true), AssertionError)
@@ -1,10 +1,6 @@
1
- import AssertionError from 'assertion-error'
1
+ import { AssertionError } from '../errors'
2
2
 
3
3
  export function falsy(value: any) {
4
4
  if (value)
5
- throw new AssertionError(
6
- `Expected value to be falsy, but received ${value}`,
7
- { value },
8
- falsy
9
- )
5
+ throw new AssertionError(`Expected value to be falsy, but received ${value}`, { ssf: falsy })
10
6
  }
@@ -1,6 +1,5 @@
1
- import AssertionError from 'assertion-error';
2
- import assertron from '..';
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import assertron, { AssertionError } from '..'
2
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
3
 
5
4
  test('path with same style passes', () => {
6
5
  assertron.pathEqual('a', 'a')
@@ -1,11 +1,8 @@
1
- import AssertionError from 'assertion-error';
2
- import { pathEqual as isPathEqual } from 'path-equal';
3
- import { notEqualMessage } from '../errors';
1
+ import { pathEqual as isPathEqual } from 'path-equal'
2
+ import { AssertionError } from '../errors'
3
+ import { notEqualMessage } from '../utils'
4
4
 
5
5
  export function pathEqual(actual: string, expected: string) {
6
6
  if (!isPathEqual(actual, expected))
7
- throw new AssertionError(
8
- notEqualMessage(actual, expected),
9
- { actual, expected },
10
- pathEqual)
7
+ throw new AssertionError(notEqualMessage(actual, expected), { ssf: pathEqual })
11
8
  }
@@ -1,7 +1,6 @@
1
- import t from 'assert';
2
- import AssertionError from 'assertion-error';
3
- import a from '..';
4
- import { assertAsyncThrows, noStackTraceFor } from '../testUtils';
1
+ import t from 'assert'
2
+ import a from '..'
3
+ import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
5
4
 
6
5
  test('pass on rejected promise', async () => {
7
6
  await a.rejects(Promise.reject(1))
@@ -12,22 +11,22 @@ test('throws on resolved string promise', async () => {
12
11
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with 'abc'`)
13
12
  })
14
13
 
15
- test('throws on resovled boolean promise', async () => {
14
+ test('throws on resolved boolean promise', async () => {
16
15
  const err = await a.throws(a.rejects(Promise.resolve(true)))
17
16
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with true`)
18
17
  })
19
18
 
20
- test('throws on resovled object promise', async () => {
19
+ test('throws on resolved object promise', async () => {
21
20
  const err = await a.throws(a.rejects(Promise.resolve(2)))
22
21
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with 2`)
23
22
  })
24
23
 
25
- test('throws on resovled object promise', async () => {
24
+ test('throws on resolved object promise', async () => {
26
25
  const err = await a.throws(a.rejects(Promise.resolve({ a: 1 })))
27
26
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with { a: 1 }`)
28
27
  })
29
28
 
30
29
  test('does not contain internal stack trace', async () => {
31
- const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 })), AssertionError)
30
+ const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 })))
32
31
  noStackTraceFor('rejects.ts', err)
33
32
  })
@@ -1,17 +1,9 @@
1
- import { tersify } from 'tersify';
2
- import AssertionError from 'assertion-error';
1
+ import { AssertionError } from '../errors'
2
+ import { notRejectedMessage } from '../utils'
3
3
 
4
4
  export function rejects(promise: Promise<any>) {
5
5
  return promise.then(
6
- value => {
7
- throw new AssertionError(
8
- `Expected promise to reject, but it resolves with ${
9
- typeof value === 'string' ?
10
- `'${value}'` :
11
- tersify(value, { maxLength: Infinity })}`,
12
- { value },
13
- rejects)
14
- },
6
+ value => { throw new AssertionError(notRejectedMessage(value), { ssf: rejects }) },
15
7
  () => { }
16
8
  )
17
9
  }
@@ -1,5 +1,4 @@
1
- import a from '..'
2
- import { FailOnOccurance } from './repeat';
1
+ import a, { FailOnOccurrence } from '..'
3
2
 
4
3
  test('repeat function n times', () => {
5
4
  let count = 0
@@ -11,7 +10,7 @@ test('repeat function n times', () => {
11
10
  test('repeat async function n times sequentially', async () => {
12
11
  let count = 0
13
12
  let actual = ''
14
- let aa = await a.repeat(() => new Promise<string>(a => {
13
+ const aa = await a.repeat(() => new Promise<string>(a => {
15
14
  setTimeout(() => {
16
15
  ++count
17
16
  actual += String(count)
@@ -26,24 +25,23 @@ test('repeat async function n times sequentially', async () => {
26
25
  test('error is captured as inner error and indicate which call failed', () => {
27
26
  let count = 0
28
27
  const err = a.throws(() => a.repeat(() => {
29
- ++count
30
- if (count === 5) throw new Error('failed')
31
- }, 10), FailOnOccurance)
28
+ if (++count === 5) throw new Error('failed')
29
+ }, 10), FailOnOccurrence)
32
30
 
33
- expect(err.occurance).toBe(5)
31
+ expect(err.occurrence).toBe(5)
34
32
  expect(err.error.message).toBe('failed')
35
33
  })
36
34
 
37
35
  test('rejected error is captured as inner error and indicate which call failed', async () => {
38
36
  let count = 0
39
- let err = await a.throws(a.repeat(() => new Promise((a, r) => {
37
+ const err = await a.throws(a.repeat(() => new Promise<void>((a, r) => {
40
38
  setTimeout(() => {
41
39
  ++count
42
40
  if (count === 5) r(new Error('failed'))
43
41
  else a()
44
42
  }, Math.random() * 10)
45
- }), 10), FailOnOccurance)
43
+ }), 10), FailOnOccurrence)
46
44
 
47
- expect(err.occurance).toBe(5)
45
+ expect(err.occurrence).toBe(5)
48
46
  expect(err.error.message).toBe('failed')
49
47
  })