@augment-vir/assert 30.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/LICENSE-CC0 +121 -0
- package/LICENSE-MIT +21 -0
- package/dist/assertions/boolean.d.ts +97 -0
- package/dist/assertions/boolean.js +47 -0
- package/dist/assertions/boundary.d.ts +83 -0
- package/dist/assertions/boundary.js +104 -0
- package/dist/assertions/enum.d.ts +38 -0
- package/dist/assertions/enum.js +42 -0
- package/dist/assertions/equality/entry-equality.d.ts +40 -0
- package/dist/assertions/equality/entry-equality.js +56 -0
- package/dist/assertions/equality/json-equality.d.ts +42 -0
- package/dist/assertions/equality/json-equality.js +75 -0
- package/dist/assertions/equality/simple-equality.d.ts +85 -0
- package/dist/assertions/equality/simple-equality.js +61 -0
- package/dist/assertions/equality/ts-type-equality.d.ts +42 -0
- package/dist/assertions/equality/ts-type-equality.js +18 -0
- package/dist/assertions/extendable-assertions.d.ts +762 -0
- package/dist/assertions/extendable-assertions.js +108 -0
- package/dist/assertions/http.d.ts +36 -0
- package/dist/assertions/http.js +41 -0
- package/dist/assertions/instance.d.ts +43 -0
- package/dist/assertions/instance.js +41 -0
- package/dist/assertions/keys.d.ts +90 -0
- package/dist/assertions/keys.js +111 -0
- package/dist/assertions/length.d.ts +56 -0
- package/dist/assertions/length.js +68 -0
- package/dist/assertions/nullish.d.ts +43 -0
- package/dist/assertions/nullish.js +42 -0
- package/dist/assertions/numeric.d.ts +69 -0
- package/dist/assertions/numeric.js +60 -0
- package/dist/assertions/output.d.ts +83 -0
- package/dist/assertions/output.example.d.ts +1 -0
- package/dist/assertions/output.example.js +13 -0
- package/dist/assertions/output.js +173 -0
- package/dist/assertions/primitive.d.ts +58 -0
- package/dist/assertions/primitive.js +62 -0
- package/dist/assertions/promise.d.ts +65 -0
- package/dist/assertions/promise.js +69 -0
- package/dist/assertions/regexp.d.ts +19 -0
- package/dist/assertions/regexp.js +18 -0
- package/dist/assertions/runtime-type.d.ts +274 -0
- package/dist/assertions/runtime-type.example.d.ts +1 -0
- package/dist/assertions/runtime-type.example.js +3 -0
- package/dist/assertions/runtime-type.js +242 -0
- package/dist/assertions/throws.d.ts +109 -0
- package/dist/assertions/throws.example.d.ts +1 -0
- package/dist/assertions/throws.example.js +11 -0
- package/dist/assertions/throws.js +166 -0
- package/dist/assertions/uuid.d.ts +35 -0
- package/dist/assertions/uuid.js +33 -0
- package/dist/assertions/values.d.ts +106 -0
- package/dist/assertions/values.js +113 -0
- package/dist/augments/assertion-exports.d.ts +5 -0
- package/dist/augments/assertion-exports.js +1 -0
- package/dist/augments/assertion.error.d.ts +23 -0
- package/dist/augments/assertion.error.example.d.ts +1 -0
- package/dist/augments/assertion.error.example.js +3 -0
- package/dist/augments/assertion.error.js +26 -0
- package/dist/augments/guards/assert-wrap.d.ts +244 -0
- package/dist/augments/guards/assert-wrap.example.d.ts +1 -0
- package/dist/augments/guards/assert-wrap.example.js +9 -0
- package/dist/augments/guards/assert-wrap.js +32 -0
- package/dist/augments/guards/assert.d.ts +177 -0
- package/dist/augments/guards/assert.example.d.ts +1 -0
- package/dist/augments/guards/assert.example.js +4 -0
- package/dist/augments/guards/assert.js +32 -0
- package/dist/augments/guards/check-wrap.d.ts +247 -0
- package/dist/augments/guards/check-wrap.example.d.ts +1 -0
- package/dist/augments/guards/check-wrap.example.js +9 -0
- package/dist/augments/guards/check-wrap.js +34 -0
- package/dist/augments/guards/check.d.ts +229 -0
- package/dist/augments/guards/check.example.d.ts +1 -0
- package/dist/augments/guards/check.example.js +5 -0
- package/dist/augments/guards/check.js +21 -0
- package/dist/augments/guards/wait-until.d.ts +262 -0
- package/dist/augments/guards/wait-until.example.d.ts +1 -0
- package/dist/augments/guards/wait-until.example.js +13 -0
- package/dist/augments/guards/wait-until.js +34 -0
- package/dist/augments/if-equals.d.ts +17 -0
- package/dist/augments/if-equals.js +1 -0
- package/dist/guard-types/assert-function.d.ts +2 -0
- package/dist/guard-types/assert-function.js +3 -0
- package/dist/guard-types/assert-wrap-function.d.ts +9 -0
- package/dist/guard-types/assert-wrap-function.js +14 -0
- package/dist/guard-types/check-function.d.ts +11 -0
- package/dist/guard-types/check-function.js +22 -0
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +9 -0
- package/dist/guard-types/check-wrap-wrapper-function.js +19 -0
- package/dist/guard-types/guard-group.d.ts +13 -0
- package/dist/guard-types/guard-group.js +3 -0
- package/dist/guard-types/guard-override.d.ts +4 -0
- package/dist/guard-types/guard-override.js +10 -0
- package/dist/guard-types/wait-until-function.d.ts +63 -0
- package/dist/guard-types/wait-until-function.js +95 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/test-timeout.mock.d.ts +3 -0
- package/dist/test-timeout.mock.js +8 -0
- package/package.json +54 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ensureError, ensureErrorAndPrependMessage, wait, } from '@augment-vir/core';
|
|
2
|
+
import { convertDuration, DurationUnit } from '@date-vir/duration';
|
|
3
|
+
import { pickOverride } from './guard-override.js';
|
|
4
|
+
export const defaultWaitUntilOptions = {
|
|
5
|
+
interval: {
|
|
6
|
+
milliseconds: 100,
|
|
7
|
+
},
|
|
8
|
+
timeout: {
|
|
9
|
+
seconds: 10,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
const notSetSymbol = Symbol('not set');
|
|
13
|
+
async function executeWaitUntil(assert, rawArgs, requireSynchronousResult) {
|
|
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);
|
|
17
|
+
let lastCallbackOutput = notSetSymbol;
|
|
18
|
+
let lastError = undefined;
|
|
19
|
+
async function checkCondition() {
|
|
20
|
+
try {
|
|
21
|
+
lastCallbackOutput = requireSynchronousResult ? callback() : await callback();
|
|
22
|
+
assert(lastCallbackOutput, ...extraAssertionArgs);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
lastCallbackOutput = notSetSymbol;
|
|
26
|
+
lastError = ensureError(error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const startTime = Date.now();
|
|
30
|
+
while (lastCallbackOutput === notSetSymbol) {
|
|
31
|
+
await checkCondition();
|
|
32
|
+
await wait(interval);
|
|
33
|
+
if (Date.now() - startTime >= timeout) {
|
|
34
|
+
const message = failureMessage ? `${failureMessage}: ` : '';
|
|
35
|
+
const preMessage = `${message}Timeout of '${timeout}' milliseconds exceeded waiting for callback value to match expectations`;
|
|
36
|
+
throw ensureErrorAndPrependMessage(lastError, preMessage);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return lastCallbackOutput;
|
|
40
|
+
}
|
|
41
|
+
export function createWaitUntilGroup(asserts, waitUntilOverrides) {
|
|
42
|
+
const waitUntilGroup = Object.entries(asserts).reduce((accum, [name, assert,]) => {
|
|
43
|
+
accum[name] = pickOverride(waitUntilOverrides, name, () => createWaitUntil(assert));
|
|
44
|
+
return accum;
|
|
45
|
+
}, {});
|
|
46
|
+
return waitUntilGroup;
|
|
47
|
+
}
|
|
48
|
+
export function createWaitUntil(assert, requireSynchronousResult = false) {
|
|
49
|
+
return ((...rawArgs) => {
|
|
50
|
+
return executeWaitUntil(assert, rawArgs, requireSynchronousResult);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function parseWaitUntilArgs(rawArgs) {
|
|
54
|
+
const args = {
|
|
55
|
+
extraAssertionArgs: [],
|
|
56
|
+
options: undefined,
|
|
57
|
+
failureMessage: undefined,
|
|
58
|
+
};
|
|
59
|
+
rawArgs.toReversed().forEach((arg) => {
|
|
60
|
+
if (args.callback) {
|
|
61
|
+
args.extraAssertionArgs.push(arg);
|
|
62
|
+
}
|
|
63
|
+
else if (typeof arg === 'function') {
|
|
64
|
+
args.callback = arg;
|
|
65
|
+
}
|
|
66
|
+
else if (typeof arg === 'string') {
|
|
67
|
+
args.failureMessage = arg;
|
|
68
|
+
}
|
|
69
|
+
else if (typeof arg === 'object') {
|
|
70
|
+
args.options = arg;
|
|
71
|
+
}
|
|
72
|
+
else if (arg === undefined) {
|
|
73
|
+
/** Skip an undefined arg. */
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw new TypeError(`Unexpected waitUntil arg: ${JSON.stringify(arg)}`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (!args.callback) {
|
|
81
|
+
throw new TypeError('Missing waitUntil callback.');
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
callback: args.callback,
|
|
85
|
+
options: parseWaitUntilOptions(args.options),
|
|
86
|
+
extraAssertionArgs: args.extraAssertionArgs.toReversed(),
|
|
87
|
+
failureMessage: args.failureMessage,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export function parseWaitUntilOptions(rawOptions) {
|
|
91
|
+
return {
|
|
92
|
+
interval: rawOptions?.interval || defaultWaitUntilOptions.interval,
|
|
93
|
+
timeout: rawOptions?.timeout || defaultWaitUntilOptions.timeout,
|
|
94
|
+
};
|
|
95
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './augments/assertion-exports.js';
|
|
2
|
+
export * from './augments/assertion.error.js';
|
|
3
|
+
export * from './augments/guards/assert-wrap.js';
|
|
4
|
+
export * from './augments/guards/assert.js';
|
|
5
|
+
export * from './augments/guards/check-wrap.js';
|
|
6
|
+
export * from './augments/guards/check.js';
|
|
7
|
+
export * from './augments/guards/wait-until.js';
|
|
8
|
+
export * from './augments/if-equals.js';
|
|
9
|
+
export type { WaitUntilOptions } from './guard-types/wait-until-function.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './augments/assertion-exports.js';
|
|
2
|
+
export * from './augments/assertion.error.js';
|
|
3
|
+
export * from './augments/guards/assert-wrap.js';
|
|
4
|
+
export * from './augments/guards/assert.js';
|
|
5
|
+
export * from './augments/guards/check-wrap.js';
|
|
6
|
+
export * from './augments/guards/check.js';
|
|
7
|
+
export * from './augments/guards/wait-until.js';
|
|
8
|
+
export * from './augments/if-equals.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@augment-vir/assert",
|
|
3
|
+
"version": "30.0.0",
|
|
4
|
+
"homepage": "https://github.com/electrovir/augment-vir",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/electrovir/augment-vir.git"
|
|
11
|
+
},
|
|
12
|
+
"license": "(MIT or CC0 1.0)",
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "electrovir",
|
|
15
|
+
"url": "https://github.com/electrovir"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"module": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"compile": "virmator compile",
|
|
23
|
+
"docs": "virmator docs",
|
|
24
|
+
"start": "tsx src/index.ts",
|
|
25
|
+
"test": "virmator test node --no-deps",
|
|
26
|
+
"test:coverage": "npm run test coverage",
|
|
27
|
+
"test:docs": "virmator docs check",
|
|
28
|
+
"test:update": "npm test"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@augment-vir/core": "^30.0.0",
|
|
32
|
+
"@date-vir/duration": "^6.0.0",
|
|
33
|
+
"deep-eql": "^5.0.2",
|
|
34
|
+
"expect-type": "^0.20.0",
|
|
35
|
+
"type-fest": "^4.25.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/deep-eql": "^4.0.2",
|
|
39
|
+
"@web/dev-server-esbuild": "^1.0.2",
|
|
40
|
+
"@web/test-runner": "^0.18.3",
|
|
41
|
+
"@web/test-runner-commands": "^0.9.0",
|
|
42
|
+
"@web/test-runner-playwright": "^0.11.0",
|
|
43
|
+
"@web/test-runner-visual-regression": "^0.9.0",
|
|
44
|
+
"c8": "^10.1.2",
|
|
45
|
+
"istanbul-smart-text-reporter": "^1.1.4",
|
|
46
|
+
"typescript": "^5.5.4"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=22"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
}
|
|
54
|
+
}
|