@augment-vir/assert 30.0.5 → 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.
@@ -6,6 +6,9 @@ type AssertTypeOf<TestingType> = {
6
6
  notEquals: ExpectTypeOf<TestingType, {
7
7
  positive: false;
8
8
  }>['toEqualTypeOf'];
9
+ slowEquals: ExpectTypeOf<TestingType, {
10
+ positive: true;
11
+ }>['branded']['toEqualTypeOf'];
9
12
  matches: ExpectTypeOf<TestingType, {
10
13
  positive: true;
11
14
  }>['toMatchTypeOf'];
@@ -20,22 +23,6 @@ input: Actual): AssertTypeOf<Actual>;
20
23
  declare function tsType<Actual>(): AssertTypeOf<Actual>;
21
24
  export declare const tsTypeGuards: {
22
25
  assert: {
23
- /**
24
- * Check if a value or type matches type expectations. Use this to write type tests.
25
- *
26
- * This should not be used in production code. It won't cause any issues there, but it also
27
- * provides no value there.
28
- *
29
- * Performs no type guarding.
30
- *
31
- * @example
32
- *
33
- * ```ts
34
- * import {assert} from '@augment-vir/assert';
35
- *
36
- * assert.tsType('hello').equals<string>();
37
- * ```
38
- */
39
26
  /**
40
27
  * Asserts within the TypeScript type system that a given type or value matches type
41
28
  * expectations (using the [`expect-type`](https://www.npmjs.com/package/expect-type) package.
@@ -8,6 +8,7 @@ input) {
8
8
  notEquals: () => { },
9
9
  matches: () => { },
10
10
  notMatches: () => { },
11
+ slowEquals: () => { },
11
12
  };
12
13
  }
13
14
  const assertions = {
@@ -4,7 +4,6 @@ declare function isLengthAtLeast<const Element, const Length extends number>(act
4
4
  declare function isLengthAtLeast(actual: string | AnyObject, length: number, failureMessage?: string | undefined): void;
5
5
  declare function isLengthExactly<const Element, const Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length, failureMessage?: string | undefined): asserts actual is Tuple<Element, Length>;
6
6
  declare function isLengthExactly(actual: string | AnyObject, length: number, failureMessage?: string | undefined): void;
7
- /** These functions are not used at run time, they're only here for types. */
8
7
  declare function checkIsLengthAtLeast<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): actual is AtLeastTuple<Element, Length>;
9
8
  declare function checkIsLengthAtLeast(actual: string | AnyObject, length: number): boolean;
10
9
  declare function assertWrapIsLengthAtLeast<Element, Length extends number>(actual: ReadonlyArray<Element | undefined>, length: Length): AtLeastTuple<Element, Length>;
@@ -1,5 +1,5 @@
1
1
  import { combineErrorMessages, ensureError, ensureErrorAndPrependMessage, extractErrorMessage, stringify, wait, } from '@augment-vir/core';
2
- import { convertDuration, DurationUnit } from '@date-vir/duration';
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, DurationUnit.Milliseconds).milliseconds;
134
- const interval = convertDuration(options.interval, DurationUnit.Milliseconds);
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, DurationUnit } from '@date-vir/duration';
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, DurationUnit.Milliseconds).milliseconds;
16
- const interval = convertDuration(options.interval, DurationUnit.Milliseconds);
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.0.5",
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.0.5",
45
- "@date-vir/duration": "^6.0.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"