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.
- package/LICENSE +2 -2
- package/README.md +61 -46
- package/package.json +62 -24
- package/src/assert-order/AssertOrder.spec.ts +10 -12
- package/src/assert-order/AssertOrder.ts +8 -8
- package/src/assert-order/InvalidOrder.ts +7 -12
- package/src/assert-order/StateMachine.ts +26 -31
- package/src/assert-order/index.ts +3 -1
- package/src/assert-order/internalInterfaces.ts +3 -3
- package/src/assert-order/types.ts +7 -0
- package/src/assertron/assertron.spec.ts +2 -4
- package/src/assertron/assertron.ts +13 -14
- package/src/assertron/falsy.spec.ts +2 -3
- package/src/assertron/falsy.ts +2 -6
- package/src/assertron/pathEqual.spec.ts +2 -3
- package/src/assertron/pathEqual.ts +4 -7
- package/src/assertron/rejects.spec.ts +7 -8
- package/src/assertron/rejects.ts +3 -11
- package/src/assertron/repeat.spec.ts +8 -10
- package/src/assertron/repeat.ts +4 -9
- package/src/assertron/resolves.spec.ts +3 -4
- package/src/assertron/resolves.ts +3 -13
- package/src/assertron/satisfies.spec.ts +57 -26
- package/src/assertron/satisfies.ts +23 -10
- package/src/assertron/throws.spec.ts +58 -39
- package/src/assertron/throws.ts +30 -54
- package/src/assertron/truthy.spec.ts +2 -3
- package/src/assertron/truthy.ts +2 -3
- package/src/errors.ts +22 -0
- package/src/index.ts +2 -1
- package/src/testUtils.ts +16 -13
- package/src/{errors/interfaces.ts → types.ts} +1 -1
- package/src/utils/index.ts +12 -0
- package/src/utils/isErrorConstructor.ts +5 -0
- package/src/utils/notEqualMessage.ts +4 -0
- package/src/{errors → utils}/notSatisfiedMessage.spec.ts +0 -0
- package/src/{errors/NotSatisfied.ts → utils/notSatisfiedMessage.ts} +1 -1
- package/src/utils/notThrownMessage.ts +5 -0
- package/src/utils/promiseMessages.ts +12 -0
- package/src/{errors → utils}/unexpectedErrorMessage.ts +4 -3
- package/dist-es2015/assert-order/AssertOrder.d.ts +0 -40
- package/dist-es2015/assert-order/AssertOrder.js +0 -132
- package/dist-es2015/assert-order/AssertOrder.js.map +0 -1
- package/dist-es2015/assert-order/InvalidOrder.d.ts +0 -8
- package/dist-es2015/assert-order/InvalidOrder.js +0 -31
- package/dist-es2015/assert-order/InvalidOrder.js.map +0 -1
- package/dist-es2015/assert-order/StateMachine.d.ts +0 -23
- package/dist-es2015/assert-order/StateMachine.js +0 -106
- package/dist-es2015/assert-order/StateMachine.js.map +0 -1
- package/dist-es2015/assert-order/index.d.ts +0 -2
- package/dist-es2015/assert-order/index.js +0 -2
- package/dist-es2015/assert-order/index.js.map +0 -1
- package/dist-es2015/assert-order/interfaces.d.ts +0 -7
- package/dist-es2015/assert-order/interfaces.js +0 -1
- package/dist-es2015/assert-order/interfaces.js.map +0 -1
- package/dist-es2015/assertron/assertron.d.ts +0 -20
- package/dist-es2015/assertron/assertron.js +0 -28
- package/dist-es2015/assertron/assertron.js.map +0 -1
- package/dist-es2015/assertron/falsy.d.ts +0 -1
- package/dist-es2015/assertron/falsy.js +0 -6
- package/dist-es2015/assertron/falsy.js.map +0 -1
- package/dist-es2015/assertron/index.d.ts +0 -1
- package/dist-es2015/assertron/index.js +0 -2
- package/dist-es2015/assertron/index.js.map +0 -1
- package/dist-es2015/assertron/pathEqual.d.ts +0 -1
- package/dist-es2015/assertron/pathEqual.js +0 -8
- package/dist-es2015/assertron/pathEqual.js.map +0 -1
- package/dist-es2015/assertron/rejects.d.ts +0 -1
- package/dist-es2015/assertron/rejects.js +0 -10
- package/dist-es2015/assertron/rejects.js.map +0 -1
- package/dist-es2015/assertron/repeat.d.ts +0 -11
- package/dist-es2015/assertron/repeat.js +0 -35
- package/dist-es2015/assertron/repeat.js.map +0 -1
- package/dist-es2015/assertron/resolves.d.ts +0 -1
- package/dist-es2015/assertron/resolves.js +0 -12
- package/dist-es2015/assertron/resolves.js.map +0 -1
- package/dist-es2015/assertron/satisfies.d.ts +0 -5
- package/dist-es2015/assertron/satisfies.js +0 -14
- package/dist-es2015/assertron/satisfies.js.map +0 -1
- package/dist-es2015/assertron/throws.d.ts +0 -5
- package/dist-es2015/assertron/throws.js +0 -55
- package/dist-es2015/assertron/throws.js.map +0 -1
- package/dist-es2015/assertron/truthy.d.ts +0 -1
- package/dist-es2015/assertron/truthy.js +0 -6
- package/dist-es2015/assertron/truthy.js.map +0 -1
- package/dist-es2015/errors/NotSatisfied.d.ts +0 -2
- package/dist-es2015/errors/NotSatisfied.js +0 -23
- package/dist-es2015/errors/NotSatisfied.js.map +0 -1
- package/dist-es2015/errors/index.d.ts +0 -7
- package/dist-es2015/errors/index.js +0 -7
- package/dist-es2015/errors/index.js.map +0 -1
- package/dist-es2015/errors/interfaces.d.ts +0 -2
- package/dist-es2015/errors/interfaces.js +0 -1
- package/dist-es2015/errors/interfaces.js.map +0 -1
- package/dist-es2015/errors/notEqualMessage.d.ts +0 -1
- package/dist-es2015/errors/notEqualMessage.js +0 -4
- package/dist-es2015/errors/notEqualMessage.js.map +0 -1
- package/dist-es2015/errors/notRejectedMessage.d.ts +0 -1
- package/dist-es2015/errors/notRejectedMessage.js +0 -4
- package/dist-es2015/errors/notRejectedMessage.js.map +0 -1
- package/dist-es2015/errors/notThrownMessage.d.ts +0 -1
- package/dist-es2015/errors/notThrownMessage.js +0 -4
- package/dist-es2015/errors/notThrownMessage.js.map +0 -1
- package/dist-es2015/errors/returnNotRejectedMessage.d.ts +0 -1
- package/dist-es2015/errors/returnNotRejectedMessage.js +0 -4
- package/dist-es2015/errors/returnNotRejectedMessage.js.map +0 -1
- package/dist-es2015/errors/unexpectedErrorMessage.d.ts +0 -2
- package/dist-es2015/errors/unexpectedErrorMessage.js +0 -6
- package/dist-es2015/errors/unexpectedErrorMessage.js.map +0 -1
- package/dist-es2015/errors/util.d.ts +0 -2
- package/dist-es2015/errors/util.js +0 -4
- package/dist-es2015/errors/util.js.map +0 -1
- package/dist-es2015/index.d.ts +0 -4
- package/dist-es2015/index.js +0 -5
- package/dist-es2015/index.js.map +0 -1
- package/dist-es5/assert-order/AssertOrder.d.ts +0 -40
- package/dist-es5/assert-order/AssertOrder.js +0 -147
- package/dist-es5/assert-order/AssertOrder.js.map +0 -1
- package/dist-es5/assert-order/InvalidOrder.d.ts +0 -8
- package/dist-es5/assert-order/InvalidOrder.js +0 -58
- package/dist-es5/assert-order/InvalidOrder.js.map +0 -1
- package/dist-es5/assert-order/StateMachine.d.ts +0 -23
- package/dist-es5/assert-order/StateMachine.js +0 -115
- package/dist-es5/assert-order/StateMachine.js.map +0 -1
- package/dist-es5/assert-order/index.d.ts +0 -2
- package/dist-es5/assert-order/index.js +0 -7
- package/dist-es5/assert-order/index.js.map +0 -1
- package/dist-es5/assert-order/interfaces.d.ts +0 -7
- package/dist-es5/assert-order/interfaces.js +0 -3
- package/dist-es5/assert-order/interfaces.js.map +0 -1
- package/dist-es5/assertron/assertron.d.ts +0 -20
- package/dist-es5/assertron/assertron.js +0 -33
- package/dist-es5/assertron/assertron.js.map +0 -1
- package/dist-es5/assertron/falsy.d.ts +0 -1
- package/dist-es5/assertron/falsy.js +0 -12
- package/dist-es5/assertron/falsy.js.map +0 -1
- package/dist-es5/assertron/index.d.ts +0 -1
- package/dist-es5/assertron/index.js +0 -7
- package/dist-es5/assertron/index.js.map +0 -1
- package/dist-es5/assertron/pathEqual.d.ts +0 -1
- package/dist-es5/assertron/pathEqual.js +0 -14
- package/dist-es5/assertron/pathEqual.js.map +0 -1
- package/dist-es5/assertron/rejects.d.ts +0 -1
- package/dist-es5/assertron/rejects.js +0 -16
- package/dist-es5/assertron/rejects.js.map +0 -1
- package/dist-es5/assertron/repeat.d.ts +0 -11
- package/dist-es5/assertron/repeat.js +0 -58
- package/dist-es5/assertron/repeat.js.map +0 -1
- package/dist-es5/assertron/resolves.d.ts +0 -1
- package/dist-es5/assertron/resolves.js +0 -18
- package/dist-es5/assertron/resolves.js.map +0 -1
- package/dist-es5/assertron/satisfies.d.ts +0 -5
- package/dist-es5/assertron/satisfies.js +0 -20
- package/dist-es5/assertron/satisfies.js.map +0 -1
- package/dist-es5/assertron/throws.d.ts +0 -5
- package/dist-es5/assertron/throws.js +0 -61
- package/dist-es5/assertron/throws.js.map +0 -1
- package/dist-es5/assertron/truthy.d.ts +0 -1
- package/dist-es5/assertron/truthy.js +0 -12
- package/dist-es5/assertron/truthy.js.map +0 -1
- package/dist-es5/errors/NotSatisfied.d.ts +0 -2
- package/dist-es5/errors/NotSatisfied.js +0 -26
- package/dist-es5/errors/NotSatisfied.js.map +0 -1
- package/dist-es5/errors/index.d.ts +0 -7
- package/dist-es5/errors/index.js +0 -12
- package/dist-es5/errors/index.js.map +0 -1
- package/dist-es5/errors/interfaces.d.ts +0 -2
- package/dist-es5/errors/interfaces.js +0 -3
- package/dist-es5/errors/interfaces.js.map +0 -1
- package/dist-es5/errors/notEqualMessage.d.ts +0 -1
- package/dist-es5/errors/notEqualMessage.js +0 -7
- package/dist-es5/errors/notEqualMessage.js.map +0 -1
- package/dist-es5/errors/notRejectedMessage.d.ts +0 -1
- package/dist-es5/errors/notRejectedMessage.js +0 -7
- package/dist-es5/errors/notRejectedMessage.js.map +0 -1
- package/dist-es5/errors/notThrownMessage.d.ts +0 -1
- package/dist-es5/errors/notThrownMessage.js +0 -7
- package/dist-es5/errors/notThrownMessage.js.map +0 -1
- package/dist-es5/errors/returnNotRejectedMessage.d.ts +0 -1
- package/dist-es5/errors/returnNotRejectedMessage.js +0 -7
- package/dist-es5/errors/returnNotRejectedMessage.js.map +0 -1
- package/dist-es5/errors/unexpectedErrorMessage.d.ts +0 -2
- package/dist-es5/errors/unexpectedErrorMessage.js +0 -9
- package/dist-es5/errors/unexpectedErrorMessage.js.map +0 -1
- package/dist-es5/errors/util.d.ts +0 -2
- package/dist-es5/errors/util.js +0 -7
- package/dist-es5/errors/util.js.map +0 -1
- package/dist-es5/index.d.ts +0 -4
- package/dist-es5/index.js +0 -10
- package/dist-es5/index.js.map +0 -1
- package/src/assert-order/interfaces.ts +0 -7
- package/src/errors/index.ts +0 -7
- package/src/errors/notEqualMessage.ts +0 -3
- package/src/errors/notRejectedMessage.ts +0 -3
- package/src/errors/notThrownMessage.ts +0 -3
- package/src/errors/returnNotRejectedMessage.ts +0 -3
- 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
|
|
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
|
-
[![
|
|
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
|
-
[![
|
|
14
|
-
|
|
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
|
|
20
|
+
`assertron` provides a collection of assertion methods.
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
import { assertron } from 'assertron'
|
|
22
|
+
### assertron.false(value)
|
|
24
23
|
|
|
25
|
-
|
|
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.
|
|
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 [`
|
|
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
|
|
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
|
|
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
|
|
175
|
+
There are other methods available. Use TypeScript to discover them!
|
|
142
176
|
|
|
143
177
|
## Contribute
|
|
144
178
|
|
|
145
179
|
```sh
|
|
146
|
-
|
|
147
|
-
npm install
|
|
180
|
+
yarn
|
|
148
181
|
|
|
149
|
-
#
|
|
182
|
+
# start making changes
|
|
150
183
|
git checkout -b <branch>
|
|
151
|
-
|
|
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
|
-
|
|
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
|
-
|
|
178
|
-
# You normally don't need to do this.
|
|
179
|
-
npm run build
|
|
200
|
+
yarn watch
|
|
180
201
|
|
|
181
|
-
|
|
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
|
-
[
|
|
194
|
-
[
|
|
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": "
|
|
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
|
-
"
|
|
20
|
-
"
|
|
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": "
|
|
29
|
-
"build
|
|
30
|
-
"build
|
|
31
|
-
"
|
|
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
|
-
"
|
|
34
|
-
"
|
|
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
|
-
"
|
|
37
|
-
"
|
|
43
|
+
"test:watch": "jest --watch",
|
|
44
|
+
"verify": "yarn lint && yarn build && yarn dependency-check && yarn coverage",
|
|
45
|
+
"watch": "yarn test:watch"
|
|
38
46
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
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": "^
|
|
54
|
+
"is-promise": "^4.0.0",
|
|
55
|
+
"iso-error": "^4.1.0",
|
|
46
56
|
"path-equal": "^1.1.1",
|
|
47
|
-
"satisfier": "^5.
|
|
48
|
-
"tersify": "^3.
|
|
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
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
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
|
|
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))
|
|
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))
|
|
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))
|
|
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))
|
|
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())
|
|
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))
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
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
|
|
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]
|
|
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 '
|
|
2
|
-
import { State } from './
|
|
1
|
+
import { AssertionError } from '../errors'
|
|
2
|
+
import { State } from './types'
|
|
3
3
|
|
|
4
4
|
export class InvalidOrder extends AssertionError {
|
|
5
|
-
method: string
|
|
6
|
-
|
|
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(
|
|
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 './
|
|
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,
|
|
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
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
47
|
+
listeners: Record<number, Array<() => void>> = {}
|
|
48
|
+
step = 1
|
|
50
49
|
maxStep?: number
|
|
51
50
|
|
|
52
|
-
subStep
|
|
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
|
-
|
|
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
|
|
111
|
-
}
|
|
112
|
-
private getStartTick() {
|
|
113
|
-
return startTick()
|
|
108
|
+
return timeTracker.taken()
|
|
114
109
|
}
|
|
115
110
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import AssertionError from '
|
|
2
|
-
import
|
|
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)
|