assertron 7.1.3 → 9.0.2
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 +11 -29
- package/package.json +48 -34
- package/src/assert-order/AssertOrder.spec.ts +10 -11
- package/src/assert-order/AssertOrder.ts +7 -7
- package/src/assert-order/InvalidOrder.ts +6 -8
- package/src/assert-order/StateMachine.ts +4 -4
- package/src/assert-order/index.ts +3 -1
- package/src/assert-order/{interfaces.ts → types.ts} +0 -0
- package/src/assertron/assertron.spec.ts +2 -3
- 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 -9
- package/src/assertron/repeat.spec.ts +7 -9
- package/src/assertron/repeat.ts +4 -9
- package/src/assertron/resolves.spec.ts +3 -4
- package/src/assertron/resolves.ts +3 -10
- package/src/assertron/satisfies.spec.ts +53 -21
- package/src/assertron/satisfies.ts +23 -10
- package/src/assertron/throws.spec.ts +46 -35
- package/src/assertron/throws.ts +29 -53
- 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} +0 -0
- package/src/utils/index.ts +12 -0
- package/src/{errors/util.ts → utils/isErrorConstructor.ts} +1 -1
- package/src/utils/notEqualMessage.ts +4 -0
- package/src/{errors → utils}/notSatisfiedMessage.spec.ts +0 -0
- package/src/{errors/NotSatisfied.ts → utils/notSatisfiedMessage.ts} +0 -0
- package/src/{errors → utils}/notThrownMessage.ts +0 -0
- package/src/utils/promiseMessages.ts +12 -0
- package/src/{errors → utils}/unexpectedErrorMessage.ts +4 -3
- package/lib/assert-order/AssertOrder.d.ts +0 -41
- package/lib/assert-order/AssertOrder.d.ts.map +0 -1
- package/lib/assert-order/AssertOrder.js +0 -147
- package/lib/assert-order/InvalidOrder.d.ts +0 -6
- package/lib/assert-order/InvalidOrder.d.ts.map +0 -1
- package/lib/assert-order/InvalidOrder.js +0 -43
- package/lib/assert-order/StateMachine.d.ts +0 -22
- package/lib/assert-order/StateMachine.d.ts.map +0 -1
- package/lib/assert-order/StateMachine.js +0 -109
- package/lib/assert-order/index.d.ts +0 -3
- package/lib/assert-order/index.d.ts.map +0 -1
- package/lib/assert-order/index.js +0 -5
- package/lib/assert-order/interfaces.d.ts +0 -8
- package/lib/assert-order/interfaces.d.ts.map +0 -1
- package/lib/assert-order/interfaces.js +0 -3
- package/lib/assertron/assertron.d.ts +0 -21
- package/lib/assertron/assertron.d.ts.map +0 -1
- package/lib/assertron/assertron.js +0 -31
- package/lib/assertron/falsy.d.ts +0 -2
- package/lib/assertron/falsy.d.ts.map +0 -1
- package/lib/assertron/falsy.js +0 -10
- package/lib/assertron/index.d.ts +0 -2
- package/lib/assertron/index.d.ts.map +0 -1
- package/lib/assertron/index.js +0 -5
- package/lib/assertron/pathEqual.d.ts +0 -2
- package/lib/assertron/pathEqual.d.ts.map +0 -1
- package/lib/assertron/pathEqual.js +0 -12
- package/lib/assertron/rejects.d.ts +0 -2
- package/lib/assertron/rejects.d.ts.map +0 -1
- package/lib/assertron/rejects.js +0 -13
- package/lib/assertron/repeat.d.ts +0 -12
- package/lib/assertron/repeat.d.ts.map +0 -1
- package/lib/assertron/repeat.js +0 -43
- package/lib/assertron/resolves.d.ts +0 -2
- package/lib/assertron/resolves.d.ts.map +0 -1
- package/lib/assertron/resolves.js +0 -16
- package/lib/assertron/satisfies.d.ts +0 -6
- package/lib/assertron/satisfies.d.ts.map +0 -1
- package/lib/assertron/satisfies.js +0 -18
- package/lib/assertron/throws.d.ts +0 -6
- package/lib/assertron/throws.d.ts.map +0 -1
- package/lib/assertron/throws.js +0 -59
- package/lib/assertron/truthy.d.ts +0 -2
- package/lib/assertron/truthy.d.ts.map +0 -1
- package/lib/assertron/truthy.js +0 -10
- package/lib/errors/NotSatisfied.d.ts +0 -3
- package/lib/errors/NotSatisfied.d.ts.map +0 -1
- package/lib/errors/NotSatisfied.js +0 -27
- package/lib/errors/index.d.ts +0 -8
- package/lib/errors/index.d.ts.map +0 -1
- package/lib/errors/index.js +0 -10
- package/lib/errors/interfaces.d.ts +0 -3
- package/lib/errors/interfaces.d.ts.map +0 -1
- package/lib/errors/interfaces.js +0 -3
- package/lib/errors/notEqualMessage.d.ts +0 -2
- package/lib/errors/notEqualMessage.d.ts.map +0 -1
- package/lib/errors/notEqualMessage.js +0 -7
- package/lib/errors/notRejectedMessage.d.ts +0 -2
- package/lib/errors/notRejectedMessage.d.ts.map +0 -1
- package/lib/errors/notRejectedMessage.js +0 -7
- package/lib/errors/notThrownMessage.d.ts +0 -2
- package/lib/errors/notThrownMessage.d.ts.map +0 -1
- package/lib/errors/notThrownMessage.js +0 -8
- package/lib/errors/returnNotRejectedMessage.d.ts +0 -2
- package/lib/errors/returnNotRejectedMessage.d.ts.map +0 -1
- package/lib/errors/returnNotRejectedMessage.js +0 -7
- package/lib/errors/unexpectedErrorMessage.d.ts +0 -3
- package/lib/errors/unexpectedErrorMessage.d.ts.map +0 -1
- package/lib/errors/unexpectedErrorMessage.js +0 -9
- package/lib/errors/util.d.ts +0 -3
- package/lib/errors/util.d.ts.map +0 -1
- package/lib/errors/util.js +0 -7
- package/lib/index.d.ts +0 -5
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -8
- package/libm/assert-order/AssertOrder.js +0 -132
- package/libm/assert-order/InvalidOrder.js +0 -31
- package/libm/assert-order/StateMachine.js +0 -102
- package/libm/assert-order/index.js +0 -2
- package/libm/assert-order/interfaces.js +0 -1
- package/libm/assertron/assertron.js +0 -28
- package/libm/assertron/falsy.js +0 -6
- package/libm/assertron/index.js +0 -2
- package/libm/assertron/pathEqual.js +0 -8
- package/libm/assertron/rejects.js +0 -9
- package/libm/assertron/repeat.js +0 -35
- package/libm/assertron/resolves.js +0 -12
- package/libm/assertron/satisfies.js +0 -14
- package/libm/assertron/throws.js +0 -55
- package/libm/assertron/truthy.js +0 -6
- package/libm/errors/NotSatisfied.js +0 -23
- package/libm/errors/index.js +0 -7
- package/libm/errors/interfaces.js +0 -1
- package/libm/errors/notEqualMessage.js +0 -4
- package/libm/errors/notRejectedMessage.js +0 -4
- package/libm/errors/notThrownMessage.js +0 -5
- package/libm/errors/returnNotRejectedMessage.js +0 -4
- package/libm/errors/unexpectedErrorMessage.js +0 -6
- package/libm/errors/util.js +0 -4
- package/libm/index.js +0 -5
- package/src/errors/index.ts +0 -7
- package/src/errors/notEqualMessage.ts +0 -3
- package/src/errors/notRejectedMessage.ts +0 -3
- package/src/errors/returnNotRejectedMessage.ts +0 -3
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
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
[![Codecov][codecov-image]][codecov-url]
|
|
10
10
|
[![Coverage Status][coveralls-image]][coveralls-url]
|
|
11
11
|
|
|
12
|
-
[![Greenkeeper][greenkeeper-image]][greenkeeper-url]
|
|
13
12
|
[![Semantic Release][semantic-release-image]][semantic-release-url]
|
|
14
13
|
|
|
15
14
|
[![Visual Studio Code][vscode-image]][vscode-url]
|
|
@@ -26,7 +25,7 @@ Asserts the provided value is false.
|
|
|
26
25
|
|
|
27
26
|
### assertron.falsy(value)
|
|
28
27
|
|
|
29
|
-
Asserts the
|
|
28
|
+
Asserts the provided value is falsy.
|
|
30
29
|
|
|
31
30
|
### assertron.pathEqual(actual, expected)
|
|
32
31
|
|
|
@@ -50,7 +49,7 @@ Asserts the promise resolves.
|
|
|
50
49
|
`assertron.satisfies()` checks if `actual` meets the requirements specified by `expected`.
|
|
51
50
|
Each property in `expected` can be a value, a `RegExp`, or a predicate function.
|
|
52
51
|
It uses `satisfier` internally to check for validity.
|
|
53
|
-
Check out [`
|
|
52
|
+
Check out [`satisfier`](https://github.com/unional/satisfier) for more detail.
|
|
54
53
|
|
|
55
54
|
```ts
|
|
56
55
|
import a from 'assertron' // assertron is also exported as default.
|
|
@@ -69,7 +68,7 @@ a.satisfies({ a: 1 }, { a: () => false })
|
|
|
69
68
|
|
|
70
69
|
### assertron.throws(...)
|
|
71
70
|
|
|
72
|
-
Asserts the promise, function, or async function throws (or
|
|
71
|
+
Asserts the promise, function, or async function throws (or rejects) an error.
|
|
73
72
|
|
|
74
73
|
```ts
|
|
75
74
|
import { assertron } from 'assertron'
|
|
@@ -93,7 +92,7 @@ Asserts the provided value is truthy.
|
|
|
93
92
|
|
|
94
93
|
## AssertOrder
|
|
95
94
|
|
|
96
|
-
Assert code
|
|
95
|
+
Assert the code is executed in the expected order.
|
|
97
96
|
|
|
98
97
|
### order.once(step: number)
|
|
99
98
|
|
|
@@ -129,7 +128,7 @@ boo()
|
|
|
129
128
|
|
|
130
129
|
### order.atLeastOnce(step: number)
|
|
131
130
|
|
|
132
|
-
Assert
|
|
131
|
+
Assert the `step` executed at least once.
|
|
133
132
|
|
|
134
133
|
```ts
|
|
135
134
|
import { AssertOrder } from 'assertron'
|
|
@@ -178,14 +177,11 @@ There are other methods available. Use TypeScript to discover them!
|
|
|
178
177
|
## Contribute
|
|
179
178
|
|
|
180
179
|
```sh
|
|
181
|
-
|
|
182
|
-
npm install
|
|
180
|
+
yarn
|
|
183
181
|
|
|
184
|
-
#
|
|
182
|
+
# start making changes
|
|
185
183
|
git checkout -b <branch>
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
# edit `webpack.config.dev.js` to exclude dependencies for the global build.
|
|
184
|
+
yarn watch
|
|
189
185
|
|
|
190
186
|
# after making change(s)
|
|
191
187
|
git commit -m "<commit message>"
|
|
@@ -199,23 +195,11 @@ git push
|
|
|
199
195
|
There are a few useful commands you can use during development.
|
|
200
196
|
|
|
201
197
|
```sh
|
|
202
|
-
|
|
203
|
-
npm run watch
|
|
204
|
-
|
|
205
|
-
# Run tests with coverage stats (but won't fail you if coverage does not meet criteria)
|
|
206
|
-
npm run test
|
|
207
|
-
|
|
208
|
-
# Manually verify the project.
|
|
209
|
-
# This will be ran during 'npm preversion' so you normally don't need to run this yourself.
|
|
210
|
-
npm run verify
|
|
198
|
+
yarn test
|
|
211
199
|
|
|
212
|
-
|
|
213
|
-
# You normally don't need to do this.
|
|
214
|
-
npm run build
|
|
200
|
+
yarn watch
|
|
215
201
|
|
|
216
|
-
|
|
217
|
-
# You normally don't need to do this as `npm run watch` and `npm version` will automatically run lint for you.
|
|
218
|
-
npm run lint
|
|
202
|
+
yarn verify
|
|
219
203
|
```
|
|
220
204
|
|
|
221
205
|
[npm-image]: https://img.shields.io/npm/v/assertron.svg?style=flat
|
|
@@ -230,8 +214,6 @@ npm run lint
|
|
|
230
214
|
[coveralls-image]: https://coveralls.io/repos/github/unional/assertron/badge.svg
|
|
231
215
|
[coveralls-url]: https://coveralls.io/github/unional/assertron
|
|
232
216
|
|
|
233
|
-
[greenkeeper-image]: https://badges.greenkeeper.io/unional/assertron.svg
|
|
234
|
-
[greenkeeper-url]: https://greenkeeper.io/
|
|
235
217
|
[semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
|
236
218
|
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
237
219
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assertron",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.2",
|
|
4
4
|
"description": "A supplementary assertion library",
|
|
5
5
|
"homepage": "https://github.com/unional/assertron",
|
|
6
6
|
"bugs": {
|
|
@@ -16,31 +16,29 @@
|
|
|
16
16
|
"email": "homawong@gmail.com"
|
|
17
17
|
},
|
|
18
18
|
"sideEffects": false,
|
|
19
|
-
"main": "
|
|
20
|
-
"module": "
|
|
21
|
-
"jsnext:main": "
|
|
19
|
+
"main": "cjs/index.js",
|
|
20
|
+
"module": "esm/index.js",
|
|
21
|
+
"jsnext:main": "esm/index.js",
|
|
22
22
|
"browser": {
|
|
23
23
|
"perf_hooks": false
|
|
24
24
|
},
|
|
25
|
-
"typings": "
|
|
25
|
+
"typings": "cjs/index.d.ts",
|
|
26
26
|
"files": [
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"cjs",
|
|
28
|
+
"esm",
|
|
29
29
|
"src"
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
|
-
"build": "yarn build:
|
|
33
|
-
"build:
|
|
34
|
-
"build:
|
|
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
35
|
"build:watch": "tsc --watch",
|
|
36
|
-
"clean": "rimraf .nyc_output .ts coverage lib libm",
|
|
37
|
-
"codacy": "cat coverage/lcov.info | codacy-coverage",
|
|
36
|
+
"clean": "rimraf .nyc_output .ts coverage cjs esm lib libm",
|
|
38
37
|
"coverage": "jest --coverage",
|
|
39
38
|
"depcheck": "yarn dependency-check",
|
|
40
|
-
"dependency-check": "dependency-check . --unused --no-dev -i global-store -i @types/node -i standard-log-color && dependency-check . --missing --no-dev",
|
|
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",
|
|
41
40
|
"lint": "eslint --ext=js,ts .",
|
|
42
41
|
"nuke": "yarn clean && rimraf node_modules",
|
|
43
|
-
"semantic-release": "semantic-release",
|
|
44
42
|
"test": "jest",
|
|
45
43
|
"test:watch": "jest --watch",
|
|
46
44
|
"verify": "yarn lint && yarn build && yarn dependency-check && yarn coverage",
|
|
@@ -52,28 +50,44 @@
|
|
|
52
50
|
}
|
|
53
51
|
},
|
|
54
52
|
"dependencies": {
|
|
55
|
-
"assertion-error": "^1.1.0",
|
|
56
53
|
"is-node": "^1.0.2",
|
|
57
|
-
"is-promise": "^
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
54
|
+
"is-promise": "^4.0.0",
|
|
55
|
+
"iso-error": "^4.1.0",
|
|
56
|
+
"path-equal": "^1.1.3",
|
|
57
|
+
"satisfier": "^5.1.1",
|
|
58
|
+
"tersify": "^3.7.11",
|
|
59
|
+
"tslib": "^2.3.1",
|
|
60
|
+
"type-plus": "^4.0.0"
|
|
62
61
|
},
|
|
63
62
|
"devDependencies": {
|
|
64
|
-
"@babel/core": "^7.
|
|
65
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
66
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
67
|
-
"@babel/preset-env": "^7.
|
|
68
|
-
"@babel/preset-typescript": "^7.
|
|
69
|
-
"@commitlint/cli": "^
|
|
70
|
-
"@commitlint/config-conventional": "^
|
|
71
|
-
"@types/
|
|
72
|
-
"@
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
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"
|
|
78
92
|
}
|
|
79
93
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import t from 'assert';
|
|
2
|
-
import
|
|
3
|
-
import a, { AssertOrder, State } from '..';
|
|
2
|
+
import a, { AssertOrder, InvalidOrder, State } from '..';
|
|
4
3
|
|
|
5
4
|
test('is() expecting 1', () => {
|
|
6
5
|
const order = new AssertOrder()
|
|
@@ -255,7 +254,7 @@ test(`onAny() throws if all assert functions throws`, () => {
|
|
|
255
254
|
test('AssertOrder(0) accepts no step >= 1', () => {
|
|
256
255
|
const order = new AssertOrder(0)
|
|
257
256
|
|
|
258
|
-
const err = a.throws(() => order.once(1))
|
|
257
|
+
const err = a.throws(() => order.once(1), InvalidOrder)
|
|
259
258
|
|
|
260
259
|
t.strictEqual(err.state.maxStep, 0)
|
|
261
260
|
})
|
|
@@ -265,7 +264,7 @@ test('AssertOrder(1) accepts step 1 but not 2', () => {
|
|
|
265
264
|
|
|
266
265
|
order.once(1)
|
|
267
266
|
|
|
268
|
-
const err = a.throws(() => order.once(2))
|
|
267
|
+
const err = a.throws(() => order.once(2), InvalidOrder)
|
|
269
268
|
|
|
270
269
|
t.strictEqual(err.state.maxStep, 1)
|
|
271
270
|
})
|
|
@@ -286,7 +285,7 @@ test('end() would mark to not accepting more steps if plan is not defined', () =
|
|
|
286
285
|
let order = new AssertOrder()
|
|
287
286
|
order.end()
|
|
288
287
|
|
|
289
|
-
let err = a.throws(() => order.once(1))
|
|
288
|
+
let err = a.throws(() => order.once(1), InvalidOrder)
|
|
290
289
|
|
|
291
290
|
t.strictEqual(err.state.maxStep, 0)
|
|
292
291
|
|
|
@@ -294,7 +293,7 @@ test('end() would mark to not accepting more steps if plan is not defined', () =
|
|
|
294
293
|
order.once(1)
|
|
295
294
|
order.end()
|
|
296
295
|
|
|
297
|
-
err = a.throws(() => order.once(2))
|
|
296
|
+
err = a.throws(() => order.once(2), InvalidOrder)
|
|
298
297
|
|
|
299
298
|
t.strictEqual(err.state.maxStep, 1)
|
|
300
299
|
})
|
|
@@ -310,7 +309,7 @@ test('end() throws if planned step not met', () => {
|
|
|
310
309
|
const order = new AssertOrder(2)
|
|
311
310
|
order.once(1)
|
|
312
311
|
|
|
313
|
-
const err = a.throws(() => order.end())
|
|
312
|
+
const err = a.throws(() => order.end(), InvalidOrder)
|
|
314
313
|
|
|
315
314
|
t.strictEqual(err.state.maxStep, 2)
|
|
316
315
|
})
|
|
@@ -331,7 +330,7 @@ test('end(n) waits n milliseconds and fail when step not met', async () => {
|
|
|
331
330
|
setTimeout(() => {
|
|
332
331
|
order.once(1)
|
|
333
332
|
}, 10)
|
|
334
|
-
const err = await a.throws(order.end(1))
|
|
333
|
+
const err = await a.throws(order.end(1), InvalidOrder)
|
|
335
334
|
|
|
336
335
|
t.strictEqual(err.state.maxStep, 1)
|
|
337
336
|
})
|
|
@@ -421,7 +420,7 @@ test('wait(step, callback) will execute the async callback but not wait for it a
|
|
|
421
420
|
const o2 = new AssertOrder(1)
|
|
422
421
|
|
|
423
422
|
order.wait(1, () => {
|
|
424
|
-
return new Promise(a => {
|
|
423
|
+
return new Promise<void>(a => {
|
|
425
424
|
setImmediate(() => {
|
|
426
425
|
o2.once(1)
|
|
427
426
|
a()
|
|
@@ -434,8 +433,8 @@ test('wait(step, callback) will execute the async callback but not wait for it a
|
|
|
434
433
|
return o2.end(100)
|
|
435
434
|
})
|
|
436
435
|
|
|
437
|
-
async function assertOrderThrows(fn, state: Partial<State>, method, ...args) {
|
|
438
|
-
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)
|
|
439
438
|
t.strictEqual(err.method, method)
|
|
440
439
|
t.deepStrictEqual(err.args, args)
|
|
441
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,18 +73,18 @@ 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
90
|
let firstError: any
|
|
@@ -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 as any)[method]
|
|
148
|
+
throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
}
|
|
@@ -1,10 +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
|
-
constructor(state: State, method: string,
|
|
6
|
-
|
|
7
|
-
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)
|
|
8
7
|
}
|
|
9
8
|
}
|
|
10
9
|
|
|
@@ -20,9 +19,8 @@ function getExpectingCalls(state: State) {
|
|
|
20
19
|
let message: string
|
|
21
20
|
if (state.subStep === 0) {
|
|
22
21
|
const methods = ['is', 'once', 'any']
|
|
23
|
-
message = methods.map(
|
|
24
|
-
`'${m}(${state.step})'`
|
|
25
|
-
`'${m}([${state.step}])'`
|
|
22
|
+
message = methods.map(
|
|
23
|
+
m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`
|
|
26
24
|
).join(', ')
|
|
27
25
|
}
|
|
28
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,6 +13,7 @@ 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
19
|
let timeTracker: { start(): void, taken(): number }
|
|
File without changes
|
|
@@ -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', () => {
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import AssertionError from '
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import { AssertionError } from '../errors'
|
|
2
|
+
import { notEqualMessage } from '../utils'
|
|
3
|
+
import { falsy } from './falsy'
|
|
4
|
+
import { pathEqual } from './pathEqual'
|
|
5
|
+
import { rejects } from './rejects'
|
|
6
|
+
import { repeat } from './repeat'
|
|
7
|
+
import { resolves } from './resolves'
|
|
8
|
+
import { satisfies } from './satisfies'
|
|
9
|
+
import { throws } from './throws'
|
|
10
|
+
import { truthy } from './truthy'
|
|
10
11
|
|
|
11
12
|
export const assertron = {
|
|
12
13
|
false(value: any) {
|
|
13
14
|
if (value !== false)
|
|
14
|
-
throw new AssertionError(
|
|
15
|
-
`Expected value to equal false, but received ${value}`,
|
|
16
|
-
{ value },
|
|
17
|
-
assertron.false)
|
|
15
|
+
throw new AssertionError(notEqualMessage(value, false), { ssf: assertron.false })
|
|
18
16
|
},
|
|
19
17
|
falsy,
|
|
20
18
|
pathEqual,
|
|
@@ -24,7 +22,8 @@ export const assertron = {
|
|
|
24
22
|
satisfies,
|
|
25
23
|
throws,
|
|
26
24
|
true(value: any) {
|
|
27
|
-
if (value !== true)
|
|
25
|
+
if (value !== true)
|
|
26
|
+
throw new AssertionError(notEqualMessage(value, true), { ssf: assertron.true })
|
|
28
27
|
},
|
|
29
28
|
truthy
|
|
30
29
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import a from '..'
|
|
2
|
-
import
|
|
3
|
-
import { assertThrows, noStackTraceFor } from '../testUtils';
|
|
1
|
+
import a, { AssertionError } from '..'
|
|
2
|
+
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
4
3
|
|
|
5
4
|
test('non-false statement throws', () => {
|
|
6
5
|
assertThrows(() => a.falsy(true), AssertionError)
|
package/src/assertron/falsy.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import AssertionError from '
|
|
1
|
+
import { AssertionError } from '../errors'
|
|
2
2
|
|
|
3
3
|
export function falsy(value: any) {
|
|
4
4
|
if (value)
|
|
5
|
-
throw new AssertionError(
|
|
6
|
-
`Expected value to be falsy, but received ${value}`,
|
|
7
|
-
{ value },
|
|
8
|
-
falsy
|
|
9
|
-
)
|
|
5
|
+
throw new AssertionError(`Expected value to be falsy, but received ${value}`, { ssf: falsy })
|
|
10
6
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import AssertionError from '
|
|
2
|
-
import
|
|
3
|
-
import { assertThrows, noStackTraceFor } from '../testUtils';
|
|
1
|
+
import assertron, { AssertionError } from '..'
|
|
2
|
+
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
4
3
|
|
|
5
4
|
test('path with same style passes', () => {
|
|
6
5
|
assertron.pathEqual('a', 'a')
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { notEqualMessage } from '../
|
|
1
|
+
import { pathEqual as isPathEqual } from 'path-equal'
|
|
2
|
+
import { AssertionError } from '../errors'
|
|
3
|
+
import { notEqualMessage } from '../utils'
|
|
4
4
|
|
|
5
5
|
export function pathEqual(actual: string, expected: string) {
|
|
6
6
|
if (!isPathEqual(actual, expected))
|
|
7
|
-
throw new AssertionError(
|
|
8
|
-
notEqualMessage(actual, expected),
|
|
9
|
-
{ actual, expected },
|
|
10
|
-
pathEqual)
|
|
7
|
+
throw new AssertionError(notEqualMessage(actual, expected), { ssf: pathEqual })
|
|
11
8
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import t from 'assert'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { assertAsyncThrows, noStackTraceFor } from '../testUtils';
|
|
1
|
+
import t from 'assert'
|
|
2
|
+
import a from '..'
|
|
3
|
+
import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
|
|
5
4
|
|
|
6
5
|
test('pass on rejected promise', async () => {
|
|
7
6
|
await a.rejects(Promise.reject(1))
|
|
@@ -12,22 +11,22 @@ test('throws on resolved string promise', async () => {
|
|
|
12
11
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with 'abc'`)
|
|
13
12
|
})
|
|
14
13
|
|
|
15
|
-
test('throws on
|
|
14
|
+
test('throws on resolved boolean promise', async () => {
|
|
16
15
|
const err = await a.throws(a.rejects(Promise.resolve(true)))
|
|
17
16
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with true`)
|
|
18
17
|
})
|
|
19
18
|
|
|
20
|
-
test('throws on
|
|
19
|
+
test('throws on resolved object promise', async () => {
|
|
21
20
|
const err = await a.throws(a.rejects(Promise.resolve(2)))
|
|
22
21
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with 2`)
|
|
23
22
|
})
|
|
24
23
|
|
|
25
|
-
test('throws on
|
|
24
|
+
test('throws on resolved object promise', async () => {
|
|
26
25
|
const err = await a.throws(a.rejects(Promise.resolve({ a: 1 })))
|
|
27
26
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with { a: 1 }`)
|
|
28
27
|
})
|
|
29
28
|
|
|
30
29
|
test('does not contain internal stack trace', async () => {
|
|
31
|
-
const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 }))
|
|
30
|
+
const err = await assertAsyncThrows(() => a.rejects(Promise.resolve({ a: 1 })))
|
|
32
31
|
noStackTraceFor('rejects.ts', err)
|
|
33
32
|
})
|
package/src/assertron/rejects.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { AssertionError } from '../errors'
|
|
2
|
+
import { notRejectedMessage } from '../utils'
|
|
3
3
|
|
|
4
4
|
export function rejects(promise: Promise<any>) {
|
|
5
5
|
return promise.then(
|
|
6
|
-
value => {
|
|
7
|
-
throw new AssertionError(
|
|
8
|
-
`Expected promise to reject, but it resolves with ${typeof value === 'string' ?
|
|
9
|
-
`'${value}'` : tersify(value, { maxLength: Infinity })}`,
|
|
10
|
-
{ value },
|
|
11
|
-
rejects)
|
|
12
|
-
},
|
|
6
|
+
value => { throw new AssertionError(notRejectedMessage(value), { ssf: rejects }) },
|
|
13
7
|
() => { }
|
|
14
8
|
)
|
|
15
9
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import a from '..'
|
|
2
|
-
import { FailOnOccurance } from './repeat';
|
|
1
|
+
import a, { FailOnOccurrence } from '..'
|
|
3
2
|
|
|
4
3
|
test('repeat function n times', () => {
|
|
5
4
|
let count = 0
|
|
@@ -26,24 +25,23 @@ test('repeat async function n times sequentially', async () => {
|
|
|
26
25
|
test('error is captured as inner error and indicate which call failed', () => {
|
|
27
26
|
let count = 0
|
|
28
27
|
const err = a.throws(() => a.repeat(() => {
|
|
29
|
-
++count
|
|
30
|
-
|
|
31
|
-
}, 10), FailOnOccurance)
|
|
28
|
+
if (++count === 5) throw new Error('failed')
|
|
29
|
+
}, 10), FailOnOccurrence)
|
|
32
30
|
|
|
33
|
-
expect(err.
|
|
31
|
+
expect(err.occurrence).toBe(5)
|
|
34
32
|
expect(err.error.message).toBe('failed')
|
|
35
33
|
})
|
|
36
34
|
|
|
37
35
|
test('rejected error is captured as inner error and indicate which call failed', async () => {
|
|
38
36
|
let count = 0
|
|
39
|
-
const err = await a.throws(a.repeat(() => new Promise((a, r) => {
|
|
37
|
+
const err = await a.throws(a.repeat(() => new Promise<void>((a, r) => {
|
|
40
38
|
setTimeout(() => {
|
|
41
39
|
++count
|
|
42
40
|
if (count === 5) r(new Error('failed'))
|
|
43
41
|
else a()
|
|
44
42
|
}, Math.random() * 10)
|
|
45
|
-
}), 10),
|
|
43
|
+
}), 10), FailOnOccurrence)
|
|
46
44
|
|
|
47
|
-
expect(err.
|
|
45
|
+
expect(err.occurrence).toBe(5)
|
|
48
46
|
expect(err.error.message).toBe('failed')
|
|
49
47
|
})
|