assertron 11.1.4 → 11.2.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/cjs/assert-order/AssertOrder.d.ts.map +1 -1
- package/cjs/assert-order/AssertOrder.js +3 -1
- package/cjs/assert-order/AssertOrder.js.map +1 -1
- package/cjs/assert-order/InvalidOrder.d.ts +1 -1
- package/cjs/assert-order/InvalidOrder.d.ts.map +1 -1
- package/cjs/assert-order/InvalidOrder.js +4 -2
- package/cjs/assert-order/InvalidOrder.js.map +1 -1
- package/cjs/assert-order/StateMachine.d.ts +1 -1
- package/cjs/assert-order/StateMachine.d.ts.map +1 -1
- package/cjs/assert-order/StateMachine.js +17 -8
- package/cjs/assert-order/StateMachine.js.map +1 -1
- package/cjs/assert-order/types.d.ts.map +1 -1
- package/cjs/assertron/assertron.d.ts +1 -1
- package/cjs/assertron/assertron.d.ts.map +1 -1
- package/cjs/assertron/assertron.js.map +1 -1
- package/cjs/assertron/falsy.d.ts.map +1 -1
- package/cjs/assertron/falsy.js.map +1 -1
- package/cjs/assertron/isInstanceof.d.ts.map +1 -1
- package/cjs/assertron/isInstanceof.js.map +1 -1
- package/cjs/assertron/pathEqual.js.map +1 -1
- package/cjs/assertron/rejects.d.ts.map +1 -1
- package/cjs/assertron/rejects.js +3 -1
- package/cjs/assertron/rejects.js.map +1 -1
- package/cjs/assertron/repeat.d.ts.map +1 -1
- package/cjs/assertron/repeat.js +3 -1
- package/cjs/assertron/repeat.js.map +1 -1
- package/cjs/assertron/resolves.d.ts.map +1 -1
- package/cjs/assertron/resolves.js +3 -1
- package/cjs/assertron/resolves.js.map +1 -1
- package/cjs/assertron/satisfies.d.ts +1 -1
- package/cjs/assertron/satisfies.d.ts.map +1 -1
- package/cjs/assertron/satisfies.js.map +1 -1
- package/cjs/assertron/throws.d.ts +1 -1
- package/cjs/assertron/throws.d.ts.map +1 -1
- package/cjs/assertron/throws.js +7 -3
- package/cjs/assertron/throws.js.map +1 -1
- package/cjs/assertron/truthy.d.ts.map +1 -1
- package/cjs/assertron/truthy.js.map +1 -1
- package/cjs/errors.d.ts +3 -3
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js.map +1 -1
- package/cjs/index.d.ts +2 -1
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +15 -1
- package/cjs/index.js.map +1 -1
- package/cjs/package.json +1 -1
- package/cjs/types.d.ts.map +1 -1
- package/cjs/utils/index.js.map +1 -1
- package/cjs/utils/isErrorConstructor.d.ts +1 -1
- package/cjs/utils/isErrorConstructor.d.ts.map +1 -1
- package/cjs/utils/isErrorConstructor.js.map +1 -1
- package/cjs/utils/notEqualMessage.js.map +1 -1
- package/cjs/utils/notSatisfiedMessage.d.ts +1 -1
- package/cjs/utils/notSatisfiedMessage.d.ts.map +1 -1
- package/cjs/utils/notSatisfiedMessage.js +8 -3
- package/cjs/utils/notSatisfiedMessage.js.map +1 -1
- package/cjs/utils/notThrownMessage.js.map +1 -1
- package/cjs/utils/promiseMessages.d.ts.map +1 -1
- package/cjs/utils/promiseMessages.js +8 -4
- package/cjs/utils/promiseMessages.js.map +1 -1
- package/cjs/utils/unexpectedErrorMessage.d.ts +1 -1
- package/cjs/utils/unexpectedErrorMessage.d.ts.map +1 -1
- package/cjs/utils/unexpectedErrorMessage.js +1 -2
- package/cjs/utils/unexpectedErrorMessage.js.map +1 -1
- package/esm/assert-order/AssertOrder.d.ts.map +1 -1
- package/esm/assert-order/AssertOrder.js +3 -1
- package/esm/assert-order/AssertOrder.js.map +1 -1
- package/esm/assert-order/InvalidOrder.d.ts +1 -1
- package/esm/assert-order/InvalidOrder.d.ts.map +1 -1
- package/esm/assert-order/InvalidOrder.js +4 -2
- package/esm/assert-order/InvalidOrder.js.map +1 -1
- package/esm/assert-order/StateMachine.d.ts +1 -1
- package/esm/assert-order/StateMachine.d.ts.map +1 -1
- package/esm/assert-order/StateMachine.js +17 -8
- package/esm/assert-order/StateMachine.js.map +1 -1
- package/esm/assert-order/types.d.ts.map +1 -1
- package/esm/assertron/assertron.d.ts +1 -1
- package/esm/assertron/assertron.d.ts.map +1 -1
- package/esm/assertron/assertron.js.map +1 -1
- package/esm/assertron/falsy.d.ts.map +1 -1
- package/esm/assertron/falsy.js.map +1 -1
- package/esm/assertron/isInstanceof.d.ts.map +1 -1
- package/esm/assertron/isInstanceof.js.map +1 -1
- package/esm/assertron/pathEqual.js.map +1 -1
- package/esm/assertron/rejects.d.ts.map +1 -1
- package/esm/assertron/rejects.js +3 -1
- package/esm/assertron/rejects.js.map +1 -1
- package/esm/assertron/repeat.d.ts.map +1 -1
- package/esm/assertron/repeat.js +3 -1
- package/esm/assertron/repeat.js.map +1 -1
- package/esm/assertron/resolves.d.ts.map +1 -1
- package/esm/assertron/resolves.js +3 -1
- package/esm/assertron/resolves.js.map +1 -1
- package/esm/assertron/satisfies.d.ts +1 -1
- package/esm/assertron/satisfies.d.ts.map +1 -1
- package/esm/assertron/satisfies.js.map +1 -1
- package/esm/assertron/throws.d.ts +1 -1
- package/esm/assertron/throws.d.ts.map +1 -1
- package/esm/assertron/throws.js +7 -3
- package/esm/assertron/throws.js.map +1 -1
- package/esm/assertron/truthy.d.ts.map +1 -1
- package/esm/assertron/truthy.js.map +1 -1
- package/esm/errors.d.ts +3 -3
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js.map +1 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/esm/types.d.ts.map +1 -1
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/isErrorConstructor.d.ts +1 -1
- package/esm/utils/isErrorConstructor.d.ts.map +1 -1
- package/esm/utils/isErrorConstructor.js.map +1 -1
- package/esm/utils/notEqualMessage.js.map +1 -1
- package/esm/utils/notSatisfiedMessage.d.ts +1 -1
- package/esm/utils/notSatisfiedMessage.d.ts.map +1 -1
- package/esm/utils/notSatisfiedMessage.js +8 -3
- package/esm/utils/notSatisfiedMessage.js.map +1 -1
- package/esm/utils/notThrownMessage.js.map +1 -1
- package/esm/utils/promiseMessages.d.ts.map +1 -1
- package/esm/utils/promiseMessages.js +8 -4
- package/esm/utils/promiseMessages.js.map +1 -1
- package/esm/utils/unexpectedErrorMessage.d.ts +1 -1
- package/esm/utils/unexpectedErrorMessage.d.ts.map +1 -1
- package/esm/utils/unexpectedErrorMessage.js +1 -2
- package/esm/utils/unexpectedErrorMessage.js.map +1 -1
- package/package.json +3 -3
- package/ts/assert-order/AssertOrder.ts +138 -143
- package/ts/assert-order/InvalidOrder.ts +23 -19
- package/ts/assert-order/StateMachine.ts +96 -89
- package/ts/assert-order/index.ts +0 -1
- package/ts/assert-order/internalInterfaces.ts +3 -3
- package/ts/assert-order/types.ts +5 -5
- package/ts/assertron/assertron.ts +39 -32
- package/ts/assertron/falsy.ts +1 -2
- package/ts/assertron/isInstanceof.ts +6 -3
- package/ts/assertron/pathEqual.ts +2 -2
- package/ts/assertron/rejects.ts +6 -4
- package/ts/assertron/repeat.ts +27 -21
- package/ts/assertron/resolves.ts +6 -4
- package/ts/assertron/satisfies.ts +28 -21
- package/ts/assertron/throws.ts +76 -55
- package/ts/assertron/truthy.ts +1 -4
- package/ts/errors.ts +9 -9
- package/ts/index.ts +17 -1
- package/ts/testUtils.ts +52 -55
- package/ts/types.ts +0 -1
- package/ts/utils/index.ts +1 -1
- package/ts/utils/isErrorConstructor.ts +2 -2
- package/ts/utils/notEqualMessage.ts +1 -1
- package/ts/utils/notSatisfiedMessage.ts +18 -14
- package/ts/utils/notThrownMessage.ts +1 -1
- package/ts/utils/promiseMessages.ts +12 -5
- package/ts/utils/unexpectedErrorMessage.ts +4 -3
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { tersify } from 'tersify';
|
|
2
2
|
export function notSatisfiedMessage(entries) {
|
|
3
|
-
return entries
|
|
3
|
+
return entries
|
|
4
|
+
.map(e => {
|
|
4
5
|
const path = formatPath(e.path);
|
|
5
6
|
return `Expect ${path} to satisfy ${formatValue(e.expected)}, but received ${formatValue(e.actual)}`;
|
|
6
|
-
})
|
|
7
|
+
})
|
|
8
|
+
.join('\n');
|
|
7
9
|
}
|
|
8
10
|
function formatPath(entries) {
|
|
9
11
|
if (entries.length === 0)
|
|
@@ -12,7 +14,10 @@ function formatPath(entries) {
|
|
|
12
14
|
if (isIndice(nodes[0])) {
|
|
13
15
|
nodes.unshift('actual');
|
|
14
16
|
}
|
|
15
|
-
return nodes
|
|
17
|
+
return nodes
|
|
18
|
+
.map(n => (isIndice(n) ? `[${n}]` : '.' + n))
|
|
19
|
+
.join('')
|
|
20
|
+
.slice(1);
|
|
16
21
|
}
|
|
17
22
|
function isIndice(node) {
|
|
18
23
|
return typeof node === 'number';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notSatisfiedMessage.js","sourceRoot":"","sources":["../../ts/utils/notSatisfiedMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,mBAAmB,CAAC,OAAe;
|
|
1
|
+
{"version":3,"file":"notSatisfiedMessage.js","sourceRoot":"","sources":["../../ts/utils/notSatisfiedMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,mBAAmB,CAAC,OAAe;IAClD,OAAO,OAAO;SACZ,GAAG,CAAC,CAAC,CAAC,EAAE;QACR,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;QAC/B,OAAO,UAAU,IAAI,eAAe,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,kBAAkB,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAA;IACrG,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACb,CAAC;AAED,SAAS,UAAU,CAAC,OAA4B;IAC/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAA;IACzC,MAAM,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,CAAA;IAC1B,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QACvB,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;KACvB;IACD,OAAO,KAAK;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;SAC5C,IAAI,CAAC,EAAE,CAAC;SACR,KAAK,CAAC,CAAC,CAAC,CAAA;AACX,CAAC;AAED,SAAS,QAAQ,CAAC,IAAqB;IACtC,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAA;AAChC,CAAC;AAED,SAAS,WAAW,CAAC,KAAU;IAC9B,OAAO,OAAO,CAAC,KAAK,CAAC,CAAA;AACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notThrownMessage.js","sourceRoot":"","sources":["../../ts/utils/notThrownMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,gBAAgB,CAAC,KAAU;
|
|
1
|
+
{"version":3,"file":"notThrownMessage.js","sourceRoot":"","sources":["../../ts/utils/notThrownMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,gBAAgB,CAAC,KAAU;IAC1C,OAAO,8CAA8C,OAAO,CAAC,KAAK,CAAC,YAAY,CAAA;AAChF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promiseMessages.d.ts","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"promiseMessages.d.ts","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,UAK5C;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,GAAG,UAS5C"}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { tersify } from 'tersify';
|
|
2
2
|
export function notRejectedMessage(value) {
|
|
3
|
-
return `Expected promise to reject, but it resolves with ` +
|
|
4
|
-
? `'${value}'` : tersify(value, { maxLength: Infinity }));
|
|
3
|
+
return (`Expected promise to reject, but it resolves with ` +
|
|
4
|
+
(typeof value === 'string' ? `'${value}'` : tersify(value, { maxLength: Infinity })));
|
|
5
5
|
}
|
|
6
6
|
export function notResolvedMessage(error) {
|
|
7
|
-
return `Expected promise to resolve, but it rejects with ` +
|
|
8
|
-
|
|
7
|
+
return (`Expected promise to resolve, but it rejects with ` +
|
|
8
|
+
(typeof error === 'string'
|
|
9
|
+
? `'${error}'`
|
|
10
|
+
: error instanceof Error
|
|
11
|
+
? error
|
|
12
|
+
: tersify(error, { maxLength: Infinity })));
|
|
9
13
|
}
|
|
10
14
|
//# sourceMappingURL=promiseMessages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promiseMessages.js","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,kBAAkB,CAAC,KAAU;
|
|
1
|
+
{"version":3,"file":"promiseMessages.js","sourceRoot":"","sources":["../../ts/utils/promiseMessages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,UAAU,kBAAkB,CAAC,KAAU;IAC5C,OAAO,CACN,mDAAmD;QACnD,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CACpF,CAAA;AACF,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAU;IAC5C,OAAO,CACN,mDAAmD;QACnD,CAAC,OAAO,KAAK,KAAK,QAAQ;YACzB,CAAC,CAAC,IAAI,KAAK,GAAG;YACd,CAAC,CAAC,KAAK,YAAY,KAAK;gBACxB,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAC3C,CAAA;AACF,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ErrorConstructor, ErrorValidator } from '../types.js';
|
|
1
|
+
import type { ErrorConstructor, ErrorValidator } from '../types.js';
|
|
2
2
|
export declare function unexpectedErrorMessage(actual: any, expected: ErrorValidator | ErrorConstructor<any>): string;
|
|
3
3
|
//# sourceMappingURL=unexpectedErrorMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unexpectedErrorMessage.d.ts","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"unexpectedErrorMessage.d.ts","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGnE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAInG"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { tersify } from 'tersify';
|
|
2
2
|
import { isErrorConstructor } from './isErrorConstructor.js';
|
|
3
3
|
export function unexpectedErrorMessage(actual, expected) {
|
|
4
|
-
return `Unexpected error. Expecting '${isErrorConstructor(expected) ?
|
|
5
|
-
expected.name : tersify(expected)}' but received ${tersify(actual)}`;
|
|
4
|
+
return `Unexpected error. Expecting '${isErrorConstructor(expected) ? expected.name : tersify(expected)}' but received ${tersify(actual)}`;
|
|
6
5
|
}
|
|
7
6
|
//# sourceMappingURL=unexpectedErrorMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unexpectedErrorMessage.js","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,MAAM,UAAU,sBAAsB,CAAC,MAAW,EAAE,QAAgD;
|
|
1
|
+
{"version":3,"file":"unexpectedErrorMessage.js","sourceRoot":"","sources":["../../ts/utils/unexpectedErrorMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,MAAM,UAAU,sBAAsB,CAAC,MAAW,EAAE,QAAgD;IACnG,OAAO,gCACN,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAChE,kBAAkB,OAAO,CAAC,MAAM,CAAC,EAAE,CAAA;AACpC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assertron",
|
|
3
|
-
"version": "11.1
|
|
3
|
+
"version": "11.2.1",
|
|
4
4
|
"description": "A supplementary assertion library",
|
|
5
5
|
"homepage": "https://github.com/unional/assertron",
|
|
6
6
|
"bugs": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"path-equal": "^1.2.5",
|
|
61
61
|
"satisfier": "^5.4.2",
|
|
62
62
|
"tersify": "^3.11.1",
|
|
63
|
-
"type-plus": "^6.
|
|
63
|
+
"type-plus": "^6.5.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@commitlint/cli": "^17.0.2",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"npm-run-all": "^4.1.5",
|
|
90
90
|
"pinst": "^3.0.0",
|
|
91
91
|
"rimraf": "^3.0.2",
|
|
92
|
-
"semantic-release": "^
|
|
92
|
+
"semantic-release": "^21.0.1",
|
|
93
93
|
"size-limit": "^8.0.0",
|
|
94
94
|
"ts-jest": "^29.0.0",
|
|
95
95
|
"tslib": "^2.4.0",
|
|
@@ -5,147 +5,142 @@ import { StateMachine } from './StateMachine.js'
|
|
|
5
5
|
// order.atMost(step, count) // exected to be executed at most `count` times
|
|
6
6
|
|
|
7
7
|
export class AssertOrder {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
private assert(method: string, step: number) {
|
|
147
|
-
if (this.state.isNotValid(step)) {
|
|
148
|
-
throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
|
|
149
|
-
}
|
|
150
|
-
}
|
|
8
|
+
/**
|
|
9
|
+
* Gets the current expecting step.
|
|
10
|
+
*/
|
|
11
|
+
get currentStep() {
|
|
12
|
+
return this.state.step
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
private state: StateMachine
|
|
16
|
+
constructor(plan?: number) {
|
|
17
|
+
this.state = new StateMachine(plan)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Asserts the current step is `step`.
|
|
22
|
+
* @param step expected step.
|
|
23
|
+
*/
|
|
24
|
+
is(step: number) {
|
|
25
|
+
this.assert('is', step)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Asserts the current step is not `step`.
|
|
30
|
+
* @param step not expected step.
|
|
31
|
+
*/
|
|
32
|
+
not(step: number) {
|
|
33
|
+
if (this.state.isValid(step)) {
|
|
34
|
+
throw new InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not })
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reset to specified step.
|
|
40
|
+
*/
|
|
41
|
+
jump(step: number) {
|
|
42
|
+
this.state.jump(step)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Move to next step.
|
|
47
|
+
*/
|
|
48
|
+
move() {
|
|
49
|
+
this.state.move()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Asserts the specified step will run once.
|
|
54
|
+
*/
|
|
55
|
+
once(step: number) {
|
|
56
|
+
this.assert('once', step)
|
|
57
|
+
this.state.move()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
on(step: number, assert: (step: number) => void) {
|
|
61
|
+
this.state.on(step, () => {
|
|
62
|
+
assert(step)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
atLeastOnce(step: number) {
|
|
67
|
+
const nextStep = step + 1
|
|
68
|
+
if (this.state.step === step) {
|
|
69
|
+
this.state.move()
|
|
70
|
+
return this.state.moveSubStep()
|
|
71
|
+
} else if (this.state.step === nextStep && this.state.subStep > 0) {
|
|
72
|
+
return this.state.moveSubStep()
|
|
73
|
+
} else throw new InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
any(steps: number[]) {
|
|
77
|
+
const index = steps.indexOf(this.state.step)
|
|
78
|
+
if (index === -1) throw new InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any })
|
|
79
|
+
|
|
80
|
+
this.state.move()
|
|
81
|
+
return steps[index]
|
|
82
|
+
}
|
|
83
|
+
onAny(steps: number[], ...asserts: Array<(...args: any[]) => any>) {
|
|
84
|
+
steps.forEach(step => {
|
|
85
|
+
this.state.on(step, () => {
|
|
86
|
+
let firstError: any
|
|
87
|
+
let hasPass = false
|
|
88
|
+
asserts.forEach(assert => {
|
|
89
|
+
try {
|
|
90
|
+
assert(step)
|
|
91
|
+
hasPass = true
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (!firstError) firstError = err
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
if (!hasPass) throw firstError
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
end(timeout: number): Promise<number>
|
|
102
|
+
end(): number
|
|
103
|
+
end(timeout?: number) {
|
|
104
|
+
if (timeout) {
|
|
105
|
+
return new Promise(r => {
|
|
106
|
+
setTimeout(r, timeout)
|
|
107
|
+
}).then(() => {
|
|
108
|
+
return this.end()
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!this.state.isMaxStepDefined()) {
|
|
113
|
+
this.state.stopAccepting()
|
|
114
|
+
return this.state.getTimeTaken()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (this.state.isAccepting()) {
|
|
118
|
+
throw new InvalidOrder(this.state.get(), 'end', [], { ssf: this.end })
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exactly(step: number, times: number) {
|
|
122
|
+
if (this.state.isNotValid(step))
|
|
123
|
+
throw new InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly })
|
|
124
|
+
|
|
125
|
+
if (this.state.maxSubStep === undefined) {
|
|
126
|
+
this.state.maxSubStep = times
|
|
127
|
+
this.state.minSubStep = times
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return this.state.moveSubStep()
|
|
131
|
+
}
|
|
132
|
+
wait(step: number): Promise<void>
|
|
133
|
+
wait(step: number, callback: () => void): void
|
|
134
|
+
wait(step: number, callback?: () => void) {
|
|
135
|
+
if (callback) this.on(step, callback)
|
|
136
|
+
else
|
|
137
|
+
return new Promise<any>(a => {
|
|
138
|
+
this.on(step, a)
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
private assert(method: string, step: number) {
|
|
142
|
+
if (this.state.isNotValid(step)) {
|
|
143
|
+
throw new InvalidOrder(this.state.get(), method, [step], { ssf: (this as any)[method] })
|
|
144
|
+
}
|
|
145
|
+
}
|
|
151
146
|
}
|
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
import { AssertionError } from '../errors.js'
|
|
2
|
-
import { State } from './types.js'
|
|
2
|
+
import type { State } from './types.js'
|
|
3
3
|
|
|
4
4
|
export class InvalidOrder extends AssertionError {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
constructor(
|
|
6
|
+
public state: State,
|
|
7
|
+
public method: string,
|
|
8
|
+
public args: any[],
|
|
9
|
+
options: AssertionError.Options
|
|
10
|
+
) {
|
|
11
|
+
super(method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args), options)
|
|
12
|
+
}
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
function getEndMessage(state: State) {
|
|
11
|
-
|
|
16
|
+
return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
function getExpectingMessage(state: State, method: string, args: any[]) {
|
|
15
|
-
|
|
20
|
+
return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
function getExpectingCalls(state: State) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return message
|
|
24
|
+
let message: string
|
|
25
|
+
if (state.subStep === 0) {
|
|
26
|
+
const methods = ['is', 'once', 'any']
|
|
27
|
+
message = methods
|
|
28
|
+
.map(m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`)
|
|
29
|
+
.join(', ')
|
|
30
|
+
} else {
|
|
31
|
+
const methods = ['exactly']
|
|
32
|
+
message = methods.map(m => `'${m}(${state.step}, ${state.maxSubStep})'`).join(', ')
|
|
33
|
+
}
|
|
34
|
+
return message
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
function getMethodArgs(args: any[]) {
|
|
34
|
-
|
|
38
|
+
return args.map(a => (Array.isArray(a) ? `[${a.join(', ')}]` : a)).join(', ')
|
|
35
39
|
}
|