@intuitionrobotics/testelot 0.47.58 → 1.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 +3 -0
- package/README.md +3 -0
- package/{core → dist/core}/Action.d.ts +7 -4
- package/dist/core/Action.d.ts.map +1 -0
- package/dist/core/Action.js +214 -0
- package/dist/core/Action.js.map +1 -0
- package/{core → dist/core}/Action_Container.d.ts +6 -3
- package/dist/core/Action_Container.d.ts.map +1 -0
- package/dist/core/Action_Container.js +97 -0
- package/dist/core/Action_Container.js.map +1 -0
- package/{core → dist/core}/Action_Custom.d.ts +2 -1
- package/dist/core/Action_Custom.d.ts.map +1 -0
- package/dist/core/Action_Custom.js +32 -0
- package/dist/core/Action_Custom.js.map +1 -0
- package/{core → dist/core}/Action_Http.d.ts +2 -1
- package/dist/core/Action_Http.d.ts.map +1 -0
- package/dist/core/Action_Http.js +181 -0
- package/dist/core/Action_Http.js.map +1 -0
- package/{core → dist/core}/Action_Log.d.ts +2 -1
- package/dist/core/Action_Log.d.ts.map +1 -0
- package/dist/core/Action_Log.js +36 -0
- package/dist/core/Action_Log.js.map +1 -0
- package/{core → dist/core}/Action_Sleep.d.ts +2 -1
- package/dist/core/Action_Sleep.d.ts.map +1 -0
- package/dist/core/Action_Sleep.js +34 -0
- package/dist/core/Action_Sleep.js.map +1 -0
- package/{core → dist/core}/Action_ThrowException.d.ts +2 -1
- package/dist/core/Action_ThrowException.d.ts.map +1 -0
- package/dist/core/Action_ThrowException.js +33 -0
- package/dist/core/Action_ThrowException.js.map +1 -0
- package/{core → dist/core}/ContainerContext.d.ts +1 -0
- package/dist/core/ContainerContext.d.ts.map +1 -0
- package/{core → dist/core}/ContainerContext.js +5 -10
- package/dist/core/ContainerContext.js.map +1 -0
- package/{core → dist/core}/Reporter.d.ts +2 -1
- package/dist/core/Reporter.d.ts.map +1 -0
- package/{core → dist/core}/Reporter.js +36 -40
- package/dist/core/Reporter.js.map +1 -0
- package/{core → dist/core}/Scenario.d.ts +2 -1
- package/dist/core/Scenario.d.ts.map +1 -0
- package/dist/core/Scenario.js +31 -0
- package/dist/core/Scenario.js.map +1 -0
- package/{core → dist/core}/TestException.d.ts +1 -0
- package/dist/core/TestException.d.ts.map +1 -0
- package/{core → dist/core}/TestException.js +2 -6
- package/dist/core/TestException.js.map +1 -0
- package/{core → dist/core}/_base_apis.d.ts +3 -2
- package/dist/core/_base_apis.d.ts.map +1 -0
- package/dist/core/_base_apis.js +81 -0
- package/dist/core/_base_apis.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/{test-app → dist/test-app}/AppTester.d.ts +2 -1
- package/dist/test-app/AppTester.d.ts.map +1 -0
- package/dist/test-app/AppTester.js +47 -0
- package/dist/test-app/AppTester.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +23 -12
- package/core/Action.js +0 -210
- package/core/Action.js.map +0 -1
- package/core/Action_Container.js +0 -112
- package/core/Action_Container.js.map +0 -1
- package/core/Action_Custom.js +0 -46
- package/core/Action_Custom.js.map +0 -1
- package/core/Action_Http.js +0 -197
- package/core/Action_Http.js.map +0 -1
- package/core/Action_Log.js +0 -48
- package/core/Action_Log.js.map +0 -1
- package/core/Action_Sleep.js +0 -48
- package/core/Action_Sleep.js.map +0 -1
- package/core/Action_ThrowException.js +0 -47
- package/core/Action_ThrowException.js.map +0 -1
- package/core/ContainerContext.js.map +0 -1
- package/core/Reporter.js.map +0 -1
- package/core/Scenario.js +0 -44
- package/core/Scenario.js.map +0 -1
- package/core/TestException.js.map +0 -1
- package/core/_base_apis.js +0 -99
- package/core/_base_apis.js.map +0 -1
- package/index.d.ts +0 -13
- package/index.js +0 -47
- package/index.js.map +0 -1
- package/test-app/AppTester.js +0 -59
- package/test-app/AppTester.js.map +0 -1
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by IR on 3/18/17.
|
|
3
3
|
*/
|
|
4
|
-
import { Logger, Constructor } from "@intuitionrobotics/ts-common";
|
|
5
|
-
import { ContextKey } from "./ContainerContext";
|
|
6
|
-
import { Reporter } from "./Reporter";
|
|
4
|
+
import { Logger, type Constructor } from "@intuitionrobotics/ts-common";
|
|
5
|
+
import { ContextKey } from "./ContainerContext.js";
|
|
6
|
+
import { Reporter } from "./Reporter.js";
|
|
7
7
|
export declare enum Status {
|
|
8
8
|
Ready = "Ready",
|
|
9
9
|
Running = "Running",
|
|
@@ -34,7 +34,9 @@ export declare abstract class Action<ParamValue = any, ReturnValue = any> extend
|
|
|
34
34
|
status: Status;
|
|
35
35
|
private shouldFailCondition?;
|
|
36
36
|
private assertFailCondition?;
|
|
37
|
-
protected constructor(actionType:
|
|
37
|
+
protected constructor(actionType: {
|
|
38
|
+
name: string;
|
|
39
|
+
}, tag?: string);
|
|
38
40
|
static resolveTestsToRun(): void;
|
|
39
41
|
expectToFail<T extends Error>(_exceptionType: Constructor<T>, assertFailCondition?: ShouldFailCondition<T>): this;
|
|
40
42
|
processReturnValue(returnValueProcessor: ReturnValueProcessor<ReturnValue>): this;
|
|
@@ -59,3 +61,4 @@ export declare abstract class Action<ParamValue = any, ReturnValue = any> extend
|
|
|
59
61
|
set<ValueType>(key: ContextKey<ValueType>, value: ValueType): ValueType | undefined;
|
|
60
62
|
reset(): void;
|
|
61
63
|
}
|
|
64
|
+
//# sourceMappingURL=Action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action.d.ts","sourceRoot":"","sources":["../../src/main/core/Action.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,OAAO,EAGN,MAAM,EAGN,KAAK,WAAW,EAGhB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,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
2
|
+
* Testelot is a typescript scenario composing framework
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020 Intuition Robotics
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Created by IR on 3/18/17.
|
|
20
|
+
*/
|
|
21
|
+
import { currentTimeMillies, generateUUID, Logger, timeout, Void, isErrorOfType, __stringify } from "@intuitionrobotics/ts-common";
|
|
22
|
+
import { ContextKey } from "./ContainerContext.js";
|
|
23
|
+
import { Reporter } from "./Reporter.js";
|
|
24
|
+
import { TestException } from "./TestException.js";
|
|
25
|
+
export var Status;
|
|
26
|
+
(function (Status) {
|
|
27
|
+
Status["Ready"] = "Ready";
|
|
28
|
+
Status["Running"] = "Running";
|
|
29
|
+
Status["Skipped"] = "Skipped";
|
|
30
|
+
Status["Success"] = "Success";
|
|
31
|
+
Status["Error"] = "Error";
|
|
32
|
+
})(Status || (Status = {}));
|
|
33
|
+
export var ErrorPolicy;
|
|
34
|
+
(function (ErrorPolicy) {
|
|
35
|
+
ErrorPolicy[ErrorPolicy["ContinueOnError"] = 0] = "ContinueOnError";
|
|
36
|
+
ErrorPolicy[ErrorPolicy["SkipOnError"] = 1] = "SkipOnError";
|
|
37
|
+
ErrorPolicy[ErrorPolicy["HaltOnError"] = 2] = "HaltOnError";
|
|
38
|
+
})(ErrorPolicy || (ErrorPolicy = {}));
|
|
39
|
+
export class Action extends Logger {
|
|
40
|
+
static testsToRun = [];
|
|
41
|
+
actionType;
|
|
42
|
+
uuid = generateUUID();
|
|
43
|
+
writeKey;
|
|
44
|
+
readKey;
|
|
45
|
+
parent;
|
|
46
|
+
reporter;
|
|
47
|
+
label = "Unnamed Action";
|
|
48
|
+
policy = ErrorPolicy.SkipOnError;
|
|
49
|
+
_started;
|
|
50
|
+
_ended;
|
|
51
|
+
postExecutionDelay = 0;
|
|
52
|
+
status = Status.Ready;
|
|
53
|
+
shouldFailCondition;
|
|
54
|
+
assertFailCondition;
|
|
55
|
+
constructor(actionType, tag) {
|
|
56
|
+
super(tag || "Testelot");
|
|
57
|
+
this.actionType = actionType.name;
|
|
58
|
+
}
|
|
59
|
+
static resolveTestsToRun() {
|
|
60
|
+
const strings = process.argv.filter((arg) => arg.includes("--test="));
|
|
61
|
+
console.log(`raw: ${__stringify(strings)}`);
|
|
62
|
+
this.testsToRun = strings.map(arg => arg.replace("--test=", ""));
|
|
63
|
+
console.log(`Tests to run: ${__stringify(this.testsToRun)}`);
|
|
64
|
+
}
|
|
65
|
+
expectToFail(_exceptionType, assertFailCondition) {
|
|
66
|
+
this.shouldFailCondition = (e) => {
|
|
67
|
+
const err = isErrorOfType(e, _exceptionType);
|
|
68
|
+
if (!err)
|
|
69
|
+
throw new TestException(`Test should have failed with an: ${_exceptionType.name}`);
|
|
70
|
+
return !assertFailCondition ? true : assertFailCondition(err);
|
|
71
|
+
};
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
processReturnValue(returnValueProcessor) {
|
|
75
|
+
this.assertFailCondition = returnValueProcessor;
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
isContainer() {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
hasParent() {
|
|
82
|
+
return !!this.parent;
|
|
83
|
+
}
|
|
84
|
+
setErrorPolicy(policy) {
|
|
85
|
+
this.policy = policy;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
setParent(parent) {
|
|
89
|
+
this.parent = parent;
|
|
90
|
+
}
|
|
91
|
+
setReporter(reporter) {
|
|
92
|
+
this.reporter = reporter;
|
|
93
|
+
}
|
|
94
|
+
setWriteKey(writeKey) {
|
|
95
|
+
this.writeKey = writeKey;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
setReadKey(readKey) {
|
|
99
|
+
this.readKey = readKey;
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
setPostExecutionDelay(postExecutionDelay) {
|
|
103
|
+
this.postExecutionDelay = postExecutionDelay;
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
setLabel(label) {
|
|
107
|
+
this.label = label;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
getStarted() {
|
|
111
|
+
return this._started;
|
|
112
|
+
}
|
|
113
|
+
getEnded() {
|
|
114
|
+
return this._ended;
|
|
115
|
+
}
|
|
116
|
+
async _executeSubAction(action) {
|
|
117
|
+
action.setParent(this);
|
|
118
|
+
action.setReporter(this.reporter);
|
|
119
|
+
await action._execute();
|
|
120
|
+
}
|
|
121
|
+
resolveLabel(param) {
|
|
122
|
+
if (!this.label)
|
|
123
|
+
return;
|
|
124
|
+
return typeof this.label === "string" ? this.label : this.label(param);
|
|
125
|
+
}
|
|
126
|
+
async _execute() {
|
|
127
|
+
this._started = currentTimeMillies();
|
|
128
|
+
let label;
|
|
129
|
+
let err;
|
|
130
|
+
let retValue = undefined;
|
|
131
|
+
try {
|
|
132
|
+
let param;
|
|
133
|
+
if (this.readKey)
|
|
134
|
+
param = this.get(this.readKey);
|
|
135
|
+
label = this.resolveLabel(param);
|
|
136
|
+
if (Action.testsToRun.length > 0 && !Action.testsToRun.find(testToRun => (label || "").includes(testToRun)))
|
|
137
|
+
this.setStatus(Status.Skipped);
|
|
138
|
+
else
|
|
139
|
+
this.setStatus(Status.Ready);
|
|
140
|
+
if (this.status === Status.Skipped) {
|
|
141
|
+
if (this.isContainer())
|
|
142
|
+
// @ts-expect-error TS struggles with this dynamic typing
|
|
143
|
+
await this.execute();
|
|
144
|
+
if (label)
|
|
145
|
+
this.reporter.logVerbose(`skipped: ${label}`);
|
|
146
|
+
this.reporter.onActionEnded(this);
|
|
147
|
+
this._ended = currentTimeMillies();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (this.isContainer()) {
|
|
151
|
+
if (label)
|
|
152
|
+
this.reporter.logVerbose(`+ ${label}`);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
if (label)
|
|
156
|
+
this.reporter.logVerbose(`Running: ${label}`);
|
|
157
|
+
if (this.readKey)
|
|
158
|
+
this.reporter.logDebug(`Using context: ${this.readKey.key}`);
|
|
159
|
+
}
|
|
160
|
+
this.reporter.onActionStarted(this);
|
|
161
|
+
this.setStatus(Status.Running);
|
|
162
|
+
retValue = await this.execute((param || Void));
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
err = this.shouldFailCondition?.(e) ? undefined : e;
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
if (this.status !== Status.Skipped) {
|
|
169
|
+
this.setStatus(err ? Status.Error : Status.Success);
|
|
170
|
+
this.reporter.onActionEnded(this);
|
|
171
|
+
if (err) {
|
|
172
|
+
if (label)
|
|
173
|
+
this.reporter.logError(`Error in Action: ${label}`);
|
|
174
|
+
this.reporter.logError(err);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// only set the ret value if we expect a success...
|
|
178
|
+
if (this.writeKey && !this.shouldFailCondition) {
|
|
179
|
+
this.set(this.writeKey, retValue);
|
|
180
|
+
}
|
|
181
|
+
this.assertFailCondition?.(retValue);
|
|
182
|
+
// label && this.reporter.logVerbose(`ended: ${label}`);
|
|
183
|
+
if (this.isContainer() && label)
|
|
184
|
+
this.reporter.logVerbose(`- ${label}`);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (this.postExecutionDelay > 0)
|
|
189
|
+
await timeout(this.postExecutionDelay);
|
|
190
|
+
this._ended = currentTimeMillies();
|
|
191
|
+
}
|
|
192
|
+
setStatus(status) {
|
|
193
|
+
this.status = status;
|
|
194
|
+
}
|
|
195
|
+
get(key) {
|
|
196
|
+
if (!this.parent)
|
|
197
|
+
return key.defaultValue;
|
|
198
|
+
return this.parent.get(key);
|
|
199
|
+
}
|
|
200
|
+
remove(key) {
|
|
201
|
+
if (!this.parent)
|
|
202
|
+
return false;
|
|
203
|
+
return this.parent.remove(key);
|
|
204
|
+
}
|
|
205
|
+
set(key, value) {
|
|
206
|
+
if (!this.parent)
|
|
207
|
+
return;
|
|
208
|
+
return this.parent.set(key, value);
|
|
209
|
+
}
|
|
210
|
+
reset() {
|
|
211
|
+
//
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=Action.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action.js","sourceRoot":"","sources":["../../src/main/core/Action.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,OAAO,EACN,kBAAkB,EAClB,YAAY,EACZ,MAAM,EACN,OAAO,EACP,IAAI,EAEJ,aAAa,EACb,WAAW,EACX,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAN,IAAY,MAMX;AAND,WAAY,MAAM;IACjB,yBAAiB,CAAA;IACjB,6BAAmB,CAAA;IACnB,6BAAmB,CAAA;IACnB,6BAAmB,CAAA;IACnB,yBAAiB,CAAA;AAClB,CAAC,EANW,MAAM,KAAN,MAAM,QAMjB;AAED,MAAM,CAAN,IAAkB,WAIjB;AAJD,WAAkB,WAAW;IAC5B,mEAAe,CAAA;IACf,2DAAW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AO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAES,MAAM,CAAY,GAA0B;QACrD,IAAI,CAAC,IAAI,CAAC,MAAM;YACf,OAAO,KAAK,CAAC;QAEd,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAEM,GAAG,CAAY,GAA0B,EAAE,KAAgB;QACjE,IAAI,CAAC,IAAI,CAAC,MAAM;YACf,OAAO;QAER,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK;QACJ,EAAE;IACH,CAAC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by IR on 3/18/17.
|
|
3
3
|
*/
|
|
4
|
-
import { Action } from "./Action";
|
|
5
|
-
import { ContextKey, TypedHashMap } from "./ContainerContext";
|
|
4
|
+
import { Action } from "./Action.js";
|
|
5
|
+
import { ContextKey, TypedHashMap } from "./ContainerContext.js";
|
|
6
6
|
export declare abstract class Action_Container extends Action {
|
|
7
7
|
protected context: TypedHashMap;
|
|
8
8
|
private readonly actions;
|
|
9
9
|
private isProxy;
|
|
10
|
-
protected constructor(type:
|
|
10
|
+
protected constructor(type: {
|
|
11
|
+
name: string;
|
|
12
|
+
}, tag?: string);
|
|
11
13
|
isContainer(): boolean;
|
|
12
14
|
add(...steps: Action<any>[]): this;
|
|
13
15
|
setProxy(isProxy: boolean): this;
|
|
@@ -19,3 +21,4 @@ export declare abstract class Action_Container extends Action {
|
|
|
19
21
|
protected execute(): Promise<void>;
|
|
20
22
|
isEmpty(): boolean;
|
|
21
23
|
}
|
|
24
|
+
//# sourceMappingURL=Action_Container.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action_Container.d.ts","sourceRoot":"","sources":["../../src/main/core/Action_Container.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,OAAO,EACN,MAAM,EAGN,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,UAAU,EACV,YAAY,EACZ,MAAM,uBAAuB,CAAC;AAE/B,8BAAsB,gBACrB,SAAQ,MAAM;IAEd,SAAS,CAAC,OAAO,EAAE,YAAY,CAAsB;IAErD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,OAAO,CAAkB;IAEjC,SAAS,aAAa,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,GAAG,CAAC,EAAE,MAAM;IAI1D,WAAW,IAAI,OAAO;IAIf,GAAG,CAAC,GAAG,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE;IAK3B,QAAQ,CAAC,OAAO,EAAE,OAAO;IAKzB,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,SAAS;IAWxE,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,OAAO;IAWzD,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS;IAU1F,SAAS,CAAC,QAAQ;IAIX,KAAK;cAOI,OAAO;IAyBhB,OAAO,IAAI,OAAO;CAGzB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Testelot is a typescript scenario composing framework
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020 Intuition Robotics
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Created by IR on 3/18/17.
|
|
20
|
+
*/
|
|
21
|
+
import { Action, ErrorPolicy, Status } from "./Action.js";
|
|
22
|
+
import { ContextKey, TypedHashMap } from "./ContainerContext.js";
|
|
23
|
+
export class Action_Container extends Action {
|
|
24
|
+
context = new TypedHashMap();
|
|
25
|
+
actions = [];
|
|
26
|
+
isProxy = false;
|
|
27
|
+
constructor(type, tag) {
|
|
28
|
+
super(type, tag);
|
|
29
|
+
}
|
|
30
|
+
isContainer() {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
add(...steps) {
|
|
34
|
+
this.actions.push(...steps);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
setProxy(isProxy) {
|
|
38
|
+
this.isProxy = isProxy;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
get(key) {
|
|
42
|
+
if (this.isProxy)
|
|
43
|
+
return super.get(key);
|
|
44
|
+
const value = this.context.get(key);
|
|
45
|
+
if (value)
|
|
46
|
+
return value;
|
|
47
|
+
return super.get(key);
|
|
48
|
+
}
|
|
49
|
+
remove(key) {
|
|
50
|
+
if (this.isProxy)
|
|
51
|
+
return super.remove(key);
|
|
52
|
+
const value = this.context.delete(key);
|
|
53
|
+
if (value)
|
|
54
|
+
return value;
|
|
55
|
+
return super.remove(key);
|
|
56
|
+
}
|
|
57
|
+
set(key, value) {
|
|
58
|
+
if (this.isProxy)
|
|
59
|
+
return super.set(key, value);
|
|
60
|
+
this.logDebug(` Storing: ${key.key} => ${JSON.stringify(value)}`);
|
|
61
|
+
const prevValue = this.context.get(key);
|
|
62
|
+
this.context.set(key, value);
|
|
63
|
+
return prevValue;
|
|
64
|
+
}
|
|
65
|
+
getSteps() {
|
|
66
|
+
return this.actions;
|
|
67
|
+
}
|
|
68
|
+
reset() {
|
|
69
|
+
this.context.clear();
|
|
70
|
+
super.reset();
|
|
71
|
+
this.actions.forEach(action => action.reset());
|
|
72
|
+
}
|
|
73
|
+
async execute() {
|
|
74
|
+
for (const action of this.actions) {
|
|
75
|
+
if (this.status !== Status.Running)
|
|
76
|
+
action.setStatus(Status.Skipped);
|
|
77
|
+
await this._executeSubAction(action);
|
|
78
|
+
if (action.status !== Status.Error)
|
|
79
|
+
continue;
|
|
80
|
+
// noinspection FallThroughInSwitchStatementJS
|
|
81
|
+
switch (action.policy) {
|
|
82
|
+
case ErrorPolicy.ContinueOnError:
|
|
83
|
+
continue;
|
|
84
|
+
case ErrorPolicy.HaltOnError:
|
|
85
|
+
this.setErrorPolicy(ErrorPolicy.SkipOnError);
|
|
86
|
+
this.setStatus(Status.Error);
|
|
87
|
+
case ErrorPolicy.SkipOnError:
|
|
88
|
+
this.setStatus(Status.Skipped);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
isEmpty() {
|
|
94
|
+
return this.actions && this.actions.length === 0;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=Action_Container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action_Container.js","sourceRoot":"","sources":["../../src/main/core/Action_Container.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,OAAO,EACN,MAAM,EACN,WAAW,EACX,MAAM,EACN,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,UAAU,EACV,YAAY,EACZ,MAAM,uBAAuB,CAAC;AAE/B,MAAM,OAAgB,gBACrB,SAAQ,MAAM;IAEJ,OAAO,GAAiB,IAAI,YAAY,EAAE,CAAC;IAEpC,OAAO,GAAkB,EAAE,CAAC;IACrC,OAAO,GA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AAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC;IAClD,CAAC;CACD"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by IR on 3/18/17.
|
|
3
3
|
*/
|
|
4
|
-
import { Action } from "./Action";
|
|
4
|
+
import { Action } from "./Action.js";
|
|
5
5
|
export declare class Action_Custom<ParamValue = any, ReturnValue = any> extends Action<ParamValue, ReturnValue> {
|
|
6
6
|
private readonly action;
|
|
7
7
|
protected constructor(action: (action: Action_Custom, param: ParamValue) => Promise<ReturnValue>);
|
|
8
8
|
protected execute(param: ParamValue): Promise<ReturnValue>;
|
|
9
9
|
}
|
|
10
|
+
//# sourceMappingURL=Action_Custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action_Custom.d.ts","sourceRoot":"","sources":["../../src/main/core/Action_Custom.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAEnC,qBAAa,aAAa,CAAC,UAAU,GAAE,GAAG,EAAE,WAAW,GAAE,GAAG,CAC3D,SAAQ,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqE;IAE5F,SAAS,aAAa,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,WAAW,CAAC;cAKhF,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC;CAGhE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Testelot is a typescript scenario composing framework
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020 Intuition Robotics
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Created by IR on 3/18/17.
|
|
20
|
+
*/
|
|
21
|
+
import { Action } from "./Action.js";
|
|
22
|
+
export class Action_Custom extends Action {
|
|
23
|
+
action;
|
|
24
|
+
constructor(action) {
|
|
25
|
+
super(Action_Custom);
|
|
26
|
+
this.action = action;
|
|
27
|
+
}
|
|
28
|
+
async execute(param) {
|
|
29
|
+
return await this.action(this, param);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=Action_Custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action_Custom.js","sourceRoot":"","sources":["../../src/main/core/Action_Custom.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH;;GAEG;AACH,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAEnC,MAAM,OAAO,aACZ,SAAQ,MAA+B;IACtB,MAAM,CAAqE;IAE5F,YAAsB,MAA0E;QAC/F,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAES,KAAK,CAAC,OAAO,CAAC,KAAiB;QACxC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;CACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Action } from "./Action";
|
|
1
|
+
import { Action } from "./Action.js";
|
|
2
2
|
import * as fetch from "node-fetch";
|
|
3
3
|
export declare enum HttpMethod {
|
|
4
4
|
ALL = "all",
|
|
@@ -33,3 +33,4 @@ export declare class Action_Http<T extends object = any> extends Action {
|
|
|
33
33
|
private resolveResponseBody;
|
|
34
34
|
private executeHttpRequest;
|
|
35
35
|
}
|
|
36
|
+
//# sourceMappingURL=Action_Http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Action_Http.d.ts","sourceRoot":"","sources":["../../src/main/core/Action_Http.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,oBAAY,UAAU;IACrB,GAAG,QAAY;IACf,IAAI,SAAY;IAChB,GAAG,QAAY;IACf,KAAK,UAAY;IACjB,MAAM,WAAY;IAClB,GAAG,QAAY;IACf,OAAO,YAAY;IACnB,IAAI,SAAY;CAChB;AAED,qBAAa,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,CAC9C,SAAQ,MAAM;IAEd,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqE;IAC7F,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IAEpC,OAAO,CAAC,MAAM,CAAW;IAEzB,OAAO,CAAC,GAAG,CAA8C;IACzD,OAAO,CAAC,IAAI,CAAgE;IAE5E,OAAO,CAAC,cAAc,CAAe;IACrC,OAAO,CAAC,iBAAiB,CAAC,CAAyB;IACnD,MAAM,CAAC,0BAA0B,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAGnG,SAAS,aAAa,MAAM,EAAE,UAAU;IAKjC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC;IAKtD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,MAAM,GAAG,CAAC,CAAC;IAKhE,SAAS,CAAC,MAAM,EAAE,MAAM;IAKxB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC;IAKxE,iBAAiB,CAAC,MAAM,EAAE,MAAM;IAKhC,oBAAoB,CAAC,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI;IAK/D,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,WAAW;cAeH,OAAO;YAsCT,mBAAmB;YAuBnB,kBAAkB;CAkChC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Testelot is a typescript scenario composing framework
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2020 Intuition Robotics
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Created by IR on 3/18/17.
|
|
20
|
+
*/
|
|
21
|
+
import { Exception, ImplementationMissingException, regexpCase, } from "@intuitionrobotics/ts-common";
|
|
22
|
+
import { Action } from "./Action.js";
|
|
23
|
+
import * as fetch from "node-fetch";
|
|
24
|
+
export var HttpMethod;
|
|
25
|
+
(function (HttpMethod) {
|
|
26
|
+
HttpMethod["ALL"] = "all";
|
|
27
|
+
HttpMethod["POST"] = "post";
|
|
28
|
+
HttpMethod["GET"] = "get";
|
|
29
|
+
HttpMethod["PATCH"] = "patch";
|
|
30
|
+
HttpMethod["DELETE"] = "delete";
|
|
31
|
+
HttpMethod["PUT"] = "put";
|
|
32
|
+
HttpMethod["OPTIONS"] = "options";
|
|
33
|
+
HttpMethod["HEAD"] = "head";
|
|
34
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
35
|
+
export class Action_Http extends Action {
|
|
36
|
+
headers = {};
|
|
37
|
+
method;
|
|
38
|
+
params = {};
|
|
39
|
+
url;
|
|
40
|
+
body;
|
|
41
|
+
responseStatus = 200;
|
|
42
|
+
responseProcessor;
|
|
43
|
+
static global_resolveResponseBody;
|
|
44
|
+
constructor(method) {
|
|
45
|
+
super(Action_Http);
|
|
46
|
+
this.method = method;
|
|
47
|
+
}
|
|
48
|
+
setUrl(url) {
|
|
49
|
+
this.url = url;
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
;
|
|
53
|
+
setBody(body) {
|
|
54
|
+
this.body = body;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
;
|
|
58
|
+
setParams(params) {
|
|
59
|
+
this.params = params;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
;
|
|
63
|
+
addHeader(key, value) {
|
|
64
|
+
this.headers[key] = value;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
;
|
|
68
|
+
setResponseStatus(status) {
|
|
69
|
+
this.responseStatus = status;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
setResponseProcessor(validator) {
|
|
73
|
+
this.responseProcessor = validator;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
resolveBody() {
|
|
77
|
+
if (typeof this.body === "function")
|
|
78
|
+
this.body = this.body(this);
|
|
79
|
+
if (typeof this.body === "string")
|
|
80
|
+
return this.body;
|
|
81
|
+
this.addHeader("Accept", 'application/json');
|
|
82
|
+
this.addHeader("Content-Type", 'application/json');
|
|
83
|
+
return JSON.stringify(this.body, null, 2);
|
|
84
|
+
}
|
|
85
|
+
resolveUrl() {
|
|
86
|
+
if (typeof this.url === "function")
|
|
87
|
+
this.url = this.url(this);
|
|
88
|
+
return this.url + `${this.toUrlParams()}`;
|
|
89
|
+
}
|
|
90
|
+
toUrlParams() {
|
|
91
|
+
if (!this.params)
|
|
92
|
+
return "";
|
|
93
|
+
if (typeof this.params === "function")
|
|
94
|
+
this.params = this.params();
|
|
95
|
+
if (Object.keys(this.params).length === 0)
|
|
96
|
+
return "";
|
|
97
|
+
return `?${Object.keys(this.params).map((key) => {
|
|
98
|
+
return `${key}=${this.params[key]}`;
|
|
99
|
+
}).join("&")}`;
|
|
100
|
+
}
|
|
101
|
+
async execute() {
|
|
102
|
+
const url = this.resolveUrl();
|
|
103
|
+
const body = this.resolveBody();
|
|
104
|
+
const headers = {};
|
|
105
|
+
for (const key of Object.keys(this.headers)) {
|
|
106
|
+
const value = this.headers[key];
|
|
107
|
+
if (typeof value !== "string") {
|
|
108
|
+
headers[key] = value(this);
|
|
109
|
+
}
|
|
110
|
+
else
|
|
111
|
+
headers[key] = value;
|
|
112
|
+
}
|
|
113
|
+
const requestBody = {
|
|
114
|
+
headers: JSON.parse(JSON.stringify(headers)),
|
|
115
|
+
body: body,
|
|
116
|
+
method: this.method
|
|
117
|
+
};
|
|
118
|
+
this.logInfo(`----- Method: ${requestBody.method}`);
|
|
119
|
+
this.logInfo(`-------- Uri: ${url}`);
|
|
120
|
+
if (Object.keys(headers).length > 0) {
|
|
121
|
+
this.logVerbose("-------- Headers --------");
|
|
122
|
+
for (const key of Object.keys(headers)) {
|
|
123
|
+
this.logVerbose(` ${key}: ${headers[key]}`);
|
|
124
|
+
}
|
|
125
|
+
this.logVerbose("-------------------------");
|
|
126
|
+
}
|
|
127
|
+
if (requestBody.body) {
|
|
128
|
+
this.logVerbose("--------- Request Body ----------");
|
|
129
|
+
this.logVerbose(body);
|
|
130
|
+
this.logVerbose("-------------------------");
|
|
131
|
+
}
|
|
132
|
+
return await this.executeHttpRequest(requestBody);
|
|
133
|
+
}
|
|
134
|
+
;
|
|
135
|
+
async resolveResponseBody(response) {
|
|
136
|
+
const contentType = response.headers.get("Content-Type");
|
|
137
|
+
if (!contentType)
|
|
138
|
+
return;
|
|
139
|
+
switch (contentType) {
|
|
140
|
+
case regexpCase(contentType, ".*application/json.*").input:
|
|
141
|
+
return await response.json();
|
|
142
|
+
case regexpCase(contentType, ".*application/x-www-form-urlencoded.*").input:
|
|
143
|
+
return decodeURI((await response.text()));
|
|
144
|
+
case regexpCase(contentType, "^text\\/.*").input:
|
|
145
|
+
return await response.text();
|
|
146
|
+
default:
|
|
147
|
+
if (Action_Http.global_resolveResponseBody)
|
|
148
|
+
return Action_Http.global_resolveResponseBody(this, response);
|
|
149
|
+
}
|
|
150
|
+
throw new ImplementationMissingException(`unhandled response with content-type: ${contentType}`);
|
|
151
|
+
}
|
|
152
|
+
async executeHttpRequest(requestBody) {
|
|
153
|
+
const response = await fetch.default(this.resolveUrl(), requestBody);
|
|
154
|
+
const status = response.status;
|
|
155
|
+
let _responseBody = "";
|
|
156
|
+
const expectedStatus = this.responseStatus;
|
|
157
|
+
if (status !== expectedStatus || status >= 500 && status < 600) {
|
|
158
|
+
try {
|
|
159
|
+
_responseBody = await response.text();
|
|
160
|
+
}
|
|
161
|
+
catch (_ignore) {
|
|
162
|
+
}
|
|
163
|
+
this.logError(`Got Response code: ${status}`);
|
|
164
|
+
this.logError(`Got Response body: ${_responseBody}`);
|
|
165
|
+
throw new Exception(`wrong status code from server. Expected: ${expectedStatus} received: ${status}`);
|
|
166
|
+
}
|
|
167
|
+
// we don't want to undefine what was already defined just because we failed...
|
|
168
|
+
if (status !== 200 && this.writeKey)
|
|
169
|
+
this.get(this.writeKey);
|
|
170
|
+
let responseBody = await this.resolveResponseBody(response);
|
|
171
|
+
if (this.responseProcessor)
|
|
172
|
+
responseBody = this.responseProcessor(responseBody);
|
|
173
|
+
if (responseBody) {
|
|
174
|
+
this.logVerbose("--------- Response ----------");
|
|
175
|
+
this.logVerbose(typeof responseBody === "object" ? JSON.stringify(responseBody, null, 2) : responseBody);
|
|
176
|
+
this.logVerbose("-------------------------");
|
|
177
|
+
}
|
|
178
|
+
return responseBody;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=Action_Http.js.map
|