assertron 7.1.2 → 9.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +61 -46
  3. package/package.json +62 -24
  4. package/src/assert-order/AssertOrder.spec.ts +10 -12
  5. package/src/assert-order/AssertOrder.ts +8 -8
  6. package/src/assert-order/InvalidOrder.ts +7 -12
  7. package/src/assert-order/StateMachine.ts +26 -31
  8. package/src/assert-order/index.ts +3 -1
  9. package/src/assert-order/internalInterfaces.ts +3 -3
  10. package/src/assert-order/types.ts +7 -0
  11. package/src/assertron/assertron.spec.ts +2 -4
  12. package/src/assertron/assertron.ts +13 -14
  13. package/src/assertron/falsy.spec.ts +2 -3
  14. package/src/assertron/falsy.ts +2 -6
  15. package/src/assertron/pathEqual.spec.ts +2 -3
  16. package/src/assertron/pathEqual.ts +4 -7
  17. package/src/assertron/rejects.spec.ts +7 -8
  18. package/src/assertron/rejects.ts +3 -11
  19. package/src/assertron/repeat.spec.ts +8 -10
  20. package/src/assertron/repeat.ts +4 -9
  21. package/src/assertron/resolves.spec.ts +3 -4
  22. package/src/assertron/resolves.ts +3 -13
  23. package/src/assertron/satisfies.spec.ts +57 -26
  24. package/src/assertron/satisfies.ts +23 -10
  25. package/src/assertron/throws.spec.ts +58 -39
  26. package/src/assertron/throws.ts +30 -54
  27. package/src/assertron/truthy.spec.ts +2 -3
  28. package/src/assertron/truthy.ts +2 -3
  29. package/src/errors.ts +22 -0
  30. package/src/index.ts +2 -1
  31. package/src/testUtils.ts +16 -13
  32. package/src/{errors/interfaces.ts → types.ts} +1 -1
  33. package/src/utils/index.ts +12 -0
  34. package/src/utils/isErrorConstructor.ts +5 -0
  35. package/src/utils/notEqualMessage.ts +4 -0
  36. package/src/{errors → utils}/notSatisfiedMessage.spec.ts +0 -0
  37. package/src/{errors/NotSatisfied.ts → utils/notSatisfiedMessage.ts} +1 -1
  38. package/src/utils/notThrownMessage.ts +5 -0
  39. package/src/utils/promiseMessages.ts +12 -0
  40. package/src/{errors → utils}/unexpectedErrorMessage.ts +4 -3
  41. package/dist-es2015/assert-order/AssertOrder.d.ts +0 -40
  42. package/dist-es2015/assert-order/AssertOrder.js +0 -132
  43. package/dist-es2015/assert-order/AssertOrder.js.map +0 -1
  44. package/dist-es2015/assert-order/InvalidOrder.d.ts +0 -8
  45. package/dist-es2015/assert-order/InvalidOrder.js +0 -31
  46. package/dist-es2015/assert-order/InvalidOrder.js.map +0 -1
  47. package/dist-es2015/assert-order/StateMachine.d.ts +0 -23
  48. package/dist-es2015/assert-order/StateMachine.js +0 -106
  49. package/dist-es2015/assert-order/StateMachine.js.map +0 -1
  50. package/dist-es2015/assert-order/index.d.ts +0 -2
  51. package/dist-es2015/assert-order/index.js +0 -2
  52. package/dist-es2015/assert-order/index.js.map +0 -1
  53. package/dist-es2015/assert-order/interfaces.d.ts +0 -7
  54. package/dist-es2015/assert-order/interfaces.js +0 -1
  55. package/dist-es2015/assert-order/interfaces.js.map +0 -1
  56. package/dist-es2015/assertron/assertron.d.ts +0 -20
  57. package/dist-es2015/assertron/assertron.js +0 -28
  58. package/dist-es2015/assertron/assertron.js.map +0 -1
  59. package/dist-es2015/assertron/falsy.d.ts +0 -1
  60. package/dist-es2015/assertron/falsy.js +0 -6
  61. package/dist-es2015/assertron/falsy.js.map +0 -1
  62. package/dist-es2015/assertron/index.d.ts +0 -1
  63. package/dist-es2015/assertron/index.js +0 -2
  64. package/dist-es2015/assertron/index.js.map +0 -1
  65. package/dist-es2015/assertron/pathEqual.d.ts +0 -1
  66. package/dist-es2015/assertron/pathEqual.js +0 -8
  67. package/dist-es2015/assertron/pathEqual.js.map +0 -1
  68. package/dist-es2015/assertron/rejects.d.ts +0 -1
  69. package/dist-es2015/assertron/rejects.js +0 -10
  70. package/dist-es2015/assertron/rejects.js.map +0 -1
  71. package/dist-es2015/assertron/repeat.d.ts +0 -11
  72. package/dist-es2015/assertron/repeat.js +0 -35
  73. package/dist-es2015/assertron/repeat.js.map +0 -1
  74. package/dist-es2015/assertron/resolves.d.ts +0 -1
  75. package/dist-es2015/assertron/resolves.js +0 -12
  76. package/dist-es2015/assertron/resolves.js.map +0 -1
  77. package/dist-es2015/assertron/satisfies.d.ts +0 -5
  78. package/dist-es2015/assertron/satisfies.js +0 -14
  79. package/dist-es2015/assertron/satisfies.js.map +0 -1
  80. package/dist-es2015/assertron/throws.d.ts +0 -5
  81. package/dist-es2015/assertron/throws.js +0 -55
  82. package/dist-es2015/assertron/throws.js.map +0 -1
  83. package/dist-es2015/assertron/truthy.d.ts +0 -1
  84. package/dist-es2015/assertron/truthy.js +0 -6
  85. package/dist-es2015/assertron/truthy.js.map +0 -1
  86. package/dist-es2015/errors/NotSatisfied.d.ts +0 -2
  87. package/dist-es2015/errors/NotSatisfied.js +0 -23
  88. package/dist-es2015/errors/NotSatisfied.js.map +0 -1
  89. package/dist-es2015/errors/index.d.ts +0 -7
  90. package/dist-es2015/errors/index.js +0 -7
  91. package/dist-es2015/errors/index.js.map +0 -1
  92. package/dist-es2015/errors/interfaces.d.ts +0 -2
  93. package/dist-es2015/errors/interfaces.js +0 -1
  94. package/dist-es2015/errors/interfaces.js.map +0 -1
  95. package/dist-es2015/errors/notEqualMessage.d.ts +0 -1
  96. package/dist-es2015/errors/notEqualMessage.js +0 -4
  97. package/dist-es2015/errors/notEqualMessage.js.map +0 -1
  98. package/dist-es2015/errors/notRejectedMessage.d.ts +0 -1
  99. package/dist-es2015/errors/notRejectedMessage.js +0 -4
  100. package/dist-es2015/errors/notRejectedMessage.js.map +0 -1
  101. package/dist-es2015/errors/notThrownMessage.d.ts +0 -1
  102. package/dist-es2015/errors/notThrownMessage.js +0 -4
  103. package/dist-es2015/errors/notThrownMessage.js.map +0 -1
  104. package/dist-es2015/errors/returnNotRejectedMessage.d.ts +0 -1
  105. package/dist-es2015/errors/returnNotRejectedMessage.js +0 -4
  106. package/dist-es2015/errors/returnNotRejectedMessage.js.map +0 -1
  107. package/dist-es2015/errors/unexpectedErrorMessage.d.ts +0 -2
  108. package/dist-es2015/errors/unexpectedErrorMessage.js +0 -6
  109. package/dist-es2015/errors/unexpectedErrorMessage.js.map +0 -1
  110. package/dist-es2015/errors/util.d.ts +0 -2
  111. package/dist-es2015/errors/util.js +0 -4
  112. package/dist-es2015/errors/util.js.map +0 -1
  113. package/dist-es2015/index.d.ts +0 -4
  114. package/dist-es2015/index.js +0 -5
  115. package/dist-es2015/index.js.map +0 -1
  116. package/dist-es5/assert-order/AssertOrder.d.ts +0 -40
  117. package/dist-es5/assert-order/AssertOrder.js +0 -147
  118. package/dist-es5/assert-order/AssertOrder.js.map +0 -1
  119. package/dist-es5/assert-order/InvalidOrder.d.ts +0 -8
  120. package/dist-es5/assert-order/InvalidOrder.js +0 -58
  121. package/dist-es5/assert-order/InvalidOrder.js.map +0 -1
  122. package/dist-es5/assert-order/StateMachine.d.ts +0 -23
  123. package/dist-es5/assert-order/StateMachine.js +0 -115
  124. package/dist-es5/assert-order/StateMachine.js.map +0 -1
  125. package/dist-es5/assert-order/index.d.ts +0 -2
  126. package/dist-es5/assert-order/index.js +0 -7
  127. package/dist-es5/assert-order/index.js.map +0 -1
  128. package/dist-es5/assert-order/interfaces.d.ts +0 -7
  129. package/dist-es5/assert-order/interfaces.js +0 -3
  130. package/dist-es5/assert-order/interfaces.js.map +0 -1
  131. package/dist-es5/assertron/assertron.d.ts +0 -20
  132. package/dist-es5/assertron/assertron.js +0 -33
  133. package/dist-es5/assertron/assertron.js.map +0 -1
  134. package/dist-es5/assertron/falsy.d.ts +0 -1
  135. package/dist-es5/assertron/falsy.js +0 -12
  136. package/dist-es5/assertron/falsy.js.map +0 -1
  137. package/dist-es5/assertron/index.d.ts +0 -1
  138. package/dist-es5/assertron/index.js +0 -7
  139. package/dist-es5/assertron/index.js.map +0 -1
  140. package/dist-es5/assertron/pathEqual.d.ts +0 -1
  141. package/dist-es5/assertron/pathEqual.js +0 -14
  142. package/dist-es5/assertron/pathEqual.js.map +0 -1
  143. package/dist-es5/assertron/rejects.d.ts +0 -1
  144. package/dist-es5/assertron/rejects.js +0 -16
  145. package/dist-es5/assertron/rejects.js.map +0 -1
  146. package/dist-es5/assertron/repeat.d.ts +0 -11
  147. package/dist-es5/assertron/repeat.js +0 -58
  148. package/dist-es5/assertron/repeat.js.map +0 -1
  149. package/dist-es5/assertron/resolves.d.ts +0 -1
  150. package/dist-es5/assertron/resolves.js +0 -18
  151. package/dist-es5/assertron/resolves.js.map +0 -1
  152. package/dist-es5/assertron/satisfies.d.ts +0 -5
  153. package/dist-es5/assertron/satisfies.js +0 -20
  154. package/dist-es5/assertron/satisfies.js.map +0 -1
  155. package/dist-es5/assertron/throws.d.ts +0 -5
  156. package/dist-es5/assertron/throws.js +0 -61
  157. package/dist-es5/assertron/throws.js.map +0 -1
  158. package/dist-es5/assertron/truthy.d.ts +0 -1
  159. package/dist-es5/assertron/truthy.js +0 -12
  160. package/dist-es5/assertron/truthy.js.map +0 -1
  161. package/dist-es5/errors/NotSatisfied.d.ts +0 -2
  162. package/dist-es5/errors/NotSatisfied.js +0 -26
  163. package/dist-es5/errors/NotSatisfied.js.map +0 -1
  164. package/dist-es5/errors/index.d.ts +0 -7
  165. package/dist-es5/errors/index.js +0 -12
  166. package/dist-es5/errors/index.js.map +0 -1
  167. package/dist-es5/errors/interfaces.d.ts +0 -2
  168. package/dist-es5/errors/interfaces.js +0 -3
  169. package/dist-es5/errors/interfaces.js.map +0 -1
  170. package/dist-es5/errors/notEqualMessage.d.ts +0 -1
  171. package/dist-es5/errors/notEqualMessage.js +0 -7
  172. package/dist-es5/errors/notEqualMessage.js.map +0 -1
  173. package/dist-es5/errors/notRejectedMessage.d.ts +0 -1
  174. package/dist-es5/errors/notRejectedMessage.js +0 -7
  175. package/dist-es5/errors/notRejectedMessage.js.map +0 -1
  176. package/dist-es5/errors/notThrownMessage.d.ts +0 -1
  177. package/dist-es5/errors/notThrownMessage.js +0 -7
  178. package/dist-es5/errors/notThrownMessage.js.map +0 -1
  179. package/dist-es5/errors/returnNotRejectedMessage.d.ts +0 -1
  180. package/dist-es5/errors/returnNotRejectedMessage.js +0 -7
  181. package/dist-es5/errors/returnNotRejectedMessage.js.map +0 -1
  182. package/dist-es5/errors/unexpectedErrorMessage.d.ts +0 -2
  183. package/dist-es5/errors/unexpectedErrorMessage.js +0 -9
  184. package/dist-es5/errors/unexpectedErrorMessage.js.map +0 -1
  185. package/dist-es5/errors/util.d.ts +0 -2
  186. package/dist-es5/errors/util.js +0 -7
  187. package/dist-es5/errors/util.js.map +0 -1
  188. package/dist-es5/index.d.ts +0 -4
  189. package/dist-es5/index.js +0 -10
  190. package/dist-es5/index.js.map +0 -1
  191. package/src/assert-order/interfaces.ts +0 -7
  192. package/src/errors/index.ts +0 -7
  193. package/src/errors/notEqualMessage.ts +0 -3
  194. package/src/errors/notRejectedMessage.ts +0 -3
  195. package/src/errors/notThrownMessage.ts +0 -3
  196. package/src/errors/returnNotRejectedMessage.ts +0 -3
  197. package/src/errors/util.ts +0 -5
package/LICENSE CHANGED
@@ -14,8 +14,8 @@ all copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
package/README.md CHANGED
@@ -5,41 +5,51 @@
5
5
  [![NPM version][npm-image]][npm-url]
6
6
  [![NPM downloads][downloads-image]][downloads-url]
7
7
 
8
- [![TravisCI][travis-image]][travis-url]
9
- [![CircleCI][circleci-image]][circleci-url]
8
+ [![Github NodeJS][github-nodejs]][github-action-url]
10
9
  [![Codecov][codecov-image]][codecov-url]
11
10
  [![Coverage Status][coveralls-image]][coveralls-url]
12
11
 
13
- [![Greenkeeper badge](https://badges.greenkeeper.io/unional/assertron.svg)](https://greenkeeper.io/)
14
- [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
12
+ [![Semantic Release][semantic-release-image]][semantic-release-url]
13
+
14
+ [![Visual Studio Code][vscode-image]][vscode-url]
15
15
 
16
16
  A supplementary assertion library that runs on both NodeJS and browser.
17
17
 
18
18
  ## assertron
19
19
 
20
- `assertron` provides additional or improved assertion functions of the `assert` module.
20
+ `assertron` provides a collection of assertion methods.
21
21
 
22
- ```ts
23
- import { assertron } from 'assertron'
22
+ ### assertron.false(value)
24
23
 
25
- assertron.throws(Promise.reject(new Error('foo')))
26
- assertron.throws(() => { throw new Error('foo') })
27
- assertron.throws(() => Promise.reject(new Error('foo')))
24
+ Asserts the provided value is false.
28
25
 
29
- assertron.pathEqual('dir/sub-dir/file.txt', 'dir\\sub-dir\\file.txt')
30
- ```
26
+ ### assertron.falsy(value)
27
+
28
+ Asserts the provided value is falsy.
29
+
30
+ ### assertron.pathEqual(actual, expected)
31
+
32
+ Asserts the two paths are equal regardless of operating system differences.
33
+
34
+ ### assertron.rejects(promise)
35
+
36
+ Asserts the promise rejects.
31
37
 
32
38
  ### assertron.repeat(fn, times)
33
39
 
34
40
  Repeat the specified function n times and return the last result.
35
41
  If the result is a promise, it will run the function sequentially.
36
42
 
43
+ ### assertron.resolves(promise)
44
+
45
+ Asserts the promise resolves.
46
+
37
47
  ### assertron.satisfies(actual, expected)
38
48
 
39
49
  `assertron.satisfies()` checks if `actual` meets the requirements specified by `expected`.
40
50
  Each property in `expected` can be a value, a `RegExp`, or a predicate function.
41
51
  It uses `satisfier` internally to check for validity.
42
- Check out [`sateisfier`](https://github.com/unional/satisfier) for more detail.
52
+ Check out [`satisfier`](https://github.com/unional/satisfier) for more detail.
43
53
 
44
54
  ```ts
45
55
  import a from 'assertron' // assertron is also exported as default.
@@ -56,9 +66,33 @@ a.satisfies({ a: 'foo' }, { a: /boo/ })
56
66
  a.satisfies({ a: 1 }, { a: () => false })
57
67
  ```
58
68
 
69
+ ### assertron.throws(...)
70
+
71
+ Asserts the promise, function, or async function throws (or rejects) an error.
72
+
73
+ ```ts
74
+ import { assertron } from 'assertron'
75
+
76
+ await assertron.throws(Promise.reject(new Error('foo')))
77
+ assertron.throws(() => { throw new Error('foo') })
78
+ await assertron.throws(() => Promise.reject(new Error('foo')))
79
+
80
+ const e1 = await assertron.throws(Promise.reject(new SpecificError('foo')), SpecificError)
81
+ const e2 = assertron.throws(() => { throw new SpecificError('foo') }, SpecificError)
82
+ const e3 = await assertron.throws(() => Promise.reject(new SpecificError('foo')), SpecificError)
83
+ ```
84
+
85
+ ### assertron.true(value)
86
+
87
+ Asserts the provided value is true.
88
+
89
+ ### assertron.truthy(value)
90
+
91
+ Asserts the provided value is truthy.
92
+
59
93
  ## AssertOrder
60
94
 
61
- Assert code are executed in expected order.
95
+ Assert the code is executed in the expected order.
62
96
 
63
97
  ### order.once(step: number)
64
98
 
@@ -94,7 +128,7 @@ boo()
94
128
 
95
129
  ### order.atLeastOnce(step: number)
96
130
 
97
- Assert step `step` have executed at least once.
131
+ Assert the `step` executed at least once.
98
132
 
99
133
  ```ts
100
134
  import { AssertOrder } from 'assertron'
@@ -138,19 +172,16 @@ for (let i = 1; i <= 4; i++) {
138
172
  }
139
173
  ```
140
174
 
141
- There are more methods available. Use TypeScript to discover them!
175
+ There are other methods available. Use TypeScript to discover them!
142
176
 
143
177
  ## Contribute
144
178
 
145
179
  ```sh
146
- # right after fork
147
- npm install
180
+ yarn
148
181
 
149
- # begin making changes
182
+ # start making changes
150
183
  git checkout -b <branch>
151
- npm run watch
152
-
153
- # edit `webpack.config.dev.js` to exclude dependencies for the global build.
184
+ yarn watch
154
185
 
155
186
  # after making change(s)
156
187
  git commit -m "<commit message>"
@@ -164,43 +195,27 @@ git push
164
195
  There are a few useful commands you can use during development.
165
196
 
166
197
  ```sh
167
- # Run tests (and lint) automatically whenever you save a file.
168
- npm run watch
169
-
170
- # Run tests with coverage stats (but won't fail you if coverage does not meet criteria)
171
- npm run test
172
-
173
- # Manually verify the project.
174
- # This will be ran during 'npm preversion' so you normally don't need to run this yourself.
175
- npm run verify
198
+ yarn test
176
199
 
177
- # Build the project.
178
- # You normally don't need to do this.
179
- npm run build
200
+ yarn watch
180
201
 
181
- # Run tslint
182
- # You normally don't need to do this as `npm run watch` and `npm version` will automatically run lint for you.
183
- npm run lint
202
+ yarn verify
184
203
  ```
185
204
 
186
- Generated by `generator-unional@0.0.1`
187
-
188
205
  [npm-image]: https://img.shields.io/npm/v/assertron.svg?style=flat
189
206
  [npm-url]: https://npmjs.org/package/assertron
190
207
  [downloads-image]: https://img.shields.io/npm/dm/assertron.svg?style=flat
191
208
  [downloads-url]: https://npmjs.org/package/assertron
192
209
 
193
- [travis-image]: https://img.shields.io/travis/unional/assertron/master.svg?style=flat
194
- [travis-url]: https://travis-ci.org/unional/assertron?branch=master
195
- [circleci-image]: https://circleci.com/gh/unional/assertron/tree/master.svg?style=shield
196
- [circleci-url]: https://circleci.com/gh/unional/assertron/tree/master
197
-
210
+ [github-nodejs]: https://github.com/unional/assertron/workflows/nodejs/badge.svg
211
+ [github-action-url]: https://github.com/unional/assertron/actions
198
212
  [codecov-image]: https://codecov.io/gh/unional/assertron/branch/master/graph/badge.svg
199
213
  [codecov-url]: https://codecov.io/gh/unional/assertron
200
214
  [coveralls-image]: https://coveralls.io/repos/github/unional/assertron/badge.svg
201
215
  [coveralls-url]: https://coveralls.io/github/unional/assertron
202
216
 
203
- [green-keeper-image]: https://badges.greenkeeper.io/unional/assertron.svg
204
- [green-keeper-url]: https://greenkeeper.io/
205
217
  [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
206
218
  [semantic-release-url]: https://github.com/semantic-release/semantic-release
219
+
220
+ [vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
221
+ [vscode-url]: https://code.visualstudio.com/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assertron",
3
- "version": "7.1.2",
3
+ "version": "9.0.1",
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 lib libm",
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": "^4.0.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": "^16.0.0",
69
+ "@commitlint/config-conventional": "^16.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)