@perforce-perfecto/scriptless-helpers 1.45.0 → 1.46.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/package.json +3 -2
- package/src/index.d.ts +6 -1
- package/src/index.js +6 -1
- package/src/index.js.map +1 -1
- package/src/lib/counter-helper.d.ts +7 -0
- package/src/lib/counter-helper.js +40 -0
- package/src/lib/counter-helper.js.map +1 -0
- package/src/lib/integer-helper.d.ts +6 -0
- package/src/lib/integer-helper.js +29 -0
- package/src/lib/integer-helper.js.map +1 -0
- package/src/lib/json-pointer-helper.d.ts +5 -0
- package/src/lib/json-pointer-helper.js +23 -0
- package/src/lib/json-pointer-helper.js.map +1 -0
- package/src/lib/text-helper.d.ts +11 -0
- package/src/lib/text-helper.js +77 -0
- package/src/lib/text-helper.js.map +1 -0
- package/src/lib/timer-helper.d.ts +28 -0
- package/src/lib/timer-helper.js +110 -0
- package/src/lib/timer-helper.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perforce-perfecto/scriptless-helpers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.46.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"tslib": "^2.3.0",
|
|
9
9
|
"webdriverio": "^9.21.0",
|
|
10
10
|
"lodash": "^4.17.21",
|
|
11
|
-
"axios": "^1.12.2"
|
|
11
|
+
"axios": "^1.12.2",
|
|
12
|
+
"jsonpointer": "^5.0.1"
|
|
12
13
|
},
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"access": "public"
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/counter-helper';
|
|
2
2
|
export * from './lib/http-request-helper';
|
|
3
|
+
export * from './lib/integer-helper';
|
|
4
|
+
export * from './lib/json-pointer-helper';
|
|
3
5
|
export * from './lib/message-helper';
|
|
6
|
+
export * from './lib/text-helper';
|
|
7
|
+
export * from './lib/timer-helper';
|
|
8
|
+
export * from './lib/webdriver-session-helper';
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./lib/
|
|
4
|
+
tslib_1.__exportStar(require("./lib/counter-helper"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./lib/http-request-helper"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/integer-helper"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/json-pointer-helper"), exports);
|
|
6
8
|
tslib_1.__exportStar(require("./lib/message-helper"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./lib/text-helper"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/timer-helper"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./lib/webdriver-session-helper"), exports);
|
|
7
12
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/execution-helpers-public/src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/execution-helpers-public/src/index.ts"],"names":[],"mappings":";;;AAAA,+DAAqC;AACrC,oEAA0C;AAC1C,+DAAqC;AACrC,oEAA0C;AAC1C,+DAAqC;AACrC,4DAAkC;AAClC,6DAAmC;AACnC,yEAA+C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Logger } from '../types/logger';
|
|
2
|
+
import { ScriptlessHelper } from '../types/scriptless-helper';
|
|
3
|
+
export declare class CounterHelper extends ScriptlessHelper {
|
|
4
|
+
constructor(logger?: Logger);
|
|
5
|
+
updateCounter(operation: 'incr' | 'decr' | 'set', counter: number, updateByValue: number): number;
|
|
6
|
+
checkCounter(counter: number, operator: string, expectedValue: number): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CounterHelper = void 0;
|
|
4
|
+
const scriptless_helper_1 = require("../types/scriptless-helper");
|
|
5
|
+
class CounterHelper extends scriptless_helper_1.ScriptlessHelper {
|
|
6
|
+
constructor(logger) {
|
|
7
|
+
super(logger);
|
|
8
|
+
}
|
|
9
|
+
updateCounter(operation, counter, updateByValue) {
|
|
10
|
+
switch (operation) {
|
|
11
|
+
case 'incr':
|
|
12
|
+
return counter + updateByValue;
|
|
13
|
+
case 'decr':
|
|
14
|
+
return counter - updateByValue;
|
|
15
|
+
case 'set':
|
|
16
|
+
default:
|
|
17
|
+
return updateByValue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
checkCounter(counter, operator, expectedValue) {
|
|
21
|
+
switch (operator) {
|
|
22
|
+
case '=':
|
|
23
|
+
return counter === expectedValue;
|
|
24
|
+
case '!=':
|
|
25
|
+
return counter !== expectedValue;
|
|
26
|
+
case '>':
|
|
27
|
+
return counter > expectedValue;
|
|
28
|
+
case '>=':
|
|
29
|
+
return counter >= expectedValue;
|
|
30
|
+
case '<':
|
|
31
|
+
return counter < expectedValue;
|
|
32
|
+
case '<=':
|
|
33
|
+
return counter <= expectedValue;
|
|
34
|
+
default:
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.CounterHelper = CounterHelper;
|
|
40
|
+
//# sourceMappingURL=counter-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"counter-helper.js","sourceRoot":"","sources":["../../../../../libs/execution-helpers-public/src/lib/counter-helper.ts"],"names":[],"mappings":";;;AACA,kEAA8D;AAE9D,MAAa,aAAc,SAAQ,oCAAgB;IACjD,YAAY,MAAe;QACzB,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,aAAa,CACX,SAAkC,EAClC,OAAe,EACf,aAAqB;QAErB,QAAQ,SAAS,EAAE,CAAC;YAClB,KAAK,MAAM;gBACT,OAAO,OAAO,GAAG,aAAa,CAAC;YACjC,KAAK,MAAM;gBACT,OAAO,OAAO,GAAG,aAAa,CAAC;YACjC,KAAK,KAAK,CAAC;YACX;gBACE,OAAO,aAAa,CAAC;QACzB,CAAC;IACH,CAAC;IAED,YAAY,CACV,OAAe,EACf,QAAgB,EAChB,aAAqB;QAErB,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,GAAG;gBACN,OAAO,OAAO,KAAK,aAAa,CAAC;YACnC,KAAK,IAAI;gBACP,OAAO,OAAO,KAAK,aAAa,CAAC;YACnC,KAAK,GAAG;gBACN,OAAO,OAAO,GAAG,aAAa,CAAC;YACjC,KAAK,IAAI;gBACP,OAAO,OAAO,IAAI,aAAa,CAAC;YAClC,KAAK,GAAG;gBACN,OAAO,OAAO,GAAG,aAAa,CAAC;YACjC,KAAK,IAAI;gBACP,OAAO,OAAO,IAAI,aAAa,CAAC;YAClC;gBACE,OAAO,KAAK,CAAC;QACjB,CAAC;IACH,CAAC;CACF;AA3CD,sCA2CC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Logger } from '../types/logger';
|
|
2
|
+
import { ScriptlessHelper } from '../types/scriptless-helper';
|
|
3
|
+
export declare class IntegerHelper extends ScriptlessHelper {
|
|
4
|
+
constructor(logger?: Logger);
|
|
5
|
+
compareInteger(operator: string, evaluatedValue: number, expectedValue: number): boolean;
|
|
6
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntegerHelper = void 0;
|
|
4
|
+
const scriptless_helper_1 = require("../types/scriptless-helper");
|
|
5
|
+
class IntegerHelper extends scriptless_helper_1.ScriptlessHelper {
|
|
6
|
+
constructor(logger) {
|
|
7
|
+
super(logger);
|
|
8
|
+
}
|
|
9
|
+
compareInteger(operator, evaluatedValue, expectedValue) {
|
|
10
|
+
switch (operator) {
|
|
11
|
+
case '=':
|
|
12
|
+
return evaluatedValue === expectedValue;
|
|
13
|
+
case '!=':
|
|
14
|
+
return evaluatedValue !== expectedValue;
|
|
15
|
+
case '>':
|
|
16
|
+
return evaluatedValue > expectedValue;
|
|
17
|
+
case '>=':
|
|
18
|
+
return evaluatedValue >= expectedValue;
|
|
19
|
+
case '<':
|
|
20
|
+
return evaluatedValue < expectedValue;
|
|
21
|
+
case '<=':
|
|
22
|
+
return evaluatedValue <= expectedValue;
|
|
23
|
+
default:
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.IntegerHelper = IntegerHelper;
|
|
29
|
+
//# sourceMappingURL=integer-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integer-helper.js","sourceRoot":"","sources":["../../../../../libs/execution-helpers-public/src/lib/integer-helper.ts"],"names":[],"mappings":";;;AACA,kEAA8D;AAE9D,MAAa,aAAc,SAAQ,oCAAgB;IACjD,YAAY,MAAe;QACzB,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,cAAc,CACZ,QAAgB,EAChB,cAAsB,EACtB,aAAqB;QAErB,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,GAAG;gBACN,OAAO,cAAc,KAAK,aAAa,CAAC;YAC1C,KAAK,IAAI;gBACP,OAAO,cAAc,KAAK,aAAa,CAAC;YAC1C,KAAK,GAAG;gBACN,OAAO,cAAc,GAAG,aAAa,CAAC;YACxC,KAAK,IAAI;gBACP,OAAO,cAAc,IAAI,aAAa,CAAC;YACzC,KAAK,GAAG;gBACN,OAAO,cAAc,GAAG,aAAa,CAAC;YACxC,KAAK,IAAI;gBACP,OAAO,cAAc,IAAI,aAAa,CAAC;YACzC;gBACE,OAAO,KAAK,CAAC;QACjB,CAAC;IACH,CAAC;CACF;AA3BD,sCA2BC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JsonPointerHelper = void 0;
|
|
4
|
+
const jsonpointer_1 = require("jsonpointer");
|
|
5
|
+
const scriptless_helper_1 = require("../types/scriptless-helper");
|
|
6
|
+
class JsonPointerHelper extends scriptless_helper_1.ScriptlessHelper {
|
|
7
|
+
isValidJsonPointer(pointer) {
|
|
8
|
+
const jsonPointerRegex = /^(\/([^~/]|~0|~1)*)*$/;
|
|
9
|
+
return jsonPointerRegex.test(pointer);
|
|
10
|
+
}
|
|
11
|
+
getJsonPointerValue(jsonString, jsonPointer) {
|
|
12
|
+
if (!this.isValidJsonPointer(jsonPointer)) {
|
|
13
|
+
throw new Error(`Invalid input error: "${jsonPointer}" is not a valid JSONPointer. (Invalid input: JSON Pointer expression must start with '/': "${jsonPointer}")`);
|
|
14
|
+
}
|
|
15
|
+
const value = (0, jsonpointer_1.get)(JSON.parse(jsonString), jsonPointer);
|
|
16
|
+
if (value === undefined) {
|
|
17
|
+
throw new Error('JSONPointer does not point to valid JSON data');
|
|
18
|
+
}
|
|
19
|
+
return JSON.stringify(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.JsonPointerHelper = JsonPointerHelper;
|
|
23
|
+
//# sourceMappingURL=json-pointer-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-pointer-helper.js","sourceRoot":"","sources":["../../../../../libs/execution-helpers-public/src/lib/json-pointer-helper.ts"],"names":[],"mappings":";;;AAAA,6CAAkC;AAClC,kEAA8D;AAE9D,MAAa,iBAAkB,SAAQ,oCAAgB;IACrD,kBAAkB,CAAC,OAAe;QAChC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;QACjD,OAAO,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,mBAAmB,CAAC,UAAkB,EAAE,WAAmB;QACzD,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CACb,yBAAyB,WAAW,+FAA+F,WAAW,IAAI,CACnJ,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,GAAG,IAAA,iBAAG,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,CAAC;QACvD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACF;AAlBD,8CAkBC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ScriptlessHelper } from '../types/scriptless-helper';
|
|
2
|
+
export declare class TextHelper extends ScriptlessHelper {
|
|
3
|
+
convertTextToNumber(text: string): number;
|
|
4
|
+
compareText(ignoreCase: string, operator: string, evaluatedValue: string, associatedValue: string): boolean;
|
|
5
|
+
findIndexOfText(data: {
|
|
6
|
+
text: string;
|
|
7
|
+
subtext: string;
|
|
8
|
+
begin?: string;
|
|
9
|
+
occurrence?: string;
|
|
10
|
+
}): number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextHelper = void 0;
|
|
4
|
+
const scriptless_helper_1 = require("../types/scriptless-helper");
|
|
5
|
+
class TextHelper extends scriptless_helper_1.ScriptlessHelper {
|
|
6
|
+
convertTextToNumber(text) {
|
|
7
|
+
if (!isNaN(parseInt(text)) &&
|
|
8
|
+
isFinite(Number(text)) &&
|
|
9
|
+
Number(text) === parseInt(text)) {
|
|
10
|
+
return parseInt(text);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
throw new Error(`Failed to convert string param into number: ${text}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
compareText(ignoreCase, operator, evaluatedValue, associatedValue) {
|
|
17
|
+
if (ignoreCase === 'ignore-case') {
|
|
18
|
+
evaluatedValue = evaluatedValue.toLowerCase();
|
|
19
|
+
associatedValue = associatedValue.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
switch (operator) {
|
|
22
|
+
case 'equal':
|
|
23
|
+
return evaluatedValue === associatedValue;
|
|
24
|
+
case 'not-equal':
|
|
25
|
+
return evaluatedValue !== associatedValue;
|
|
26
|
+
case 'one-of':
|
|
27
|
+
return associatedValue
|
|
28
|
+
.split(',')
|
|
29
|
+
.map((value) => value.trim())
|
|
30
|
+
.includes(evaluatedValue);
|
|
31
|
+
case 'not-one-of':
|
|
32
|
+
return !associatedValue
|
|
33
|
+
.split(',')
|
|
34
|
+
.map((value) => value.trim())
|
|
35
|
+
.includes(evaluatedValue);
|
|
36
|
+
case 'contain':
|
|
37
|
+
return evaluatedValue.includes(associatedValue);
|
|
38
|
+
case 'not-contain':
|
|
39
|
+
return !evaluatedValue.includes(associatedValue);
|
|
40
|
+
case 'regexp':
|
|
41
|
+
return new RegExp(associatedValue).test(evaluatedValue);
|
|
42
|
+
default:
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
findIndexOfText(data) {
|
|
47
|
+
if (data.begin) {
|
|
48
|
+
if (data.occurrence === 'last') {
|
|
49
|
+
const foundIndex = data.text
|
|
50
|
+
.slice(0, parseInt(data.begin))
|
|
51
|
+
.lastIndexOf(data.subtext);
|
|
52
|
+
if (foundIndex !== -1) {
|
|
53
|
+
return foundIndex;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const foundIndex = data.text
|
|
58
|
+
.slice(parseInt(data.begin))
|
|
59
|
+
.indexOf(data.subtext);
|
|
60
|
+
if (foundIndex !== -1) {
|
|
61
|
+
return foundIndex + parseInt(data.begin);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (data.occurrence === 'last') {
|
|
67
|
+
return data.text.lastIndexOf(data.subtext);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return data.text.indexOf(data.subtext);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return -1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.TextHelper = TextHelper;
|
|
77
|
+
//# sourceMappingURL=text-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-helper.js","sourceRoot":"","sources":["../../../../../libs/execution-helpers-public/src/lib/text-helper.ts"],"names":[],"mappings":";;;AAAA,kEAA8D;AAE9D,MAAa,UAAW,SAAQ,oCAAgB;IAC9C,mBAAmB,CAAC,IAAY;QAC9B,IACE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtB,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtB,MAAM,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,EAC/B,CAAC;YACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,EAAE,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IAED,WAAW,CACT,UAAkB,EAClB,QAAgB,EAChB,cAAsB,EACtB,eAAuB;QAEvB,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;YACjC,cAAc,GAAG,cAAc,CAAC,WAAW,EAAE,CAAC;YAC9C,eAAe,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC;QAClD,CAAC;QAED,QAAQ,QAAQ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G,IAAI,CAAC,IAAI;qBACzB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBAC3B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACzB,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;oBACtB,OAAO,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC3C,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,EAAE,CAAC;gBAC/B,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7C,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACzC,CAAC;QACH,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;CACF;AAjFD,gCAiFC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ScriptlessHelper } from '../types/scriptless-helper';
|
|
2
|
+
type TimerType = 'ux';
|
|
3
|
+
type InitPolicy = 'reset' | 'noreset';
|
|
4
|
+
type TimeUnit = 'milliseconds' | 'seconds';
|
|
5
|
+
type TimerReportStatus = 'success' | 'failure';
|
|
6
|
+
export type TimerData = {
|
|
7
|
+
isRunning: boolean;
|
|
8
|
+
timeInMs: number;
|
|
9
|
+
type: TimerType;
|
|
10
|
+
};
|
|
11
|
+
export type Timer = Map<string, TimerData>;
|
|
12
|
+
export declare class TimerHelper extends ScriptlessHelper {
|
|
13
|
+
startTimer(timerId: string, initPolicy: InitPolicy, timers: Timer): void;
|
|
14
|
+
stopTimer(timerId: string, timers: Timer): void;
|
|
15
|
+
getTimerInfo(timerId: string, units: TimeUnit, type: TimerType, timers: Timer): number;
|
|
16
|
+
addTimeToRunningTimers(time: string, timers: Timer): void;
|
|
17
|
+
checkTimer(timerId: string, gt: number | undefined, lt: number | undefined, type: TimerType, timers: Timer): {
|
|
18
|
+
timeInMs: number;
|
|
19
|
+
timeInSeconds: number;
|
|
20
|
+
expectedConditions: string[];
|
|
21
|
+
isWithinLimits: boolean;
|
|
22
|
+
unmetCondition: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
isTimerReportSuccessful(result: number, threshold: number, status: TimerReportStatus): boolean;
|
|
25
|
+
private getExpectedConditions;
|
|
26
|
+
private validateTimerCondition;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimerHelper = void 0;
|
|
4
|
+
const scriptless_helper_1 = require("../types/scriptless-helper");
|
|
5
|
+
const message_helper_1 = require("./message-helper");
|
|
6
|
+
class TimerHelper extends scriptless_helper_1.ScriptlessHelper {
|
|
7
|
+
startTimer(timerId, initPolicy, timers) {
|
|
8
|
+
if (timerId === 'script') {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const existingTimer = timers.get(timerId);
|
|
12
|
+
const timeInMs = initPolicy === 'reset' || !existingTimer ? 0 : existingTimer.timeInMs;
|
|
13
|
+
timers.set(timerId, {
|
|
14
|
+
isRunning: true,
|
|
15
|
+
timeInMs,
|
|
16
|
+
type: 'ux'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
stopTimer(timerId, timers) {
|
|
20
|
+
if (timerId === 'script') {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const existingTimer = timers.get(timerId);
|
|
24
|
+
if (!existingTimer) {
|
|
25
|
+
throw new Error(message_helper_1.errorDisplayMessage.command.timer.timerStop.invalidTimerId.replace('[timerId]', timerId));
|
|
26
|
+
}
|
|
27
|
+
if (existingTimer.isRunning) {
|
|
28
|
+
timers.set(timerId, Object.assign(Object.assign({}, existingTimer), { isRunning: false }));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getTimerInfo(timerId, units, type, timers) {
|
|
32
|
+
const existingTimer = timers.get(timerId);
|
|
33
|
+
if (!existingTimer) {
|
|
34
|
+
throw new Error(message_helper_1.errorDisplayMessage.command.timer.timerInfo.invalidTimerId.replace('[timerId]', timerId));
|
|
35
|
+
}
|
|
36
|
+
if (type !== 'ux') {
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
if (units === 'seconds') {
|
|
40
|
+
return Math.round(existingTimer.timeInMs / 1000);
|
|
41
|
+
}
|
|
42
|
+
return existingTimer.timeInMs;
|
|
43
|
+
}
|
|
44
|
+
addTimeToRunningTimers(time, timers) {
|
|
45
|
+
for (const [timerId, timer] of timers) {
|
|
46
|
+
if (timer.isRunning) {
|
|
47
|
+
timers.set(timerId, Object.assign(Object.assign({}, timer), { timeInMs: timer.timeInMs + Number(time) }));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
checkTimer(timerId, gt, lt, type, timers) {
|
|
52
|
+
const timeInMs = this.getTimerInfo(timerId, 'milliseconds', type, timers);
|
|
53
|
+
const timeInSeconds = timeInMs / 1000;
|
|
54
|
+
const expectedConditions = this.getExpectedConditions(gt, lt);
|
|
55
|
+
const validationResult = this.validateTimerCondition(timeInSeconds, gt, lt);
|
|
56
|
+
return {
|
|
57
|
+
timeInMs,
|
|
58
|
+
timeInSeconds,
|
|
59
|
+
expectedConditions,
|
|
60
|
+
isWithinLimits: validationResult.isWithinLimits,
|
|
61
|
+
unmetCondition: validationResult.unmetCondition
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
isTimerReportSuccessful(result, threshold, status) {
|
|
65
|
+
if (status) {
|
|
66
|
+
if (status === 'failure') {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (typeof threshold === 'number' && result > threshold) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
getExpectedConditions(gt, lt) {
|
|
78
|
+
if (typeof lt !== 'number' && typeof gt !== 'number') {
|
|
79
|
+
throw new Error(message_helper_1.errorDisplayMessage.command.timer.timerCheck.noLimitProvided);
|
|
80
|
+
}
|
|
81
|
+
const expectedConditions = [];
|
|
82
|
+
if (typeof gt === 'number') {
|
|
83
|
+
expectedConditions.push(`>${gt}`);
|
|
84
|
+
}
|
|
85
|
+
if (typeof lt === 'number') {
|
|
86
|
+
expectedConditions.push(`<${lt}`);
|
|
87
|
+
}
|
|
88
|
+
return expectedConditions;
|
|
89
|
+
}
|
|
90
|
+
validateTimerCondition(timeInSeconds, gt, lt) {
|
|
91
|
+
if (typeof gt === 'number' && timeInSeconds < gt) {
|
|
92
|
+
return {
|
|
93
|
+
isWithinLimits: false,
|
|
94
|
+
unmetCondition: `[>${gt} seconds]`
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (typeof lt === 'number' && timeInSeconds > lt) {
|
|
98
|
+
return {
|
|
99
|
+
isWithinLimits: false,
|
|
100
|
+
unmetCondition: `[<${lt} seconds]`
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
isWithinLimits: true,
|
|
105
|
+
unmetCondition: undefined
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.TimerHelper = TimerHelper;
|
|
110
|
+
//# sourceMappingURL=timer-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer-helper.js","sourceRoot":"","sources":["../../../../../libs/execution-helpers-public/src/lib/timer-helper.ts"],"names":[],"mappings":";;;AAAA,kEAA8D;AAC9D,qDAAuD;AAavD,MAAa,WAAY,SAAQ,oCAAgB;IAC/C,UAAU,CAAC,OAAe,EAAE,UAAsB,EAAE,MAAa;QAC/D,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,MAAM,a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