@augment-vir/assert 30.1.0 → 30.3.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { combineErrorMessages, ensureError, ensureErrorAndPrependMessage, extractErrorMessage, stringify, wait, } from '@augment-vir/core';
|
|
2
|
-
import { convertDuration
|
|
2
|
+
import { convertDuration } from '@date-vir/duration';
|
|
3
3
|
import { AssertionError } from '../augments/assertion.error.js';
|
|
4
4
|
import { parseWaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
5
5
|
import { deepEquals } from './equality/simple-equality.js';
|
|
@@ -130,8 +130,8 @@ export async function waitUntilOutput(functionToCallOrAsserter, inputsOrFunction
|
|
|
130
130
|
const failureMessage = usingCustomAsserter
|
|
131
131
|
? emptyOrFailureMessage
|
|
132
132
|
: emptyOrFailureMessageOrOptions;
|
|
133
|
-
const timeout = convertDuration(options.timeout,
|
|
134
|
-
const interval = convertDuration(options.interval,
|
|
133
|
+
const timeout = convertDuration(options.timeout, { milliseconds: true }).milliseconds;
|
|
134
|
+
const interval = convertDuration(options.interval, { milliseconds: true });
|
|
135
135
|
let lastCallbackOutput = notSetSymbol;
|
|
136
136
|
let lastError = undefined;
|
|
137
137
|
async function checkCondition() {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type MaybePromise } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
|
|
4
|
+
* and the custom checker is only run on primitives. This function automatically handles async
|
|
5
|
+
* custom checkers and circular references.
|
|
6
|
+
*
|
|
7
|
+
* @category Assert
|
|
8
|
+
*/
|
|
9
|
+
export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => boolean): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
|
|
12
|
+
* and the custom checker is only run on primitives. This function automatically handles async
|
|
13
|
+
* custom checkers and circular references.
|
|
14
|
+
*
|
|
15
|
+
* @category Assert
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => Promise<boolean>): Promise<boolean>;
|
|
18
|
+
/**
|
|
19
|
+
* Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
|
|
20
|
+
* and the custom checker is only run on primitives. This function automatically handles async
|
|
21
|
+
* custom checkers and circular references.
|
|
22
|
+
*
|
|
23
|
+
* @category Assert
|
|
24
|
+
*/
|
|
25
|
+
export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => MaybePromise<boolean>): MaybePromise<boolean>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ensureError, getObjectTypedKeys, } from '@augment-vir/core';
|
|
2
|
+
import { check } from './guards/check.js';
|
|
3
|
+
/**
|
|
4
|
+
* Deeply checks inputs for equality with a custom checker callback. All objects are recursed into
|
|
5
|
+
* and the custom checker is only run on primitives. This function automatically handles async
|
|
6
|
+
* custom checkers and circular references.
|
|
7
|
+
*
|
|
8
|
+
* @category Assert
|
|
9
|
+
*/
|
|
10
|
+
export function checkCustomDeepQuality(a, b, customChecker) {
|
|
11
|
+
return recursiveCheckCustomDeepQuality(a, b, customChecker, new Set());
|
|
12
|
+
}
|
|
13
|
+
function recursiveCheckCustomDeepQuality(a, b, customChecker, checkedObjects) {
|
|
14
|
+
a = flattenComplexObject(a);
|
|
15
|
+
b = flattenComplexObject(b);
|
|
16
|
+
if (check.isObject(a) && check.isObject(b)) {
|
|
17
|
+
if (checkedObjects.has(a) || checkedObjects.has(b)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
checkedObjects.add(a);
|
|
21
|
+
checkedObjects.add(b);
|
|
22
|
+
if (!recursiveCheckCustomDeepQuality(getObjectTypedKeys(a).sort(), getObjectTypedKeys(b).sort(), customChecker, checkedObjects)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
let receivedPromise = false;
|
|
26
|
+
const results = getObjectTypedKeys(a).map((key) => {
|
|
27
|
+
const result = recursiveCheckCustomDeepQuality(a[key], b[key], customChecker, checkedObjects);
|
|
28
|
+
if (check.isPromise(result)) {
|
|
29
|
+
receivedPromise = true;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
});
|
|
33
|
+
return handleMaybePromise(receivedPromise, results);
|
|
34
|
+
}
|
|
35
|
+
else if (check.isArray(a) && check.isArray(b)) {
|
|
36
|
+
if (checkedObjects.has(a) || checkedObjects.has(b)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
checkedObjects.add(a);
|
|
40
|
+
checkedObjects.add(b);
|
|
41
|
+
if (a.length !== b.length) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
let receivedPromise = false;
|
|
45
|
+
const results = a.map((entry, index) => {
|
|
46
|
+
const result = recursiveCheckCustomDeepQuality(entry, b[index], customChecker, checkedObjects);
|
|
47
|
+
if (check.isPromise(result)) {
|
|
48
|
+
receivedPromise = true;
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
});
|
|
52
|
+
return handleMaybePromise(receivedPromise, results);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return customChecker(a, b);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function flattenComplexObject(input) {
|
|
59
|
+
if (input instanceof Set) {
|
|
60
|
+
return Array.from(input.entries()).sort();
|
|
61
|
+
}
|
|
62
|
+
else if (input instanceof Map) {
|
|
63
|
+
return Object.fromEntries(input.entries());
|
|
64
|
+
}
|
|
65
|
+
else if (input instanceof RegExp) {
|
|
66
|
+
return input.source;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return input;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function handleMaybePromise(hasPromise, results) {
|
|
73
|
+
if (hasPromise) {
|
|
74
|
+
return new Promise(async (resolve, reject) => {
|
|
75
|
+
try {
|
|
76
|
+
const awaitedResult = await Promise.all(results);
|
|
77
|
+
resolve(awaitedResult.every(check.isTrue));
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
reject(ensureError(error));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return results.every(check.isTrue);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ensureError, ensureErrorAndPrependMessage, wait, } from '@augment-vir/core';
|
|
2
|
-
import { convertDuration
|
|
2
|
+
import { convertDuration } from '@date-vir/duration';
|
|
3
3
|
import { pickOverride } from './guard-override.js';
|
|
4
4
|
export const defaultWaitUntilOptions = {
|
|
5
5
|
interval: {
|
|
@@ -12,8 +12,8 @@ export const defaultWaitUntilOptions = {
|
|
|
12
12
|
const notSetSymbol = Symbol('not set');
|
|
13
13
|
export async function executeWaitUntil(assert, rawArgs, requireSynchronousResult) {
|
|
14
14
|
const { callback, extraAssertionArgs, failureMessage, options } = parseWaitUntilArgs(rawArgs);
|
|
15
|
-
const timeout = convertDuration(options.timeout,
|
|
16
|
-
const interval = convertDuration(options.interval,
|
|
15
|
+
const timeout = convertDuration(options.timeout, { milliseconds: true }).milliseconds;
|
|
16
|
+
const interval = convertDuration(options.interval, { milliseconds: true });
|
|
17
17
|
let lastCallbackOutput = notSetSymbol;
|
|
18
18
|
let lastError = undefined;
|
|
19
19
|
async function checkCondition() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './augments/assertion-exports.js';
|
|
2
2
|
export * from './augments/assertion.error.js';
|
|
3
|
+
export * from './augments/custom-equality.js';
|
|
3
4
|
export * from './augments/guards/assert-wrap.js';
|
|
4
5
|
export * from './augments/guards/assert.js';
|
|
5
6
|
export * from './augments/guards/check-wrap.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './augments/assertion-exports.js';
|
|
2
2
|
export * from './augments/assertion.error.js';
|
|
3
|
+
export * from './augments/custom-equality.js';
|
|
3
4
|
export * from './augments/guards/assert-wrap.js';
|
|
4
5
|
export * from './augments/guards/assert.js';
|
|
5
6
|
export * from './augments/guards/check-wrap.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/assert",
|
|
3
|
-
"version": "30.
|
|
3
|
+
"version": "30.3.0",
|
|
4
4
|
"description": "A collection of assertions for test and production code alike.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"augment",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"test:update": "npm test"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@augment-vir/core": "^30.
|
|
45
|
-
"@date-vir/duration": "^6.0.
|
|
44
|
+
"@augment-vir/core": "^30.3.0",
|
|
45
|
+
"@date-vir/duration": "^6.0.1",
|
|
46
46
|
"deep-eql": "^5.0.2",
|
|
47
47
|
"expect-type": "^0.20.0",
|
|
48
48
|
"type-fest": "^4.26.1"
|