sat-wait 0.0.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/.prettierrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "arrowParens": "avoid",
5
+ "printWidth": 120,
6
+ "tabWidth": 2,
7
+ "useTabs": false,
8
+ "semi": true,
9
+ "bracketSpacing": true,
10
+ "proseWrap": "never"
11
+ }
@@ -0,0 +1 @@
1
+ export * from './wait';
package/built/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./wait"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Asynchronously sleeps for the specified number of milliseconds.
3
+ *
4
+ * @param {number} [millisecond=5000] - The number of milliseconds to sleep. Defaults to 5 seconds (5000 milliseconds).
5
+ * @returns {Promise<void>} A Promise that resolves after the specified sleep duration.
6
+ */
7
+ declare function sleep(millisecond?: number): Promise<unknown>;
8
+ export type IWaiterOpts = {
9
+ timeout?: number;
10
+ interval?: number;
11
+ dontThrow?: boolean;
12
+ falseIfError?: boolean;
13
+ stopIfNoError?: boolean;
14
+ message?: string | ((timeout: number, callbackError?: any) => Promise<string> | string);
15
+ waiterError?: new (...args: any[]) => any;
16
+ analyseResult?: (...args: any[]) => boolean | Promise<boolean>;
17
+ before?: () => Promise<void> | any;
18
+ after?: () => Promise<void> | any;
19
+ callEveryCycle?: () => Promise<void> | any;
20
+ };
21
+ /**
22
+ * @example
23
+ * const {waitFor} = require('sat-utils');
24
+ *
25
+ * waitResult();
26
+ * async function waitResult() {
27
+ * await waitFor(async () => new Promise(res => setTimeout(res, 2500)), {
28
+ * timeout: 5000,
29
+ * interval: 500
30
+ * })
31
+ * }
32
+ *
33
+ * @param {Function} callback
34
+ * @param {!Object} options execution options
35
+ * @param {number} [options.timeout] execution time
36
+ * @param {number} [options.interval] call interval
37
+ * @param {boolean} [options.dontThrow] if during waiting cylce result was not achived - last call back execution result will be returned as a waiting cycle result
38
+ * @param {boolean} [options.falseIfError] if call back throws an error - counted as negative result
39
+ * @param {boolean} [options.stopIfNoError] if callback did not throw error - counted as successful result
40
+ * @param {Error|new (...args: any[]) => any} [options.waiterError] error which will be thrown if result will not achieved
41
+ * @param {Function} [options.analyseResult] custom analyser of the call back result
42
+ * @param {Function} [options.before] call before waiting cycle
43
+ * @param {Function} [options.after] call after waiting cycle, even if result was not achived, if result achived - also will be executed
44
+ * @param {Function} [options.callEveryCycle] call every time after main call back execution if result was not achived
45
+ * @returns {any} any result that call back will return
46
+ */
47
+ declare function waitFor(callback: any, options?: IWaiterOpts): Promise<any>;
48
+ declare namespace waitFor {
49
+ var setDefaultOpts: (opts: IWaiterOpts) => void;
50
+ }
51
+ export { waitFor, sleep };
package/built/wait.js ADDED
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.waitFor = waitFor;
4
+ exports.sleep = sleep;
5
+ /* eslint-disable sonarjs/cognitive-complexity */
6
+ const sat_utils_1 = require("sat-utils");
7
+ /**
8
+ * Asynchronously sleeps for the specified number of milliseconds.
9
+ *
10
+ * @param {number} [millisecond=5000] - The number of milliseconds to sleep. Defaults to 5 seconds (5000 milliseconds).
11
+ * @returns {Promise<void>} A Promise that resolves after the specified sleep duration.
12
+ */
13
+ async function sleep(millisecond = 5 * 1000) {
14
+ return new Promise(resolve => setTimeout(resolve, millisecond));
15
+ }
16
+ const defaultOptions = {};
17
+ /**
18
+ * @example
19
+ * const {waitFor} = require('sat-utils');
20
+ *
21
+ * waitResult();
22
+ * async function waitResult() {
23
+ * await waitFor(async () => new Promise(res => setTimeout(res, 2500)), {
24
+ * timeout: 5000,
25
+ * interval: 500
26
+ * })
27
+ * }
28
+ *
29
+ * @param {Function} callback
30
+ * @param {!Object} options execution options
31
+ * @param {number} [options.timeout] execution time
32
+ * @param {number} [options.interval] call interval
33
+ * @param {boolean} [options.dontThrow] if during waiting cylce result was not achived - last call back execution result will be returned as a waiting cycle result
34
+ * @param {boolean} [options.falseIfError] if call back throws an error - counted as negative result
35
+ * @param {boolean} [options.stopIfNoError] if callback did not throw error - counted as successful result
36
+ * @param {Error|new (...args: any[]) => any} [options.waiterError] error which will be thrown if result will not achieved
37
+ * @param {Function} [options.analyseResult] custom analyser of the call back result
38
+ * @param {Function} [options.before] call before waiting cycle
39
+ * @param {Function} [options.after] call after waiting cycle, even if result was not achived, if result achived - also will be executed
40
+ * @param {Function} [options.callEveryCycle] call every time after main call back execution if result was not achived
41
+ * @returns {any} any result that call back will return
42
+ */
43
+ async function waitFor(callback, options = {}) {
44
+ if (!(0, sat_utils_1.isObject)(options)) {
45
+ throw new TypeError(`waitFor(): second argument should be an object, current arg is ${(0, sat_utils_1.getType)(options)}`);
46
+ }
47
+ let callbackError;
48
+ const mergedOpts = { ...defaultOptions, ...options };
49
+ const { message, timeout = 5000, interval = 250, dontThrow = false, analyseResult, falseIfError = true, stopIfNoError, waiterError = Error, callEveryCycle = () => { }, before = () => { }, after = () => { }, } = mergedOpts;
50
+ if (!(0, sat_utils_1.isFunction)(callback) && !(0, sat_utils_1.isAsyncFunction)(callback)) {
51
+ throw new TypeError(`waitFor(): first argument should be a function, async function or arrow function current arg is ${(0, sat_utils_1.getType)(callback)}`);
52
+ }
53
+ if (!(0, sat_utils_1.isNumber)(interval)) {
54
+ throw new TypeError(`waitFor(): second argument property "interval" should be a number, current arg is ${(0, sat_utils_1.getType)(interval)}`);
55
+ }
56
+ if (!(0, sat_utils_1.isNumber)(interval)) {
57
+ throw new TypeError(`waitFor(): second argument property "interval" should be a number, current arg is ${(0, sat_utils_1.getType)(interval)}`);
58
+ }
59
+ if (!(0, sat_utils_1.isNumber)(timeout)) {
60
+ throw new TypeError(`waitFor(): second argument property "timeout" should be a number, current arg is ${(0, sat_utils_1.getType)(timeout)}`);
61
+ }
62
+ if (!(0, sat_utils_1.isFunction)(before) && !(0, sat_utils_1.isAsyncFunction)(before)) {
63
+ throw new TypeError(`waitFor(): second argument property "before" should be a function, async function or arrow function, current arg is ${(0, sat_utils_1.getType)(before)}`);
64
+ }
65
+ if (!(0, sat_utils_1.isFunction)(after) && !(0, sat_utils_1.isAsyncFunction)(after)) {
66
+ throw new TypeError(`waitFor(): second argument property "after" should be a function, async function or arrow function, current arg is ${(0, sat_utils_1.getType)(before)}`);
67
+ }
68
+ if (!(0, sat_utils_1.isFunction)(callEveryCycle) && !(0, sat_utils_1.isAsyncFunction)(callEveryCycle)) {
69
+ throw new TypeError(`waitFor(): second argument property "callEveryCycle" should be a function, async function or arrow function, current arg is ${(0, sat_utils_1.getType)(callEveryCycle)}`);
70
+ }
71
+ if (analyseResult && !(0, sat_utils_1.isFunction)(analyseResult) && !(0, sat_utils_1.isAsyncFunction)(analyseResult)) {
72
+ throw new TypeError(`waitFor(): second argument property "analyseResult" should be a function, async function or arrow function, current arg is ${(0, sat_utils_1.getType)(analyseResult)}`);
73
+ }
74
+ const start = Date.now();
75
+ let result;
76
+ await before();
77
+ while (Date.now() - start < timeout) {
78
+ if (falseIfError) {
79
+ try {
80
+ result = await callback();
81
+ if (stopIfNoError)
82
+ return result;
83
+ }
84
+ catch (error) {
85
+ callbackError = error;
86
+ result = false;
87
+ }
88
+ }
89
+ else {
90
+ result = await callback();
91
+ }
92
+ if (analyseResult && (await analyseResult(result))) {
93
+ await after();
94
+ return result;
95
+ }
96
+ if (result) {
97
+ await after();
98
+ return result;
99
+ }
100
+ try {
101
+ await callEveryCycle();
102
+ }
103
+ catch (error) {
104
+ callbackError = error;
105
+ }
106
+ await sleep(interval);
107
+ }
108
+ await after();
109
+ if (dontThrow) {
110
+ return result;
111
+ }
112
+ if (!result) {
113
+ const callbackErrorMessagePart = callbackError || '';
114
+ let errorMessage = `Required condition was not achieved during ${timeout} ms. ${callbackErrorMessagePart}`;
115
+ if ((0, sat_utils_1.isString)(message)) {
116
+ errorMessage = message;
117
+ }
118
+ else if ((0, sat_utils_1.isFunction)(message) || (0, sat_utils_1.isAsyncFunction)(message)) {
119
+ errorMessage = await message(timeout, callbackError);
120
+ }
121
+ throw new waiterError(errorMessage);
122
+ }
123
+ }
124
+ waitFor.setDefaultOpts = function (opts) {
125
+ Object.keys(defaultOptions).forEach(key => {
126
+ delete defaultOptions[key];
127
+ });
128
+ Object.assign(defaultOptions, opts);
129
+ };
130
+ //# sourceMappingURL=wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.js","sourceRoot":"","sources":["../lib/wait.ts"],"names":[],"mappings":";;AA4MS,0BAAO;AAAE,sBAAK;AA5MvB,iDAAiD;AACjD,yCAA+F;AAE/F;;;;;GAKG;AACH,KAAK,UAAU,KAAK,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI;IACzC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;AAClE,CAAC;AAiBD,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;;;;;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,OAAO,CAAC,cAAc,GAAG,UAAU,IAAiB;IAClD,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACxC,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC,CAAC"}
package/licence ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Potapov Dmytro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "sat-wait",
3
+ "version": "0.0.1",
4
+ "description": "Universal waiting library",
5
+ "scripts": {
6
+ "test": "mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000",
7
+ "lint": "eslint --ext .ts ./",
8
+ "tsc": "rm -rf ./built && tsc"
9
+ },
10
+ "main": "./built/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "require": "./built/index.js"
14
+ }
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Simple-Automation-Testing/sat-wait.git"
19
+ },
20
+ "keywords": [
21
+ "waiting",
22
+ "wait for"
23
+ ],
24
+ "author": "Potapov Dmitriy",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/Simple-Automation-Testing/sat-wait/issues"
28
+ },
29
+ "homepage": "https://github.com/Simple-Automation-Testing/sat-wait#readme",
30
+ "devDependencies": {
31
+ "@types/mocha": "^10.0.8",
32
+ "@types/node": "^22.5.5",
33
+ "@typescript-eslint/eslint-plugin": "^8.6.0",
34
+ "@typescript-eslint/parser": "^8.6.0",
35
+ "assertior": "^0.0.28",
36
+ "eslint": "^8.57.1",
37
+ "eslint-config-prettier": "^9.1.0",
38
+ "eslint-plugin-jsdoc": "^50.2.4",
39
+ "eslint-plugin-no-only-tests": "^3.3.0",
40
+ "eslint-plugin-prettier": "^5.2.1",
41
+ "eslint-plugin-promise": "^7.1.0",
42
+ "eslint-plugin-sonarjs": "^2.0.2",
43
+ "eslint-plugin-unicorn": "^55.0.0",
44
+ "mocha": "^10.7.3",
45
+ "ts-node": "^10.9.2",
46
+ "tslint": "^6.1.3",
47
+ "typescript": "^5.6.2"
48
+ },
49
+ "dependencies": {
50
+ "sat-utils": "^3.0.0"
51
+ }
52
+ }
package/readme.md ADDED
@@ -0,0 +1,41 @@
1
+ # SAT WAITING LIBRARY
2
+
3
+ ![npm downloads](https://img.shields.io/npm/dm/sat-wait.svg?style=flat-square)
4
+
5
+ ## Content
6
+
7
+ - [waitForCondition](#waitforcondition)
8
+
9
+ ## waitForCondition
10
+
11
+ ```js
12
+ const {waitForCondition} = require('sat-utils')
13
+
14
+ waitForCondition.setDefaultOpts({
15
+ timeout: 2500, // default waiting time is 2500 ms
16
+ interval: 250, // default re-check condition interval time is 250 ms
17
+ message: 'Failed', // default error message is "Failed"
18
+ waiterError: TypeError, // default error is TypeError
19
+ });
20
+
21
+ test()
22
+ async function test() {
23
+ await waitForCondition(async () => {
24
+ const result = await someAsyncLogic()
25
+ return result;
26
+ })
27
+ }
28
+
29
+ test1()
30
+ async function test1() {
31
+ await waitForCondition(async () => {
32
+ const result = await someAsyncLogic()
33
+ return result;
34
+ }, {
35
+ analyseResult: (result) => result.status === 200;
36
+ timeout: 25000,
37
+ interval: 250,
38
+ message: (time) => throw new Error(`My custom error throw function with time ${time}`)
39
+ })
40
+ }
41
+ ```
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es2020",
5
+ "sourceMap": true,
6
+ "outDir": "built",
7
+ "declaration": true,
8
+ "allowJs": true
9
+ },
10
+ "exclude": [
11
+ "node_modules",
12
+ "built",
13
+ "specs",
14
+ "example",
15
+ "playground.*"
16
+ ]
17
+ }