assertron 7.1.0 → 8.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 (257) hide show
  1. package/README.md +56 -23
  2. package/{dist-es2015 → cjs}/assert-order/AssertOrder.d.ts +3 -2
  3. package/cjs/assert-order/AssertOrder.d.ts.map +1 -0
  4. package/cjs/assert-order/AssertOrder.js +148 -0
  5. package/cjs/assert-order/InvalidOrder.d.ts +10 -0
  6. package/cjs/assert-order/InvalidOrder.d.ts.map +1 -0
  7. package/cjs/assert-order/InvalidOrder.js +44 -0
  8. package/{dist-es5 → cjs}/assert-order/StateMachine.d.ts +4 -5
  9. package/cjs/assert-order/StateMachine.d.ts.map +1 -0
  10. package/cjs/assert-order/StateMachine.js +111 -0
  11. package/{dist-es2015 → cjs}/assert-order/index.d.ts +1 -0
  12. package/cjs/assert-order/index.d.ts.map +1 -0
  13. package/cjs/assert-order/index.js +6 -0
  14. package/{dist-es2015 → cjs}/assert-order/interfaces.d.ts +1 -0
  15. package/cjs/assert-order/interfaces.d.ts.map +1 -0
  16. package/cjs/assert-order/interfaces.js +3 -0
  17. package/{dist-es2015 → cjs}/assertron/assertron.d.ts +1 -0
  18. package/cjs/assertron/assertron.d.ts.map +1 -0
  19. package/cjs/assertron/assertron.js +32 -0
  20. package/{dist-es2015 → cjs}/assertron/falsy.d.ts +1 -0
  21. package/cjs/assertron/falsy.d.ts.map +1 -0
  22. package/cjs/assertron/falsy.js +11 -0
  23. package/cjs/assertron/index.d.ts +2 -0
  24. package/cjs/assertron/index.d.ts.map +1 -0
  25. package/cjs/assertron/index.js +5 -0
  26. package/{dist-es2015 → cjs}/assertron/pathEqual.d.ts +1 -0
  27. package/cjs/assertron/pathEqual.d.ts.map +1 -0
  28. package/cjs/assertron/pathEqual.js +13 -0
  29. package/{dist-es2015 → cjs}/assertron/rejects.d.ts +1 -0
  30. package/cjs/assertron/rejects.d.ts.map +1 -0
  31. package/cjs/assertron/rejects.js +14 -0
  32. package/{dist-es2015 → cjs}/assertron/repeat.d.ts +9 -0
  33. package/cjs/assertron/repeat.d.ts.map +1 -0
  34. package/cjs/assertron/repeat.js +44 -0
  35. package/{dist-es2015 → cjs}/assertron/resolves.d.ts +1 -0
  36. package/cjs/assertron/resolves.d.ts.map +1 -0
  37. package/cjs/assertron/resolves.js +17 -0
  38. package/cjs/assertron/satisfies.d.ts +10 -0
  39. package/cjs/assertron/satisfies.d.ts.map +1 -0
  40. package/cjs/assertron/satisfies.js +19 -0
  41. package/{dist-es2015 → cjs}/assertron/throws.d.ts +2 -0
  42. package/cjs/assertron/throws.d.ts.map +1 -0
  43. package/cjs/assertron/throws.js +62 -0
  44. package/{dist-es2015 → cjs}/assertron/truthy.d.ts +1 -0
  45. package/cjs/assertron/truthy.d.ts.map +1 -0
  46. package/cjs/assertron/truthy.js +11 -0
  47. package/{dist-es2015 → cjs}/errors/NotSatisfied.d.ts +1 -0
  48. package/cjs/errors/NotSatisfied.d.ts.map +1 -0
  49. package/cjs/errors/NotSatisfied.js +28 -0
  50. package/{dist-es5 → cjs}/errors/index.d.ts +1 -0
  51. package/cjs/errors/index.d.ts.map +1 -0
  52. package/cjs/errors/index.js +11 -0
  53. package/{dist-es2015 → cjs}/errors/interfaces.d.ts +1 -0
  54. package/cjs/errors/interfaces.d.ts.map +1 -0
  55. package/cjs/errors/interfaces.js +3 -0
  56. package/{dist-es2015 → cjs}/errors/notEqualMessage.d.ts +1 -0
  57. package/cjs/errors/notEqualMessage.d.ts.map +1 -0
  58. package/cjs/errors/notEqualMessage.js +8 -0
  59. package/{dist-es2015 → cjs}/errors/notRejectedMessage.d.ts +1 -0
  60. package/cjs/errors/notRejectedMessage.d.ts.map +1 -0
  61. package/cjs/errors/notRejectedMessage.js +8 -0
  62. package/{dist-es2015 → cjs}/errors/notThrownMessage.d.ts +1 -0
  63. package/cjs/errors/notThrownMessage.d.ts.map +1 -0
  64. package/cjs/errors/notThrownMessage.js +9 -0
  65. package/{dist-es2015 → cjs}/errors/returnNotRejectedMessage.d.ts +1 -0
  66. package/cjs/errors/returnNotRejectedMessage.d.ts.map +1 -0
  67. package/cjs/errors/returnNotRejectedMessage.js +8 -0
  68. package/{dist-es2015 → cjs}/errors/unexpectedErrorMessage.d.ts +1 -0
  69. package/cjs/errors/unexpectedErrorMessage.d.ts.map +1 -0
  70. package/cjs/errors/unexpectedErrorMessage.js +10 -0
  71. package/{dist-es2015 → cjs}/errors/util.d.ts +1 -0
  72. package/cjs/errors/util.d.ts.map +1 -0
  73. package/cjs/errors/util.js +8 -0
  74. package/{dist-es5 → cjs}/index.d.ts +1 -0
  75. package/cjs/index.d.ts.map +1 -0
  76. package/cjs/index.js +8 -0
  77. package/esm/assert-order/AssertOrder.js +132 -0
  78. package/esm/assert-order/InvalidOrder.js +31 -0
  79. package/esm/assert-order/StateMachine.js +103 -0
  80. package/esm/assert-order/index.js +3 -0
  81. package/esm/assert-order/interfaces.js +2 -0
  82. package/esm/assertron/assertron.js +28 -0
  83. package/esm/assertron/falsy.js +6 -0
  84. package/esm/assertron/index.js +2 -0
  85. package/esm/assertron/pathEqual.js +8 -0
  86. package/esm/assertron/rejects.js +9 -0
  87. package/esm/assertron/repeat.js +35 -0
  88. package/esm/assertron/resolves.js +12 -0
  89. package/esm/assertron/satisfies.js +14 -0
  90. package/esm/assertron/throws.js +57 -0
  91. package/esm/assertron/truthy.js +6 -0
  92. package/esm/errors/NotSatisfied.js +23 -0
  93. package/esm/errors/index.js +8 -0
  94. package/esm/errors/interfaces.js +2 -0
  95. package/esm/errors/notEqualMessage.js +4 -0
  96. package/esm/errors/notRejectedMessage.js +4 -0
  97. package/esm/errors/notThrownMessage.js +5 -0
  98. package/esm/errors/returnNotRejectedMessage.js +4 -0
  99. package/esm/errors/unexpectedErrorMessage.js +6 -0
  100. package/esm/errors/util.js +4 -0
  101. package/esm/index.js +5 -0
  102. package/package.json +63 -24
  103. package/src/assert-order/AssertOrder.spec.ts +0 -1
  104. package/src/assert-order/AssertOrder.ts +3 -3
  105. package/src/assert-order/InvalidOrder.ts +5 -8
  106. package/src/assert-order/StateMachine.ts +24 -28
  107. package/src/assert-order/interfaces.ts +5 -5
  108. package/src/assert-order/internalInterfaces.ts +3 -3
  109. package/src/assertron/assertron.spec.ts +3 -4
  110. package/src/assertron/assertron.ts +9 -9
  111. package/src/assertron/falsy.spec.ts +2 -2
  112. package/src/assertron/pathEqual.spec.ts +3 -3
  113. package/src/assertron/pathEqual.ts +3 -3
  114. package/src/assertron/rejects.spec.ts +7 -7
  115. package/src/assertron/rejects.ts +4 -6
  116. package/src/assertron/repeat.spec.ts +27 -1
  117. package/src/assertron/repeat.ts +27 -10
  118. package/src/assertron/resolves.spec.ts +4 -4
  119. package/src/assertron/resolves.ts +7 -10
  120. package/src/assertron/satisfies.spec.ts +8 -9
  121. package/src/assertron/satisfies.ts +15 -5
  122. package/src/assertron/throws.spec.ts +33 -13
  123. package/src/assertron/throws.ts +8 -5
  124. package/src/assertron/truthy.spec.ts +3 -3
  125. package/src/errors/NotSatisfied.ts +1 -1
  126. package/src/errors/interfaces.ts +1 -1
  127. package/src/errors/notThrownMessage.ts +3 -1
  128. package/src/errors/util.ts +2 -2
  129. package/src/testUtils.ts +17 -13
  130. package/dist-es2015/assert-order/AssertOrder.js +0 -132
  131. package/dist-es2015/assert-order/AssertOrder.js.map +0 -1
  132. package/dist-es2015/assert-order/InvalidOrder.d.ts +0 -8
  133. package/dist-es2015/assert-order/InvalidOrder.js +0 -31
  134. package/dist-es2015/assert-order/InvalidOrder.js.map +0 -1
  135. package/dist-es2015/assert-order/StateMachine.d.ts +0 -23
  136. package/dist-es2015/assert-order/StateMachine.js +0 -106
  137. package/dist-es2015/assert-order/StateMachine.js.map +0 -1
  138. package/dist-es2015/assert-order/index.js +0 -2
  139. package/dist-es2015/assert-order/index.js.map +0 -1
  140. package/dist-es2015/assert-order/interfaces.js +0 -1
  141. package/dist-es2015/assert-order/interfaces.js.map +0 -1
  142. package/dist-es2015/assertron/assertron.js +0 -28
  143. package/dist-es2015/assertron/assertron.js.map +0 -1
  144. package/dist-es2015/assertron/falsy.js +0 -6
  145. package/dist-es2015/assertron/falsy.js.map +0 -1
  146. package/dist-es2015/assertron/index.d.ts +0 -1
  147. package/dist-es2015/assertron/index.js +0 -2
  148. package/dist-es2015/assertron/index.js.map +0 -1
  149. package/dist-es2015/assertron/pathEqual.js +0 -8
  150. package/dist-es2015/assertron/pathEqual.js.map +0 -1
  151. package/dist-es2015/assertron/rejects.js +0 -10
  152. package/dist-es2015/assertron/rejects.js.map +0 -1
  153. package/dist-es2015/assertron/repeat.js +0 -21
  154. package/dist-es2015/assertron/repeat.js.map +0 -1
  155. package/dist-es2015/assertron/resolves.js +0 -12
  156. package/dist-es2015/assertron/resolves.js.map +0 -1
  157. package/dist-es2015/assertron/satisfies.d.ts +0 -5
  158. package/dist-es2015/assertron/satisfies.js +0 -14
  159. package/dist-es2015/assertron/satisfies.js.map +0 -1
  160. package/dist-es2015/assertron/throws.js +0 -55
  161. package/dist-es2015/assertron/throws.js.map +0 -1
  162. package/dist-es2015/assertron/truthy.js +0 -6
  163. package/dist-es2015/assertron/truthy.js.map +0 -1
  164. package/dist-es2015/errors/NotSatisfied.js +0 -23
  165. package/dist-es2015/errors/NotSatisfied.js.map +0 -1
  166. package/dist-es2015/errors/index.d.ts +0 -7
  167. package/dist-es2015/errors/index.js +0 -7
  168. package/dist-es2015/errors/index.js.map +0 -1
  169. package/dist-es2015/errors/interfaces.js +0 -1
  170. package/dist-es2015/errors/interfaces.js.map +0 -1
  171. package/dist-es2015/errors/notEqualMessage.js +0 -4
  172. package/dist-es2015/errors/notEqualMessage.js.map +0 -1
  173. package/dist-es2015/errors/notRejectedMessage.js +0 -4
  174. package/dist-es2015/errors/notRejectedMessage.js.map +0 -1
  175. package/dist-es2015/errors/notThrownMessage.js +0 -4
  176. package/dist-es2015/errors/notThrownMessage.js.map +0 -1
  177. package/dist-es2015/errors/returnNotRejectedMessage.js +0 -4
  178. package/dist-es2015/errors/returnNotRejectedMessage.js.map +0 -1
  179. package/dist-es2015/errors/unexpectedErrorMessage.js +0 -6
  180. package/dist-es2015/errors/unexpectedErrorMessage.js.map +0 -1
  181. package/dist-es2015/errors/util.js +0 -4
  182. package/dist-es2015/errors/util.js.map +0 -1
  183. package/dist-es2015/index.d.ts +0 -4
  184. package/dist-es2015/index.js +0 -5
  185. package/dist-es2015/index.js.map +0 -1
  186. package/dist-es5/assert-order/AssertOrder.d.ts +0 -40
  187. package/dist-es5/assert-order/AssertOrder.js +0 -147
  188. package/dist-es5/assert-order/AssertOrder.js.map +0 -1
  189. package/dist-es5/assert-order/InvalidOrder.d.ts +0 -8
  190. package/dist-es5/assert-order/InvalidOrder.js +0 -58
  191. package/dist-es5/assert-order/InvalidOrder.js.map +0 -1
  192. package/dist-es5/assert-order/StateMachine.js +0 -115
  193. package/dist-es5/assert-order/StateMachine.js.map +0 -1
  194. package/dist-es5/assert-order/index.d.ts +0 -2
  195. package/dist-es5/assert-order/index.js +0 -7
  196. package/dist-es5/assert-order/index.js.map +0 -1
  197. package/dist-es5/assert-order/interfaces.d.ts +0 -7
  198. package/dist-es5/assert-order/interfaces.js +0 -3
  199. package/dist-es5/assert-order/interfaces.js.map +0 -1
  200. package/dist-es5/assertron/assertron.d.ts +0 -20
  201. package/dist-es5/assertron/assertron.js +0 -33
  202. package/dist-es5/assertron/assertron.js.map +0 -1
  203. package/dist-es5/assertron/falsy.d.ts +0 -1
  204. package/dist-es5/assertron/falsy.js +0 -12
  205. package/dist-es5/assertron/falsy.js.map +0 -1
  206. package/dist-es5/assertron/index.d.ts +0 -1
  207. package/dist-es5/assertron/index.js +0 -7
  208. package/dist-es5/assertron/index.js.map +0 -1
  209. package/dist-es5/assertron/pathEqual.d.ts +0 -1
  210. package/dist-es5/assertron/pathEqual.js +0 -14
  211. package/dist-es5/assertron/pathEqual.js.map +0 -1
  212. package/dist-es5/assertron/rejects.d.ts +0 -1
  213. package/dist-es5/assertron/rejects.js +0 -16
  214. package/dist-es5/assertron/rejects.js.map +0 -1
  215. package/dist-es5/assertron/repeat.d.ts +0 -5
  216. package/dist-es5/assertron/repeat.js +0 -27
  217. package/dist-es5/assertron/repeat.js.map +0 -1
  218. package/dist-es5/assertron/resolves.d.ts +0 -1
  219. package/dist-es5/assertron/resolves.js +0 -18
  220. package/dist-es5/assertron/resolves.js.map +0 -1
  221. package/dist-es5/assertron/satisfies.d.ts +0 -5
  222. package/dist-es5/assertron/satisfies.js +0 -20
  223. package/dist-es5/assertron/satisfies.js.map +0 -1
  224. package/dist-es5/assertron/throws.d.ts +0 -4
  225. package/dist-es5/assertron/throws.js +0 -61
  226. package/dist-es5/assertron/throws.js.map +0 -1
  227. package/dist-es5/assertron/truthy.d.ts +0 -1
  228. package/dist-es5/assertron/truthy.js +0 -12
  229. package/dist-es5/assertron/truthy.js.map +0 -1
  230. package/dist-es5/errors/NotSatisfied.d.ts +0 -2
  231. package/dist-es5/errors/NotSatisfied.js +0 -26
  232. package/dist-es5/errors/NotSatisfied.js.map +0 -1
  233. package/dist-es5/errors/index.js +0 -12
  234. package/dist-es5/errors/index.js.map +0 -1
  235. package/dist-es5/errors/interfaces.d.ts +0 -2
  236. package/dist-es5/errors/interfaces.js +0 -3
  237. package/dist-es5/errors/interfaces.js.map +0 -1
  238. package/dist-es5/errors/notEqualMessage.d.ts +0 -1
  239. package/dist-es5/errors/notEqualMessage.js +0 -7
  240. package/dist-es5/errors/notEqualMessage.js.map +0 -1
  241. package/dist-es5/errors/notRejectedMessage.d.ts +0 -1
  242. package/dist-es5/errors/notRejectedMessage.js +0 -7
  243. package/dist-es5/errors/notRejectedMessage.js.map +0 -1
  244. package/dist-es5/errors/notThrownMessage.d.ts +0 -1
  245. package/dist-es5/errors/notThrownMessage.js +0 -7
  246. package/dist-es5/errors/notThrownMessage.js.map +0 -1
  247. package/dist-es5/errors/returnNotRejectedMessage.d.ts +0 -1
  248. package/dist-es5/errors/returnNotRejectedMessage.js +0 -7
  249. package/dist-es5/errors/returnNotRejectedMessage.js.map +0 -1
  250. package/dist-es5/errors/unexpectedErrorMessage.d.ts +0 -2
  251. package/dist-es5/errors/unexpectedErrorMessage.js +0 -9
  252. package/dist-es5/errors/unexpectedErrorMessage.js.map +0 -1
  253. package/dist-es5/errors/util.d.ts +0 -2
  254. package/dist-es5/errors/util.js +0 -7
  255. package/dist-es5/errors/util.js.map +0 -1
  256. package/dist-es5/index.js +0 -10
  257. package/dist-es5/index.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "assertron",
3
- "version": "7.1.0",
4
- "description": "A supplementary assertion library",
3
+ "version": "8.0.0",
4
+ "description": "A supplementary assertion cjsrary",
5
5
  "homepage": "https://github.com/unional/assertron",
6
6
  "bugs": {
7
7
  "url": "https://github.com/unional/assertron/issues"
@@ -15,41 +15,80 @@
15
15
  "name": "Homa Wong",
16
16
  "email": "homawong@gmail.com"
17
17
  },
18
+ "sideEffects": false,
19
+ "type": "module",
20
+ "main": "cjs/index.js",
21
+ "module": "esm/index.js",
22
+ "jsnext:main": "esm/index.js",
23
+ "browser": {
24
+ "perf_hooks": false
25
+ },
26
+ "typings": "cjs/index.d.ts",
18
27
  "files": [
19
- "dist",
20
- "dist-es5",
21
- "dist-es2015",
28
+ "cjs",
29
+ "esm",
22
30
  "src"
23
31
  ],
24
- "main": "dist-es5/index.js",
25
- "module": "dist-es2015/index.js",
26
- "typings": "dist-es5/index.d.ts",
27
32
  "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",
33
+ "build": "yarn build:esm && yarn build:cjs",
34
+ "build:cjs": "tsc -p tsconfig.cjs.json",
35
+ "build:esm": "tsc -p tsconfig.esm.json",
36
+ "build:watch": "tsc --watch",
37
+ "clean": "rimraf .nyc_output .ts coverage cjs esm",
32
38
  "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",
39
+ "depcheck": "yarn dependency-check",
40
+ "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",
41
+ "lint": "eslint --ext=js,ts .",
42
+ "nuke": "yarn clean && rimraf node_modules",
35
43
  "test": "jest",
36
- "verify": "npm run lint && npm run build && npm run dependency-check && npm run coverage",
37
- "watch": "jest --watch"
44
+ "test:watch": "jest --watch",
45
+ "verify": "yarn lint && yarn build && yarn dependency-check && yarn coverage",
46
+ "watch": "yarn test:watch"
38
47
  },
39
- "browser": {
40
- "perf_hooks": false
48
+ "husky": {
49
+ "hooks": {
50
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
51
+ }
41
52
  },
42
53
  "dependencies": {
43
54
  "assertion-error": "^1.1.0",
44
55
  "is-node": "^1.0.2",
45
- "is-promise": "^2.1.0",
56
+ "is-promise": "^4.0.0",
46
57
  "path-equal": "^1.1.1",
47
- "satisfier": "^5.0.2",
48
- "tersify": "^3.0.1"
58
+ "satisfier": "^5.1.1",
59
+ "tersify": "^3.7.9",
60
+ "tslib": "^2.3.1",
61
+ "type-plus": "^3.13.1"
49
62
  },
50
63
  "devDependencies": {
51
- "@types/lodash": "^4.14.126",
52
- "@unional/devpkg-node": "^1.3.0",
53
- "lodash": "^4.17.11"
64
+ "@babel/core": "^7.12.16",
65
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
66
+ "@babel/plugin-proposal-optional-chaining": "^7.12.16",
67
+ "@babel/preset-env": "^7.12.16",
68
+ "@babel/preset-typescript": "^7.12.16",
69
+ "@commitlint/cli": "^15.0.0",
70
+ "@commitlint/config-conventional": "^15.0.0",
71
+ "@types/jest": "^27.0.3",
72
+ "@types/lodash": "^4.14.149",
73
+ "@types/node": "^16.11.11",
74
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
75
+ "@typescript-eslint/parser": "^5.5.0",
76
+ "babel-jest": "^27.4.2",
77
+ "dependency-check": "^4.1.0",
78
+ "eslint": "^8.4.0",
79
+ "eslint-plugin-harmony": "^6.0.0",
80
+ "husky": "^7.0.4",
81
+ "jest": "^27.4.3",
82
+ "jest-junit": "^13.0.0",
83
+ "jest-progress-tracker": "^3.0.1",
84
+ "jest-validate": "^27.4.2",
85
+ "jest-watch-repeat": "^2.0.0",
86
+ "jest-watch-suspend": "^1.1.2",
87
+ "jest-watch-toggle-config": "^2.0.1",
88
+ "jest-watch-typeahead": "^1.0.0",
89
+ "node-supported-releases": "^0.0.0",
90
+ "rimraf": "^3.0.2",
91
+ "typescript": "^4.1.5",
92
+ "update-notifier": "^5.1.0"
54
93
  }
55
94
  }
@@ -1,4 +1,3 @@
1
-
2
1
  import t from 'assert';
3
2
  import AssertionError from 'assertion-error';
4
3
  import a, { AssertOrder, State } from '..';
@@ -84,10 +84,10 @@ export class AssertOrder {
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 {
@@ -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, (this as any)[method], step)
149
149
  }
150
150
  }
151
151
  }
@@ -1,11 +1,8 @@
1
- import AssertionError from 'assertion-error';
2
- import { State } from './interfaces';
1
+ import AssertionError from 'assertion-error'
2
+ import { State } from './interfaces'
3
3
 
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[]) {
4
+ export class InvalidOrder extends AssertionError<{ method: string, state: State, args: any[] }> {
5
+ constructor(state: State, method: string, ssf: (...args: any[]) => any, ...args: any[]) {
9
6
  const message = method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args)
10
7
  super(message, { method, state, args }, ssf)
11
8
  }
@@ -15,7 +12,7 @@ function getEndMessage(state: State) {
15
12
  return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
16
13
  }
17
14
 
18
- function getExpectingMessage(state, method, args) {
15
+ function getExpectingMessage(state: State, method: string, args: any[]) {
19
16
  return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
20
17
  }
21
18
 
@@ -3,7 +3,7 @@ import { State } from './interfaces'
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`
6
+ // without this, systemJS will complain `process is not defined`
7
7
  if (!global.process)
8
8
  return false
9
9
  const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version
@@ -14,48 +14,47 @@ function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
14
14
  }
15
15
 
16
16
  // istanbul ignore next
17
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
17
18
  const performance = isNode && nodeVersionIsOrAbove(8, 5) ? require('perf_hooks').performance : undefined
18
19
 
19
- let startTick
20
- let timeTaken
20
+ let timeTracker: { start(): void, taken(): number }
21
21
  // istanbul ignore else
22
- // tslint:disable-next-line
23
22
  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
23
+ let tick: [number, number]
24
+ timeTracker = {
25
+ start() { tick = process.hrtime() },
26
+ taken() {
27
+ const [second, nanoSecond] = process.hrtime(tick)
28
+ return second * 1000 + nanoSecond / 1e6
29
+ }
28
30
  }
29
31
  }
30
- // tslint:disable-next-line
31
32
  else if (performance && typeof performance.now === 'function') {
32
- startTick = performance.now
33
- timeTaken = function (startTick) {
34
- const end = performance.now()
35
- return end - startTick
33
+ let tick: number
34
+ timeTracker = {
35
+ start() { tick = performance.now() },
36
+ taken() { return performance.now() - tick }
36
37
  }
37
38
  }
38
39
  else {
39
- startTick = function () {
40
- return new Date().valueOf()
41
- }
42
- timeTaken = function (startTick) {
43
- return new Date().valueOf() - startTick
40
+ let tick: number
41
+ timeTracker = {
42
+ start() { tick = new Date().valueOf() },
43
+ taken() { return new Date().valueOf() - tick }
44
44
  }
45
45
  }
46
46
 
47
47
  export class StateMachine {
48
- listeners = {}
49
- step: number = 1
48
+ listeners: Record<number, Array<() => void>> = {}
49
+ step = 1
50
50
  maxStep?: number
51
51
 
52
- subStep: number = 0
52
+ subStep = 0
53
53
  minSubStep?: number
54
54
  maxSubStep?: number
55
- private startTick: [number, number] | number
56
55
  constructor(maxStep?: number) {
57
56
  this.maxStep = maxStep
58
- this.startTick = this.getStartTick()
57
+ timeTracker.start()
59
58
  }
60
59
  jump(step: number) {
61
60
  this.step = step
@@ -87,7 +86,7 @@ export class StateMachine {
87
86
  maxSubStep
88
87
  }
89
88
  }
90
- on(step: number, listener) {
89
+ on(step: number, listener: () => void) {
91
90
  this.listeners[step] = [listener]
92
91
  }
93
92
  isNotValid(step: number) {
@@ -107,9 +106,6 @@ export class StateMachine {
107
106
  return this.maxStep ? this.maxStep >= this.step : true
108
107
  }
109
108
  getTimeTaken() {
110
- return timeTaken(this.startTick)
111
- }
112
- private getStartTick() {
113
- return startTick()
109
+ return timeTracker.taken()
114
110
  }
115
111
  }
@@ -1,7 +1,7 @@
1
1
  export interface State {
2
- step: number
3
- maxStep?: number
4
- subStep: number
5
- minSubStep?: number
6
- maxSubStep?: number
2
+ step: number,
3
+ maxStep?: number,
4
+ subStep: number,
5
+ minSubStep?: number,
6
+ maxSubStep?: number,
7
7
  }
@@ -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
  }
@@ -1,6 +1,6 @@
1
- import AssertionError from 'assertion-error';
2
- import a from '..';
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import AssertionError from 'assertion-error'
2
+ import a from '..'
3
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
4
 
5
5
  describe('false()', () => {
6
6
  test('non-false statement throws', () => {
@@ -21,7 +21,6 @@ describe('false()', () => {
21
21
  })
22
22
  })
23
23
 
24
-
25
24
  describe('true()', () => {
26
25
  test('non-true statement throws', () => {
27
26
  assertThrows(() => a.true(false), AssertionError)
@@ -1,12 +1,12 @@
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 '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'
10
10
 
11
11
  export const assertron = {
12
12
  false(value: any) {
@@ -1,6 +1,6 @@
1
- import a from '..';
1
+ import a from '..'
2
2
  import AssertionError from 'assertion-error'
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
3
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
4
 
5
5
  test('non-false statement throws', () => {
6
6
  assertThrows(() => a.falsy(true), AssertionError)
@@ -1,6 +1,6 @@
1
- import AssertionError from 'assertion-error';
2
- import assertron from '..';
3
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import AssertionError from 'assertion-error'
2
+ import assertron from '..'
3
+ import { assertThrows, noStackTraceFor } from '../testUtils'
4
4
 
5
5
  test('path with same style passes', () => {
6
6
  assertron.pathEqual('a', 'a')
@@ -1,6 +1,6 @@
1
- import AssertionError from 'assertion-error';
2
- import { pathEqual as isPathEqual } from 'path-equal';
3
- import { notEqualMessage } from '../errors';
1
+ import AssertionError from 'assertion-error'
2
+ import { pathEqual as isPathEqual } from 'path-equal'
3
+ import { notEqualMessage } from '../errors'
4
4
 
5
5
  export function pathEqual(actual: string, expected: string) {
6
6
  if (!isPathEqual(actual, expected))
@@ -1,7 +1,7 @@
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 AssertionError from 'assertion-error'
3
+ import a from '..'
4
+ import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
5
5
 
6
6
  test('pass on rejected promise', async () => {
7
7
  await a.rejects(Promise.reject(1))
@@ -12,17 +12,17 @@ test('throws on resolved string promise', async () => {
12
12
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with 'abc'`)
13
13
  })
14
14
 
15
- test('throws on resovled boolean promise', async () => {
15
+ test('throws on resolved boolean promise', async () => {
16
16
  const err = await a.throws(a.rejects(Promise.resolve(true)))
17
17
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with true`)
18
18
  })
19
19
 
20
- test('throws on resovled object promise', async () => {
20
+ test('throws on resolved object promise', async () => {
21
21
  const err = await a.throws(a.rejects(Promise.resolve(2)))
22
22
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with 2`)
23
23
  })
24
24
 
25
- test('throws on resovled object promise', async () => {
25
+ test('throws on resolved object promise', async () => {
26
26
  const err = await a.throws(a.rejects(Promise.resolve({ a: 1 })))
27
27
  t.strictEqual(err.message, `Expected promise to reject, but it resolves with { a: 1 }`)
28
28
  })
@@ -1,14 +1,12 @@
1
- import { tersify } from 'tersify';
2
- import AssertionError from 'assertion-error';
1
+ import { tersify } from 'tersify'
2
+ import AssertionError from 'assertion-error'
3
3
 
4
4
  export function rejects(promise: Promise<any>) {
5
5
  return promise.then(
6
6
  value => {
7
7
  throw new AssertionError(
8
- `Expected promise to reject, but it resolves with ${
9
- typeof value === 'string' ?
10
- `'${value}'` :
11
- tersify(value, { maxLength: Infinity })}`,
8
+ `Expected promise to reject, but it resolves with ${typeof value === 'string' ?
9
+ `'${value}'` : tersify(value, { maxLength: Infinity })}`,
12
10
  { value },
13
11
  rejects)
14
12
  },
@@ -1,4 +1,5 @@
1
1
  import a from '..'
2
+ import { FailOnOccurrence } from './repeat'
2
3
 
3
4
  test('repeat function n times', () => {
4
5
  let count = 0
@@ -10,7 +11,7 @@ test('repeat function n times', () => {
10
11
  test('repeat async function n times sequentially', async () => {
11
12
  let count = 0
12
13
  let actual = ''
13
- let aa = await a.repeat(() => new Promise<string>(a => {
14
+ const aa = await a.repeat(() => new Promise<string>(a => {
14
15
  setTimeout(() => {
15
16
  ++count
16
17
  actual += String(count)
@@ -21,3 +22,28 @@ test('repeat async function n times sequentially', async () => {
21
22
  expect(actual).toBe('12345678910')
22
23
  expect(actual).toBe(aa)
23
24
  })
25
+
26
+ test('error is captured as inner error and indicate which call failed', () => {
27
+ let count = 0
28
+ const err = a.throws(() => a.repeat(() => {
29
+ ++count
30
+ if (count === 5) throw new Error('failed')
31
+ }, 10), FailOnOccurrence)
32
+
33
+ expect(err.occurrence).toBe(5)
34
+ expect(err.error.message).toBe('failed')
35
+ })
36
+
37
+ test('rejected error is captured as inner error and indicate which call failed', async () => {
38
+ let count = 0
39
+ const err = await a.throws(a.repeat(() => new Promise<void>((a, r) => {
40
+ setTimeout(() => {
41
+ ++count
42
+ if (count === 5) r(new Error('failed'))
43
+ else a()
44
+ }, Math.random() * 10)
45
+ }), 10), FailOnOccurrence)
46
+
47
+ expect(err.occurrence).toBe(5)
48
+ expect(err.error.message).toBe('failed')
49
+ })
@@ -1,20 +1,37 @@
1
1
  import isPromise from 'is-promise';
2
+ import AssertionError from 'assertion-error'
2
3
 
3
4
  /**
4
5
  * Repeat the specified function n times and return the last result.
5
6
  * If the result is a promise, it will run the function sequentially.
6
7
  */
7
8
  export function repeat<R>(fn: () => R | (() => Promise<R>), times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R {
8
- const result = fn()
9
- if (isPromise(result)) {
10
- if (times <= 1) return result as any
11
- return result.then(() => repeat(fn, times - 1)) as any
12
- }
13
- else {
14
- let result
15
- for (let i = 1; i < times; i++) {
16
- result = fn()
9
+ return repeatRecur(fn, 1, times)
10
+ }
11
+
12
+ function repeatRecur<R>(fn: () => R | (() => Promise<R>), i: number, times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R {
13
+ try {
14
+ const result = fn()
15
+ if (i === times) return result as any
16
+
17
+ if (isPromise(result)) {
18
+ return result.then(
19
+ () => repeatRecur(fn, i + 1, times),
20
+ (e) => { throw new FailOnOccurrence(i, e) }
21
+ ) as any
22
+ }
23
+ else {
24
+ return repeatRecur(fn, i + 1, times)
17
25
  }
18
- return result
26
+ }
27
+ catch (e) {
28
+ if (e instanceof FailOnOccurrence) throw e
29
+ throw new FailOnOccurrence(i, e)
30
+ }
31
+ }
32
+
33
+ export class FailOnOccurrence extends AssertionError<{ occurrence: number }> {
34
+ constructor(public occurrence: number, public error: any) {
35
+ super(`Failed on ${occurrence} occurrence`)
19
36
  }
20
37
  }
@@ -1,7 +1,7 @@
1
- import t from 'assert';
2
- import a from '..';
3
- import AssertionError from 'assertion-error';
4
- import { assertAsyncThrows, noStackTraceFor } from '../testUtils';
1
+ import t from 'assert'
2
+ import a from '..'
3
+ import AssertionError from 'assertion-error'
4
+ import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
5
5
 
6
6
 
7
7
  test('pass on resolved promise', async () => {
@@ -1,18 +1,15 @@
1
- import { tersify } from 'tersify';
2
- import AssertionError from 'assertion-error';
1
+ import { tersify } from 'tersify'
2
+ import AssertionError from 'assertion-error'
3
3
 
4
4
  export function resolves(promise: Promise<any>) {
5
5
  return promise.then(
6
6
  () => { },
7
7
  error => {
8
- throw new AssertionError(`Expected promise to resolve, but it rejects with ${
9
- typeof error === 'string' ?
10
- `'${error}'` :
11
- error instanceof Error ?
12
- error :
13
- tersify(error, { maxLength: Infinity })}`,
14
- { error },
15
- resolves
8
+ throw new AssertionError(`Expected promise to resolve, but it rejects with ${typeof error === 'string' ?
9
+ `'${error}'` :
10
+ error instanceof Error ?
11
+ error :
12
+ tersify(error, { maxLength: Infinity })}`, { error }, resolves
16
13
  )
17
14
  }
18
15
  )
@@ -1,7 +1,7 @@
1
- import AssertionError from 'assertion-error';
2
- import { every } from 'satisfier';
3
- import a from '..';
4
- import { assertThrows, noStackTraceFor } from '../testUtils';
1
+ import AssertionError from 'assertion-error'
2
+ import { every } from 'satisfier'
3
+ import a from '..'
4
+ import { assertThrows, noStackTraceFor } from '../testUtils'
5
5
 
6
6
  test('primitive types will pass', () => {
7
7
  a.satisfies(1, 1)
@@ -74,12 +74,11 @@ test('function will use as predicate', () => {
74
74
  })
75
75
 
76
76
  test('predicate error should mention path', () => {
77
- a.throws(() => a.satisfies({ a: 1 }, { a: () => false }), e => e.message === `Expect a to satisfy fn() { return false }, but received 1`)
77
+ a.throws(() => a.satisfies({ a: 1 }, { a: () => false }), e => e.message === `Expect a to satisfy () => false, but received 1`)
78
78
  })
79
79
 
80
80
  test('deep predicate error should mention path', () => {
81
-
82
- a.throws(() => a.satisfies({ a: { b: 1 } }, { a: { b: b => b === 2 } }), e => e.message === `Expect a.b to satisfy fn(b) { return b === 2 }, but received 1`)
81
+ a.throws(() => a.satisfies({ a: { b: 1 } }, { a: { b: b => b === 2 } }), e => e.message === `Expect a.b to satisfy b => b === 2, but received 1`)
83
82
  })
84
83
 
85
84
  test('can check parent property', () => {
@@ -94,7 +93,7 @@ test('can check parent property', () => {
94
93
  })
95
94
 
96
95
  test('actual of type any should not have type checking error', () => {
97
- let actual: any = { a: 1 }
96
+ const actual: any = { a: 1 }
98
97
  a.satisfies(actual, { a: 1 })
99
98
  })
100
99
 
@@ -102,7 +101,7 @@ test('Work with null in array', () => {
102
101
  interface Foo {
103
102
  payload: any;
104
103
  }
105
- let action: Foo = { payload: [null, 3, 4] }
104
+ const action: Foo = { payload: [null, 3, 4] }
106
105
  a.satisfies(action, { payload: [null, 3, 4] })
107
106
  })
108
107
 
@@ -1,13 +1,23 @@
1
- import AssertionError from 'assertion-error';
2
- import { createSatisfier } from 'satisfier';
3
- import { notSatisfiedMessage } from '../errors';
1
+ import AssertionError from 'assertion-error'
2
+ import { createSatisfier } from 'satisfier'
3
+ import { And, If, PrimitiveTypes, IsExtend } from 'type-plus'
4
+ import { notSatisfiedMessage } from '../errors'
5
+
6
+ export type SatisfyExpectation<T> = If<
7
+ And<IsExtend<T, PrimitiveTypes>, IsExtend<T, Array<any>>>,
8
+ T | ((v: T) => boolean),
9
+ {
10
+ [P in keyof T]?: T[P] extends string
11
+ ? SatisfyExpectation<T[P]> | ((v: T[P]) => boolean) | RegExp
12
+ : SatisfyExpectation<T[P]> | ((v: T[P]) => boolean)
13
+ }>
4
14
 
5
15
  /**
6
16
  * Check if `actual` satisfies criteria in `expected`.
7
17
  * @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
18
  */
9
- export function satisfies<Actual extends any>(actual: Actual, expected: any) {
10
- const diff = createSatisfier(expected).exec(actual);
19
+ export function satisfies<Actual>(actual: Actual, expected: SatisfyExpectation<Actual>) {
20
+ const diff = createSatisfier(expected as any).exec(actual);
11
21
  if (diff) {
12
22
  throw new AssertionError(
13
23
  notSatisfiedMessage(diff),