assertron 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -23
- package/{dist-es2015 → cjs}/assert-order/AssertOrder.d.ts +3 -2
- package/cjs/assert-order/AssertOrder.d.ts.map +1 -0
- package/cjs/assert-order/AssertOrder.js +148 -0
- package/cjs/assert-order/InvalidOrder.d.ts +10 -0
- package/cjs/assert-order/InvalidOrder.d.ts.map +1 -0
- package/cjs/assert-order/InvalidOrder.js +44 -0
- package/{dist-es5 → cjs}/assert-order/StateMachine.d.ts +4 -5
- package/cjs/assert-order/StateMachine.d.ts.map +1 -0
- package/cjs/assert-order/StateMachine.js +111 -0
- package/{dist-es2015 → cjs}/assert-order/index.d.ts +1 -0
- package/cjs/assert-order/index.d.ts.map +1 -0
- package/cjs/assert-order/index.js +6 -0
- package/{dist-es2015 → cjs}/assert-order/interfaces.d.ts +1 -0
- package/cjs/assert-order/interfaces.d.ts.map +1 -0
- package/cjs/assert-order/interfaces.js +3 -0
- package/{dist-es2015 → cjs}/assertron/assertron.d.ts +1 -0
- package/cjs/assertron/assertron.d.ts.map +1 -0
- package/cjs/assertron/assertron.js +32 -0
- package/{dist-es2015 → cjs}/assertron/falsy.d.ts +1 -0
- package/cjs/assertron/falsy.d.ts.map +1 -0
- package/cjs/assertron/falsy.js +11 -0
- package/cjs/assertron/index.d.ts +2 -0
- package/cjs/assertron/index.d.ts.map +1 -0
- package/cjs/assertron/index.js +5 -0
- package/{dist-es2015 → cjs}/assertron/pathEqual.d.ts +1 -0
- package/cjs/assertron/pathEqual.d.ts.map +1 -0
- package/cjs/assertron/pathEqual.js +13 -0
- package/{dist-es2015 → cjs}/assertron/rejects.d.ts +1 -0
- package/cjs/assertron/rejects.d.ts.map +1 -0
- package/cjs/assertron/rejects.js +14 -0
- package/{dist-es2015 → cjs}/assertron/repeat.d.ts +9 -0
- package/cjs/assertron/repeat.d.ts.map +1 -0
- package/cjs/assertron/repeat.js +44 -0
- package/{dist-es2015 → cjs}/assertron/resolves.d.ts +1 -0
- package/cjs/assertron/resolves.d.ts.map +1 -0
- package/cjs/assertron/resolves.js +17 -0
- package/cjs/assertron/satisfies.d.ts +10 -0
- package/cjs/assertron/satisfies.d.ts.map +1 -0
- package/cjs/assertron/satisfies.js +19 -0
- package/{dist-es2015 → cjs}/assertron/throws.d.ts +2 -0
- package/cjs/assertron/throws.d.ts.map +1 -0
- package/cjs/assertron/throws.js +62 -0
- package/{dist-es2015 → cjs}/assertron/truthy.d.ts +1 -0
- package/cjs/assertron/truthy.d.ts.map +1 -0
- package/cjs/assertron/truthy.js +11 -0
- package/{dist-es2015 → cjs}/errors/NotSatisfied.d.ts +1 -0
- package/cjs/errors/NotSatisfied.d.ts.map +1 -0
- package/cjs/errors/NotSatisfied.js +28 -0
- package/{dist-es5 → cjs}/errors/index.d.ts +1 -0
- package/cjs/errors/index.d.ts.map +1 -0
- package/cjs/errors/index.js +11 -0
- package/{dist-es2015 → cjs}/errors/interfaces.d.ts +1 -0
- package/cjs/errors/interfaces.d.ts.map +1 -0
- package/cjs/errors/interfaces.js +3 -0
- package/{dist-es2015 → cjs}/errors/notEqualMessage.d.ts +1 -0
- package/cjs/errors/notEqualMessage.d.ts.map +1 -0
- package/cjs/errors/notEqualMessage.js +8 -0
- package/{dist-es2015 → cjs}/errors/notRejectedMessage.d.ts +1 -0
- package/cjs/errors/notRejectedMessage.d.ts.map +1 -0
- package/cjs/errors/notRejectedMessage.js +8 -0
- package/{dist-es2015 → cjs}/errors/notThrownMessage.d.ts +1 -0
- package/cjs/errors/notThrownMessage.d.ts.map +1 -0
- package/cjs/errors/notThrownMessage.js +9 -0
- package/{dist-es2015 → cjs}/errors/returnNotRejectedMessage.d.ts +1 -0
- package/cjs/errors/returnNotRejectedMessage.d.ts.map +1 -0
- package/cjs/errors/returnNotRejectedMessage.js +8 -0
- package/{dist-es2015 → cjs}/errors/unexpectedErrorMessage.d.ts +1 -0
- package/cjs/errors/unexpectedErrorMessage.d.ts.map +1 -0
- package/cjs/errors/unexpectedErrorMessage.js +10 -0
- package/{dist-es2015 → cjs}/errors/util.d.ts +1 -0
- package/cjs/errors/util.d.ts.map +1 -0
- package/cjs/errors/util.js +8 -0
- package/{dist-es5 → cjs}/index.d.ts +1 -0
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +8 -0
- package/esm/assert-order/AssertOrder.js +132 -0
- package/esm/assert-order/InvalidOrder.js +31 -0
- package/esm/assert-order/StateMachine.js +103 -0
- package/esm/assert-order/index.js +3 -0
- package/esm/assert-order/interfaces.js +2 -0
- package/esm/assertron/assertron.js +28 -0
- package/esm/assertron/falsy.js +6 -0
- package/esm/assertron/index.js +2 -0
- package/esm/assertron/pathEqual.js +8 -0
- package/esm/assertron/rejects.js +9 -0
- package/esm/assertron/repeat.js +35 -0
- package/esm/assertron/resolves.js +12 -0
- package/esm/assertron/satisfies.js +14 -0
- package/esm/assertron/throws.js +57 -0
- package/esm/assertron/truthy.js +6 -0
- package/esm/errors/NotSatisfied.js +23 -0
- package/esm/errors/index.js +8 -0
- package/esm/errors/interfaces.js +2 -0
- package/esm/errors/notEqualMessage.js +4 -0
- package/esm/errors/notRejectedMessage.js +4 -0
- package/esm/errors/notThrownMessage.js +5 -0
- package/esm/errors/returnNotRejectedMessage.js +4 -0
- package/esm/errors/unexpectedErrorMessage.js +6 -0
- package/esm/errors/util.js +4 -0
- package/esm/index.js +5 -0
- package/package.json +63 -24
- package/src/assert-order/AssertOrder.spec.ts +0 -1
- package/src/assert-order/AssertOrder.ts +3 -3
- package/src/assert-order/InvalidOrder.ts +5 -8
- package/src/assert-order/StateMachine.ts +24 -28
- package/src/assert-order/interfaces.ts +5 -5
- package/src/assert-order/internalInterfaces.ts +3 -3
- package/src/assertron/assertron.spec.ts +3 -4
- package/src/assertron/assertron.ts +9 -9
- package/src/assertron/falsy.spec.ts +2 -2
- package/src/assertron/pathEqual.spec.ts +3 -3
- package/src/assertron/pathEqual.ts +3 -3
- package/src/assertron/rejects.spec.ts +7 -7
- package/src/assertron/rejects.ts +4 -6
- package/src/assertron/repeat.spec.ts +27 -1
- package/src/assertron/repeat.ts +27 -10
- package/src/assertron/resolves.spec.ts +4 -4
- package/src/assertron/resolves.ts +7 -10
- package/src/assertron/satisfies.spec.ts +8 -9
- package/src/assertron/satisfies.ts +15 -5
- package/src/assertron/throws.spec.ts +33 -13
- package/src/assertron/throws.ts +8 -5
- package/src/assertron/truthy.spec.ts +3 -3
- package/src/errors/NotSatisfied.ts +1 -1
- package/src/errors/interfaces.ts +1 -1
- package/src/errors/notThrownMessage.ts +3 -1
- package/src/errors/util.ts +2 -2
- package/src/testUtils.ts +17 -13
- 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.js +0 -2
- package/dist-es2015/assert-order/index.js.map +0 -1
- package/dist-es2015/assert-order/interfaces.js +0 -1
- package/dist-es2015/assert-order/interfaces.js.map +0 -1
- package/dist-es2015/assertron/assertron.js +0 -28
- package/dist-es2015/assertron/assertron.js.map +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.js +0 -8
- package/dist-es2015/assertron/pathEqual.js.map +0 -1
- package/dist-es2015/assertron/rejects.js +0 -10
- package/dist-es2015/assertron/rejects.js.map +0 -1
- package/dist-es2015/assertron/repeat.js +0 -21
- package/dist-es2015/assertron/repeat.js.map +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.js +0 -55
- package/dist-es2015/assertron/throws.js.map +0 -1
- package/dist-es2015/assertron/truthy.js +0 -6
- package/dist-es2015/assertron/truthy.js.map +0 -1
- 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.js +0 -1
- package/dist-es2015/errors/interfaces.js.map +0 -1
- package/dist-es2015/errors/notEqualMessage.js +0 -4
- package/dist-es2015/errors/notEqualMessage.js.map +0 -1
- package/dist-es2015/errors/notRejectedMessage.js +0 -4
- package/dist-es2015/errors/notRejectedMessage.js.map +0 -1
- package/dist-es2015/errors/notThrownMessage.js +0 -4
- package/dist-es2015/errors/notThrownMessage.js.map +0 -1
- package/dist-es2015/errors/returnNotRejectedMessage.js +0 -4
- package/dist-es2015/errors/returnNotRejectedMessage.js.map +0 -1
- package/dist-es2015/errors/unexpectedErrorMessage.js +0 -6
- package/dist-es2015/errors/unexpectedErrorMessage.js.map +0 -1
- 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.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 -5
- package/dist-es5/assertron/repeat.js +0 -27
- 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 -4
- 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.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.js +0 -10
- package/dist-es5/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assertron",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "A supplementary assertion
|
|
3
|
+
"version": "8.0.0",
|
|
4
|
+
"description": "A supplementary assertion cjsrary",
|
|
5
5
|
"homepage": "https://github.com/unional/assertron",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/unional/assertron/issues"
|
|
@@ -15,41 +15,80 @@
|
|
|
15
15
|
"name": "Homa Wong",
|
|
16
16
|
"email": "homawong@gmail.com"
|
|
17
17
|
},
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "cjs/index.js",
|
|
21
|
+
"module": "esm/index.js",
|
|
22
|
+
"jsnext:main": "esm/index.js",
|
|
23
|
+
"browser": {
|
|
24
|
+
"perf_hooks": false
|
|
25
|
+
},
|
|
26
|
+
"typings": "cjs/index.d.ts",
|
|
18
27
|
"files": [
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"dist-es2015",
|
|
28
|
+
"cjs",
|
|
29
|
+
"esm",
|
|
22
30
|
"src"
|
|
23
31
|
],
|
|
24
|
-
"main": "dist-es5/index.js",
|
|
25
|
-
"module": "dist-es2015/index.js",
|
|
26
|
-
"typings": "dist-es5/index.d.ts",
|
|
27
32
|
"scripts": {
|
|
28
|
-
"build": "
|
|
29
|
-
"build
|
|
30
|
-
"build
|
|
31
|
-
"
|
|
33
|
+
"build": "yarn build:esm && yarn build:cjs",
|
|
34
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
35
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
36
|
+
"build:watch": "tsc --watch",
|
|
37
|
+
"clean": "rimraf .nyc_output .ts coverage cjs esm",
|
|
32
38
|
"coverage": "jest --coverage",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
39
|
+
"depcheck": "yarn dependency-check",
|
|
40
|
+
"dependency-check": "dependency-check . --unused --no-dev -i type-plus -i global-store -i @types/node -i standard-log-color && dependency-check . --missing --no-dev",
|
|
41
|
+
"lint": "eslint --ext=js,ts .",
|
|
42
|
+
"nuke": "yarn clean && rimraf node_modules",
|
|
35
43
|
"test": "jest",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
44
|
+
"test:watch": "jest --watch",
|
|
45
|
+
"verify": "yarn lint && yarn build && yarn dependency-check && yarn coverage",
|
|
46
|
+
"watch": "yarn test:watch"
|
|
38
47
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
48
|
+
"husky": {
|
|
49
|
+
"hooks": {
|
|
50
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
51
|
+
}
|
|
41
52
|
},
|
|
42
53
|
"dependencies": {
|
|
43
54
|
"assertion-error": "^1.1.0",
|
|
44
55
|
"is-node": "^1.0.2",
|
|
45
|
-
"is-promise": "^
|
|
56
|
+
"is-promise": "^4.0.0",
|
|
46
57
|
"path-equal": "^1.1.1",
|
|
47
|
-
"satisfier": "^5.
|
|
48
|
-
"tersify": "^3.
|
|
58
|
+
"satisfier": "^5.1.1",
|
|
59
|
+
"tersify": "^3.7.9",
|
|
60
|
+
"tslib": "^2.3.1",
|
|
61
|
+
"type-plus": "^3.13.1"
|
|
49
62
|
},
|
|
50
63
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
64
|
+
"@babel/core": "^7.12.16",
|
|
65
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
|
|
66
|
+
"@babel/plugin-proposal-optional-chaining": "^7.12.16",
|
|
67
|
+
"@babel/preset-env": "^7.12.16",
|
|
68
|
+
"@babel/preset-typescript": "^7.12.16",
|
|
69
|
+
"@commitlint/cli": "^15.0.0",
|
|
70
|
+
"@commitlint/config-conventional": "^15.0.0",
|
|
71
|
+
"@types/jest": "^27.0.3",
|
|
72
|
+
"@types/lodash": "^4.14.149",
|
|
73
|
+
"@types/node": "^16.11.11",
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
75
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
76
|
+
"babel-jest": "^27.4.2",
|
|
77
|
+
"dependency-check": "^4.1.0",
|
|
78
|
+
"eslint": "^8.4.0",
|
|
79
|
+
"eslint-plugin-harmony": "^6.0.0",
|
|
80
|
+
"husky": "^7.0.4",
|
|
81
|
+
"jest": "^27.4.3",
|
|
82
|
+
"jest-junit": "^13.0.0",
|
|
83
|
+
"jest-progress-tracker": "^3.0.1",
|
|
84
|
+
"jest-validate": "^27.4.2",
|
|
85
|
+
"jest-watch-repeat": "^2.0.0",
|
|
86
|
+
"jest-watch-suspend": "^1.1.2",
|
|
87
|
+
"jest-watch-toggle-config": "^2.0.1",
|
|
88
|
+
"jest-watch-typeahead": "^1.0.0",
|
|
89
|
+
"node-supported-releases": "^0.0.0",
|
|
90
|
+
"rimraf": "^3.0.2",
|
|
91
|
+
"typescript": "^4.1.5",
|
|
92
|
+
"update-notifier": "^5.1.0"
|
|
54
93
|
}
|
|
55
94
|
}
|
|
@@ -84,10 +84,10 @@ export class AssertOrder {
|
|
|
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 {
|
|
@@ -145,7 +145,7 @@ export class AssertOrder {
|
|
|
145
145
|
}
|
|
146
146
|
private assert(method: string, step: number) {
|
|
147
147
|
if (this.state.isNotValid(step)) {
|
|
148
|
-
throw new InvalidOrder(this.state.get(), method, this[method], step)
|
|
148
|
+
throw new InvalidOrder(this.state.get(), method, (this as any)[method], step)
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import AssertionError from 'assertion-error'
|
|
2
|
-
import { State } from './interfaces'
|
|
1
|
+
import AssertionError from 'assertion-error'
|
|
2
|
+
import { State } from './interfaces'
|
|
3
3
|
|
|
4
|
-
export class InvalidOrder extends AssertionError {
|
|
5
|
-
method: string
|
|
6
|
-
args: any[]
|
|
7
|
-
state: State
|
|
8
|
-
constructor(state: State, method: string, ssf: Function, ...args: any[]) {
|
|
4
|
+
export class InvalidOrder extends AssertionError<{ method: string, state: State, args: any[] }> {
|
|
5
|
+
constructor(state: State, method: string, ssf: (...args: any[]) => any, ...args: any[]) {
|
|
9
6
|
const message = method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args)
|
|
10
7
|
super(message, { method, state, args }, ssf)
|
|
11
8
|
}
|
|
@@ -15,7 +12,7 @@ function getEndMessage(state: State) {
|
|
|
15
12
|
return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
function getExpectingMessage(state, method, args) {
|
|
15
|
+
function getExpectingMessage(state: State, method: string, args: any[]) {
|
|
19
16
|
return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
|
|
20
17
|
}
|
|
21
18
|
|
|
@@ -3,7 +3,7 @@ import { State } from './interfaces'
|
|
|
3
3
|
|
|
4
4
|
// istanbul ignore next
|
|
5
5
|
function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
|
|
6
|
-
// without this,
|
|
6
|
+
// without this, systemJS will complain `process is not defined`
|
|
7
7
|
if (!global.process)
|
|
8
8
|
return false
|
|
9
9
|
const versionString = process.version.startsWith('v') ? process.version.slice(1) : process.version
|
|
@@ -14,48 +14,47 @@ function nodeVersionIsOrAbove(major: number, minor = 0, patch = 0) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// istanbul ignore next
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
18
|
const performance = isNode && nodeVersionIsOrAbove(8, 5) ? require('perf_hooks').performance : undefined
|
|
18
19
|
|
|
19
|
-
let
|
|
20
|
-
let timeTaken
|
|
20
|
+
let timeTracker: { start(): void, taken(): number }
|
|
21
21
|
// istanbul ignore else
|
|
22
|
-
// tslint:disable-next-line
|
|
23
22
|
if (process && typeof process.hrtime === 'function') {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
let tick: [number, number]
|
|
24
|
+
timeTracker = {
|
|
25
|
+
start() { tick = process.hrtime() },
|
|
26
|
+
taken() {
|
|
27
|
+
const [second, nanoSecond] = process.hrtime(tick)
|
|
28
|
+
return second * 1000 + nanoSecond / 1e6
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
// tslint:disable-next-line
|
|
31
32
|
else if (performance && typeof performance.now === 'function') {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
33
|
+
let tick: number
|
|
34
|
+
timeTracker = {
|
|
35
|
+
start() { tick = performance.now() },
|
|
36
|
+
taken() { return performance.now() - tick }
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
else {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return new Date().valueOf() - startTick
|
|
40
|
+
let tick: number
|
|
41
|
+
timeTracker = {
|
|
42
|
+
start() { tick = new Date().valueOf() },
|
|
43
|
+
taken() { return new Date().valueOf() - tick }
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export class StateMachine {
|
|
48
|
-
listeners = {}
|
|
49
|
-
step
|
|
48
|
+
listeners: Record<number, Array<() => void>> = {}
|
|
49
|
+
step = 1
|
|
50
50
|
maxStep?: number
|
|
51
51
|
|
|
52
|
-
subStep
|
|
52
|
+
subStep = 0
|
|
53
53
|
minSubStep?: number
|
|
54
54
|
maxSubStep?: number
|
|
55
|
-
private startTick: [number, number] | number
|
|
56
55
|
constructor(maxStep?: number) {
|
|
57
56
|
this.maxStep = maxStep
|
|
58
|
-
|
|
57
|
+
timeTracker.start()
|
|
59
58
|
}
|
|
60
59
|
jump(step: number) {
|
|
61
60
|
this.step = step
|
|
@@ -87,7 +86,7 @@ export class StateMachine {
|
|
|
87
86
|
maxSubStep
|
|
88
87
|
}
|
|
89
88
|
}
|
|
90
|
-
on(step: number, listener) {
|
|
89
|
+
on(step: number, listener: () => void) {
|
|
91
90
|
this.listeners[step] = [listener]
|
|
92
91
|
}
|
|
93
92
|
isNotValid(step: number) {
|
|
@@ -107,9 +106,6 @@ export class StateMachine {
|
|
|
107
106
|
return this.maxStep ? this.maxStep >= this.step : true
|
|
108
107
|
}
|
|
109
108
|
getTimeTaken() {
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
private getStartTick() {
|
|
113
|
-
return startTick()
|
|
109
|
+
return timeTracker.taken()
|
|
114
110
|
}
|
|
115
111
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AssertionError from 'assertion-error'
|
|
2
|
-
import a from '..'
|
|
3
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
1
|
+
import AssertionError from 'assertion-error'
|
|
2
|
+
import a from '..'
|
|
3
|
+
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
4
4
|
|
|
5
5
|
describe('false()', () => {
|
|
6
6
|
test('non-false statement throws', () => {
|
|
@@ -21,7 +21,6 @@ describe('false()', () => {
|
|
|
21
21
|
})
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
|
|
25
24
|
describe('true()', () => {
|
|
26
25
|
test('non-true statement throws', () => {
|
|
27
26
|
assertThrows(() => a.true(false), AssertionError)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import AssertionError from 'assertion-error'
|
|
2
|
-
import { falsy } from './falsy'
|
|
3
|
-
import { pathEqual } from './pathEqual'
|
|
4
|
-
import { rejects } from './rejects'
|
|
5
|
-
import { repeat } from './repeat'
|
|
6
|
-
import { resolves } from './resolves'
|
|
7
|
-
import { satisfies } from './satisfies'
|
|
8
|
-
import { throws } from './throws'
|
|
9
|
-
import { truthy } from './truthy'
|
|
1
|
+
import AssertionError from 'assertion-error'
|
|
2
|
+
import { falsy } from './falsy'
|
|
3
|
+
import { pathEqual } from './pathEqual'
|
|
4
|
+
import { rejects } from './rejects'
|
|
5
|
+
import { repeat } from './repeat'
|
|
6
|
+
import { resolves } from './resolves'
|
|
7
|
+
import { satisfies } from './satisfies'
|
|
8
|
+
import { throws } from './throws'
|
|
9
|
+
import { truthy } from './truthy'
|
|
10
10
|
|
|
11
11
|
export const assertron = {
|
|
12
12
|
false(value: any) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import a from '..'
|
|
1
|
+
import a from '..'
|
|
2
2
|
import AssertionError from 'assertion-error'
|
|
3
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
3
|
+
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
4
4
|
|
|
5
5
|
test('non-false statement throws', () => {
|
|
6
6
|
assertThrows(() => a.falsy(true), AssertionError)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AssertionError from 'assertion-error'
|
|
2
|
-
import assertron from '..'
|
|
3
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
1
|
+
import AssertionError from 'assertion-error'
|
|
2
|
+
import assertron from '..'
|
|
3
|
+
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
4
4
|
|
|
5
5
|
test('path with same style passes', () => {
|
|
6
6
|
assertron.pathEqual('a', 'a')
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import AssertionError from 'assertion-error'
|
|
2
|
-
import { pathEqual as isPathEqual } from 'path-equal'
|
|
3
|
-
import { notEqualMessage } from '../errors'
|
|
1
|
+
import AssertionError from 'assertion-error'
|
|
2
|
+
import { pathEqual as isPathEqual } from 'path-equal'
|
|
3
|
+
import { notEqualMessage } from '../errors'
|
|
4
4
|
|
|
5
5
|
export function pathEqual(actual: string, expected: string) {
|
|
6
6
|
if (!isPathEqual(actual, expected))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import t from 'assert'
|
|
2
|
-
import AssertionError from 'assertion-error'
|
|
3
|
-
import a from '..'
|
|
4
|
-
import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
|
|
1
|
+
import t from 'assert'
|
|
2
|
+
import AssertionError from 'assertion-error'
|
|
3
|
+
import a from '..'
|
|
4
|
+
import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
|
|
5
5
|
|
|
6
6
|
test('pass on rejected promise', async () => {
|
|
7
7
|
await a.rejects(Promise.reject(1))
|
|
@@ -12,17 +12,17 @@ test('throws on resolved string promise', async () => {
|
|
|
12
12
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with 'abc'`)
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
test('throws on
|
|
15
|
+
test('throws on resolved boolean promise', async () => {
|
|
16
16
|
const err = await a.throws(a.rejects(Promise.resolve(true)))
|
|
17
17
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with true`)
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
-
test('throws on
|
|
20
|
+
test('throws on resolved object promise', async () => {
|
|
21
21
|
const err = await a.throws(a.rejects(Promise.resolve(2)))
|
|
22
22
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with 2`)
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
test('throws on
|
|
25
|
+
test('throws on resolved object promise', async () => {
|
|
26
26
|
const err = await a.throws(a.rejects(Promise.resolve({ a: 1 })))
|
|
27
27
|
t.strictEqual(err.message, `Expected promise to reject, but it resolves with { a: 1 }`)
|
|
28
28
|
})
|
package/src/assertron/rejects.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { tersify } from 'tersify'
|
|
2
|
-
import AssertionError from 'assertion-error'
|
|
1
|
+
import { tersify } from 'tersify'
|
|
2
|
+
import AssertionError from 'assertion-error'
|
|
3
3
|
|
|
4
4
|
export function rejects(promise: Promise<any>) {
|
|
5
5
|
return promise.then(
|
|
6
6
|
value => {
|
|
7
7
|
throw new AssertionError(
|
|
8
|
-
`Expected promise to reject, but it resolves with ${
|
|
9
|
-
|
|
10
|
-
`'${value}'` :
|
|
11
|
-
tersify(value, { maxLength: Infinity })}`,
|
|
8
|
+
`Expected promise to reject, but it resolves with ${typeof value === 'string' ?
|
|
9
|
+
`'${value}'` : tersify(value, { maxLength: Infinity })}`,
|
|
12
10
|
{ value },
|
|
13
11
|
rejects)
|
|
14
12
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import a from '..'
|
|
2
|
+
import { FailOnOccurrence } from './repeat'
|
|
2
3
|
|
|
3
4
|
test('repeat function n times', () => {
|
|
4
5
|
let count = 0
|
|
@@ -10,7 +11,7 @@ test('repeat function n times', () => {
|
|
|
10
11
|
test('repeat async function n times sequentially', async () => {
|
|
11
12
|
let count = 0
|
|
12
13
|
let actual = ''
|
|
13
|
-
|
|
14
|
+
const aa = await a.repeat(() => new Promise<string>(a => {
|
|
14
15
|
setTimeout(() => {
|
|
15
16
|
++count
|
|
16
17
|
actual += String(count)
|
|
@@ -21,3 +22,28 @@ test('repeat async function n times sequentially', async () => {
|
|
|
21
22
|
expect(actual).toBe('12345678910')
|
|
22
23
|
expect(actual).toBe(aa)
|
|
23
24
|
})
|
|
25
|
+
|
|
26
|
+
test('error is captured as inner error and indicate which call failed', () => {
|
|
27
|
+
let count = 0
|
|
28
|
+
const err = a.throws(() => a.repeat(() => {
|
|
29
|
+
++count
|
|
30
|
+
if (count === 5) throw new Error('failed')
|
|
31
|
+
}, 10), FailOnOccurrence)
|
|
32
|
+
|
|
33
|
+
expect(err.occurrence).toBe(5)
|
|
34
|
+
expect(err.error.message).toBe('failed')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('rejected error is captured as inner error and indicate which call failed', async () => {
|
|
38
|
+
let count = 0
|
|
39
|
+
const err = await a.throws(a.repeat(() => new Promise<void>((a, r) => {
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
++count
|
|
42
|
+
if (count === 5) r(new Error('failed'))
|
|
43
|
+
else a()
|
|
44
|
+
}, Math.random() * 10)
|
|
45
|
+
}), 10), FailOnOccurrence)
|
|
46
|
+
|
|
47
|
+
expect(err.occurrence).toBe(5)
|
|
48
|
+
expect(err.error.message).toBe('failed')
|
|
49
|
+
})
|
package/src/assertron/repeat.ts
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
import isPromise from 'is-promise';
|
|
2
|
+
import AssertionError from 'assertion-error'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Repeat the specified function n times and return the last result.
|
|
5
6
|
* If the result is a promise, it will run the function sequentially.
|
|
6
7
|
*/
|
|
7
8
|
export function repeat<R>(fn: () => R | (() => Promise<R>), times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
return repeatRecur(fn, 1, times)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function repeatRecur<R>(fn: () => R | (() => Promise<R>), i: number, times: number): ReturnType<typeof fn> extends Promise<R> ? Promise<R> : R {
|
|
13
|
+
try {
|
|
14
|
+
const result = fn()
|
|
15
|
+
if (i === times) return result as any
|
|
16
|
+
|
|
17
|
+
if (isPromise(result)) {
|
|
18
|
+
return result.then(
|
|
19
|
+
() => repeatRecur(fn, i + 1, times),
|
|
20
|
+
(e) => { throw new FailOnOccurrence(i, e) }
|
|
21
|
+
) as any
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return repeatRecur(fn, i + 1, times)
|
|
17
25
|
}
|
|
18
|
-
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
if (e instanceof FailOnOccurrence) throw e
|
|
29
|
+
throw new FailOnOccurrence(i, e)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class FailOnOccurrence extends AssertionError<{ occurrence: number }> {
|
|
34
|
+
constructor(public occurrence: number, public error: any) {
|
|
35
|
+
super(`Failed on ${occurrence} occurrence`)
|
|
19
36
|
}
|
|
20
37
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import t from 'assert'
|
|
2
|
-
import a from '..'
|
|
3
|
-
import AssertionError from 'assertion-error'
|
|
4
|
-
import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
|
|
1
|
+
import t from 'assert'
|
|
2
|
+
import a from '..'
|
|
3
|
+
import AssertionError from 'assertion-error'
|
|
4
|
+
import { assertAsyncThrows, noStackTraceFor } from '../testUtils'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
test('pass on resolved promise', async () => {
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { tersify } from 'tersify'
|
|
2
|
-
import AssertionError from 'assertion-error'
|
|
1
|
+
import { tersify } from 'tersify'
|
|
2
|
+
import AssertionError from 'assertion-error'
|
|
3
3
|
|
|
4
4
|
export function resolves(promise: Promise<any>) {
|
|
5
5
|
return promise.then(
|
|
6
6
|
() => { },
|
|
7
7
|
error => {
|
|
8
|
-
throw new AssertionError(`Expected promise to resolve, but it rejects with ${
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
error
|
|
12
|
-
|
|
13
|
-
tersify(error, { maxLength: Infinity })}`,
|
|
14
|
-
{ error },
|
|
15
|
-
resolves
|
|
8
|
+
throw new AssertionError(`Expected promise to resolve, but it rejects with ${typeof error === 'string' ?
|
|
9
|
+
`'${error}'` :
|
|
10
|
+
error instanceof Error ?
|
|
11
|
+
error :
|
|
12
|
+
tersify(error, { maxLength: Infinity })}`, { error }, resolves
|
|
16
13
|
)
|
|
17
14
|
}
|
|
18
15
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import AssertionError from 'assertion-error'
|
|
2
|
-
import { every } from 'satisfier'
|
|
3
|
-
import a from '..'
|
|
4
|
-
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
1
|
+
import AssertionError from 'assertion-error'
|
|
2
|
+
import { every } from 'satisfier'
|
|
3
|
+
import a from '..'
|
|
4
|
+
import { assertThrows, noStackTraceFor } from '../testUtils'
|
|
5
5
|
|
|
6
6
|
test('primitive types will pass', () => {
|
|
7
7
|
a.satisfies(1, 1)
|
|
@@ -74,12 +74,11 @@ test('function will use as predicate', () => {
|
|
|
74
74
|
})
|
|
75
75
|
|
|
76
76
|
test('predicate error should mention path', () => {
|
|
77
|
-
a.throws(() => a.satisfies({ a: 1 }, { a: () => false }), e => e.message === `Expect a to satisfy
|
|
77
|
+
a.throws(() => a.satisfies({ a: 1 }, { a: () => false }), e => e.message === `Expect a to satisfy () => false, but received 1`)
|
|
78
78
|
})
|
|
79
79
|
|
|
80
80
|
test('deep predicate error should mention path', () => {
|
|
81
|
-
|
|
82
|
-
a.throws(() => a.satisfies({ a: { b: 1 } }, { a: { b: b => b === 2 } }), e => e.message === `Expect a.b to satisfy fn(b) { return b === 2 }, but received 1`)
|
|
81
|
+
a.throws(() => a.satisfies({ a: { b: 1 } }, { a: { b: b => b === 2 } }), e => e.message === `Expect a.b to satisfy b => b === 2, but received 1`)
|
|
83
82
|
})
|
|
84
83
|
|
|
85
84
|
test('can check parent property', () => {
|
|
@@ -94,7 +93,7 @@ test('can check parent property', () => {
|
|
|
94
93
|
})
|
|
95
94
|
|
|
96
95
|
test('actual of type any should not have type checking error', () => {
|
|
97
|
-
|
|
96
|
+
const actual: any = { a: 1 }
|
|
98
97
|
a.satisfies(actual, { a: 1 })
|
|
99
98
|
})
|
|
100
99
|
|
|
@@ -102,7 +101,7 @@ test('Work with null in array', () => {
|
|
|
102
101
|
interface Foo {
|
|
103
102
|
payload: any;
|
|
104
103
|
}
|
|
105
|
-
|
|
104
|
+
const action: Foo = { payload: [null, 3, 4] }
|
|
106
105
|
a.satisfies(action, { payload: [null, 3, 4] })
|
|
107
106
|
})
|
|
108
107
|
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import AssertionError from 'assertion-error'
|
|
2
|
-
import { createSatisfier } from 'satisfier'
|
|
3
|
-
import {
|
|
1
|
+
import AssertionError from 'assertion-error'
|
|
2
|
+
import { createSatisfier } from 'satisfier'
|
|
3
|
+
import { And, If, PrimitiveTypes, IsExtend } from 'type-plus'
|
|
4
|
+
import { notSatisfiedMessage } from '../errors'
|
|
5
|
+
|
|
6
|
+
export type SatisfyExpectation<T> = If<
|
|
7
|
+
And<IsExtend<T, PrimitiveTypes>, IsExtend<T, Array<any>>>,
|
|
8
|
+
T | ((v: T) => boolean),
|
|
9
|
+
{
|
|
10
|
+
[P in keyof T]?: T[P] extends string
|
|
11
|
+
? SatisfyExpectation<T[P]> | ((v: T[P]) => boolean) | RegExp
|
|
12
|
+
: SatisfyExpectation<T[P]> | ((v: T[P]) => boolean)
|
|
13
|
+
}>
|
|
4
14
|
|
|
5
15
|
/**
|
|
6
16
|
* Check if `actual` satisfies criteria in `expected`.
|
|
7
17
|
* @param expected All properties can be a value which will be compared to the same property in `actual`, RegExp, or a predicate function that will be used to check against the property.
|
|
8
18
|
*/
|
|
9
|
-
export function satisfies<Actual
|
|
10
|
-
const diff = createSatisfier(expected).exec(actual);
|
|
19
|
+
export function satisfies<Actual>(actual: Actual, expected: SatisfyExpectation<Actual>) {
|
|
20
|
+
const diff = createSatisfier(expected as any).exec(actual);
|
|
11
21
|
if (diff) {
|
|
12
22
|
throw new AssertionError(
|
|
13
23
|
notSatisfiedMessage(diff),
|