@augment-vir/assert 30.1.0 → 30.2.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,22 @@
|
|
|
1
|
+
import { type MaybePromise } from '@augment-vir/core';
|
|
2
|
+
/**
|
|
3
|
+
* Runs a custom provided checker that is applied deeply to any given variables. Automatically
|
|
4
|
+
* handles async custom checkers.
|
|
5
|
+
*
|
|
6
|
+
* @category Assert
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => boolean): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Runs a custom provided checker that is applied deeply to any given variables. Automatically
|
|
11
|
+
* handles async custom checkers.
|
|
12
|
+
*
|
|
13
|
+
* @category Assert
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => Promise<boolean>): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Runs a custom provided checker that is applied deeply to any given variables. Automatically
|
|
18
|
+
* handles async custom checkers.
|
|
19
|
+
*
|
|
20
|
+
* @category Assert
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkCustomDeepQuality(a: unknown, b: unknown, customChecker: (a: unknown, b: unknown) => MaybePromise<boolean>): MaybePromise<boolean>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ensureError, getObjectTypedKeys, } from '@augment-vir/core';
|
|
2
|
+
import { check } from './guards/check.js';
|
|
3
|
+
/**
|
|
4
|
+
* Runs a custom provided checker that is applied deeply to any given variables. Automatically
|
|
5
|
+
* handles async custom checkers.
|
|
6
|
+
*
|
|
7
|
+
* @category Assert
|
|
8
|
+
*/
|
|
9
|
+
export function checkCustomDeepQuality(a, b, customChecker) {
|
|
10
|
+
a = flattenComplexObject(a);
|
|
11
|
+
b = flattenComplexObject(b);
|
|
12
|
+
if (check.isObject(a) && check.isObject(b)) {
|
|
13
|
+
if (!checkCustomDeepQuality(getObjectTypedKeys(a).sort(), getObjectTypedKeys(b).sort(), customChecker)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
let receivedPromise = false;
|
|
17
|
+
const results = getObjectTypedKeys(a).map((key) => {
|
|
18
|
+
const result = checkCustomDeepQuality(a[key], b[key], customChecker);
|
|
19
|
+
if (check.isPromise(result)) {
|
|
20
|
+
receivedPromise = true;
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
});
|
|
24
|
+
return handleMaybePromise(receivedPromise, results);
|
|
25
|
+
}
|
|
26
|
+
else if (check.isArray(a) && check.isArray(b)) {
|
|
27
|
+
if (a.length !== b.length) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
let receivedPromise = false;
|
|
31
|
+
const results = a.map((entry, index) => {
|
|
32
|
+
const result = checkCustomDeepQuality(entry, b[index], customChecker);
|
|
33
|
+
if (check.isPromise(result)) {
|
|
34
|
+
receivedPromise = true;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
});
|
|
38
|
+
return handleMaybePromise(receivedPromise, results);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return customChecker(a, b);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function flattenComplexObject(input) {
|
|
45
|
+
if (input instanceof Set) {
|
|
46
|
+
return Array.from(input.entries()).sort();
|
|
47
|
+
}
|
|
48
|
+
else if (input instanceof Map) {
|
|
49
|
+
return Object.fromEntries(input.entries());
|
|
50
|
+
}
|
|
51
|
+
else if (input instanceof RegExp) {
|
|
52
|
+
return input.source;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return input;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function handleMaybePromise(hasPromise, results) {
|
|
59
|
+
if (hasPromise) {
|
|
60
|
+
return new Promise(async (resolve, reject) => {
|
|
61
|
+
try {
|
|
62
|
+
const awaitedResult = await Promise.all(results);
|
|
63
|
+
resolve(awaitedResult.every(check.isTrue));
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
reject(ensureError(error));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
return results.every(check.isTrue);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -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.2.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.2.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"
|