@opentap/runner-client 2.38.1 → 2.39.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/dist/cjs/DTOs.d.ts +84 -133
- package/dist/cjs/DTOs.js +257 -442
- package/dist/cjs/SessionClient.d.ts +10 -1
- package/dist/cjs/SessionClient.js +63 -30
- package/dist/mjs/DTOs.d.ts +84 -133
- package/dist/mjs/DTOs.js +169 -346
- package/dist/mjs/SessionClient.d.ts +10 -1
- package/dist/mjs/SessionClient.js +56 -26
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BreakPoints, CommonContext, CommonSettings, DataGridControl, IMetricsConfiguration, Image, Interaction, ListItemType, LogList, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, Resource, Result, RunStatus, SessionEvent, Setting, TestPlan, TestStepType, TestStepValidationError, WatchDog } from './DTOs';
|
|
1
|
+
import { BreakPoints, CommonContext, CommonSettings, DataGridControl, IMetricsConfiguration, Image, Interaction, ListItemType, LogList, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, Resource, Result, RunStatus, SessionEvent, SessionEventName, Setting, TestPlan, TestStepType, TestStepValidationError, WatchDog } from './DTOs';
|
|
2
2
|
import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions } from 'nats.ws';
|
|
3
3
|
import { BaseClient } from './BaseClient';
|
|
4
4
|
export declare class SessionClient extends BaseClient {
|
|
5
5
|
private _sessionId;
|
|
6
6
|
private subscriptions;
|
|
7
|
+
private static readonly sessionEventFactories;
|
|
7
8
|
get sessionId(): string | undefined;
|
|
8
9
|
constructor(baseSubject: string, options: ConnectionOptions);
|
|
9
10
|
/**
|
|
@@ -18,6 +19,14 @@ export declare class SessionClient extends BaseClient {
|
|
|
18
19
|
* @returns Subscription object
|
|
19
20
|
*/
|
|
20
21
|
connectSessionLogs(sessionLogsHandler: (logList: LogList | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
|
|
22
|
+
/**
|
|
23
|
+
* Connect to a specific session event
|
|
24
|
+
* @param eventName The name of the session event to connect to
|
|
25
|
+
* @param eventHandler Function to be called when session event or error is received
|
|
26
|
+
* @param options (optional) Subscription options
|
|
27
|
+
* @returns Subscription object
|
|
28
|
+
*/
|
|
29
|
+
connectSessionEvent(eventName: SessionEventName, eventHandler: (sessionEvent: SessionEvent | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
|
|
21
30
|
/**
|
|
22
31
|
* @param eventHandler Function to be called when session event or error is received
|
|
23
32
|
* @param options (optional) Subscription options
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Result, RunStatus,
|
|
2
|
-
import { JSONCodec } from 'nats.ws';
|
|
1
|
+
import { BreakEvent, BreakPoints, CommonContext, CommonSettings, DataGridControl, HeartbeatEvent, Image, Interaction, ListItemType, LogList, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Result, RunStatus, SessionEventName, SessionStateChangedEvent, SessionTimeoutEvent, Setting, SettingsChangedEvent, StartingEvent, StartedEvent, StoppedEvent, StoppingEvent, TestPlan, TestPlanChangedEvent, TestPlanSettingsChangedEvent, TestStepChangedEvent, TestStepType, TestStepValidationError, TypeCacheInvalidatedEvent, UserInputRequestCompletedEvent, UserInputRequestedEvent, WatchDog, } from './DTOs';
|
|
3
2
|
import { BaseClient } from './BaseClient';
|
|
3
|
+
import { jsonCodec } from './encoders';
|
|
4
4
|
export class SessionClient extends BaseClient {
|
|
5
5
|
constructor(baseSubject, options) {
|
|
6
6
|
super(baseSubject, options);
|
|
@@ -34,7 +34,6 @@ export class SessionClient extends BaseClient {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
try {
|
|
37
|
-
const jsonCodec = JSONCodec();
|
|
38
37
|
const logListJson = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
|
|
39
38
|
const logList = LogList.fromJS(logListJson);
|
|
40
39
|
sessionLogsHandler(logList, error);
|
|
@@ -44,29 +43,47 @@ export class SessionClient extends BaseClient {
|
|
|
44
43
|
}
|
|
45
44
|
} }));
|
|
46
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Connect to a specific session event
|
|
48
|
+
* @param eventName The name of the session event to connect to
|
|
49
|
+
* @param eventHandler Function to be called when session event or error is received
|
|
50
|
+
* @param options (optional) Subscription options
|
|
51
|
+
* @returns Subscription object
|
|
52
|
+
*/
|
|
53
|
+
connectSessionEvent(eventName, eventHandler, options) {
|
|
54
|
+
const factory = SessionClient.sessionEventFactories[eventName];
|
|
55
|
+
return this.subscribe(`Events.${eventName}`, Object.assign(Object.assign({}, options), { callback: (error, encodedMessage) => {
|
|
56
|
+
var _a;
|
|
57
|
+
if (error) {
|
|
58
|
+
eventHandler(undefined, error);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
if (((_a = encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
63
|
+
const payload = jsonCodec.decode(encodedMessage.data);
|
|
64
|
+
const sessionEvent = factory(payload);
|
|
65
|
+
sessionEvent.sessionId = this._sessionId;
|
|
66
|
+
eventHandler(sessionEvent, null);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
eventHandler(undefined, err);
|
|
71
|
+
}
|
|
72
|
+
} }));
|
|
73
|
+
}
|
|
47
74
|
/**
|
|
48
75
|
* @param eventHandler Function to be called when session event or error is received
|
|
49
76
|
* @param options (optional) Subscription options
|
|
50
77
|
* @returns Subscription object
|
|
51
78
|
*/
|
|
52
79
|
connectSessionEvents(eventHandler, options) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const sessionEventJs = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
|
|
61
|
-
const sessionEvent = SessionEvent.fromJS(sessionEventJs);
|
|
62
|
-
eventHandler(sessionEvent, error);
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
eventHandler(undefined, error);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
this.subscriptions.push(this.subscribe('Events', Object.assign(Object.assign({}, options), { callback })));
|
|
69
|
-
this.subscriptions.push(this.subscribe('Events.*', Object.assign(Object.assign({}, options), { callback })));
|
|
80
|
+
this.unsubscribeSessionEvents();
|
|
81
|
+
this.subscriptions = [];
|
|
82
|
+
// Subscribe to all session events using the new connectSessionEvent method
|
|
83
|
+
Object.keys(SessionClient.sessionEventFactories).forEach(eventName => {
|
|
84
|
+
const subscription = this.connectSessionEvent(eventName, eventHandler, options);
|
|
85
|
+
this.subscriptions.push(subscription);
|
|
86
|
+
});
|
|
70
87
|
}
|
|
71
88
|
/**
|
|
72
89
|
* Connect to listen to the TestPlanRun events for the given test plan run ID.
|
|
@@ -83,7 +100,6 @@ export class SessionClient extends BaseClient {
|
|
|
83
100
|
return;
|
|
84
101
|
}
|
|
85
102
|
try {
|
|
86
|
-
const jsonCodec = JSONCodec();
|
|
87
103
|
const onTestPlanRunJs = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
|
|
88
104
|
const onTestPlanRun = OnTestPlanRun.fromJS(onTestPlanRunJs);
|
|
89
105
|
const planRunId = (_a = encodedMessage.subject.match(/\.PlanRun\.(.+)$/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
@@ -115,7 +131,6 @@ export class SessionClient extends BaseClient {
|
|
|
115
131
|
return;
|
|
116
132
|
}
|
|
117
133
|
try {
|
|
118
|
-
const jsonCodec = JSONCodec();
|
|
119
134
|
const logListJson = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
|
|
120
135
|
const logList = LogList.fromJS(logListJson);
|
|
121
136
|
handler(logList, error);
|
|
@@ -141,7 +156,6 @@ export class SessionClient extends BaseClient {
|
|
|
141
156
|
return;
|
|
142
157
|
}
|
|
143
158
|
try {
|
|
144
|
-
const jsonCodec = JSONCodec();
|
|
145
159
|
const onTestStepRunJs = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
|
|
146
160
|
const onTestStepRun = OnTestStepRun.fromJS(onTestStepRunJs);
|
|
147
161
|
const [, planRunId, stepRunId] = (_a = encodedMessage.subject.match(/\.PlanRun\.(.+)\.StepRun\.(.+)$/)) !== null && _a !== void 0 ? _a : [
|
|
@@ -179,7 +193,6 @@ export class SessionClient extends BaseClient {
|
|
|
179
193
|
return;
|
|
180
194
|
}
|
|
181
195
|
try {
|
|
182
|
-
const jsonCodec = JSONCodec();
|
|
183
196
|
const resultJs = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
|
|
184
197
|
const result = Result.fromJS(resultJs);
|
|
185
198
|
handler(result, error);
|
|
@@ -193,8 +206,8 @@ export class SessionClient extends BaseClient {
|
|
|
193
206
|
* Unsubscibe from session events
|
|
194
207
|
*/
|
|
195
208
|
unsubscribeSessionEvents() {
|
|
196
|
-
|
|
197
|
-
|
|
209
|
+
this.subscriptions.forEach(subscription => subscription.unsubscribe());
|
|
210
|
+
this.subscriptions = [];
|
|
198
211
|
}
|
|
199
212
|
/**
|
|
200
213
|
* Retrieve session logs
|
|
@@ -680,3 +693,20 @@ export class SessionClient extends BaseClient {
|
|
|
680
693
|
return this.request('SetMetricsConfiguration', metricsRequest).then(this.success()).catch(this.error());
|
|
681
694
|
}
|
|
682
695
|
}
|
|
696
|
+
SessionClient.sessionEventFactories = {
|
|
697
|
+
[SessionEventName.TypeCacheInvalidated]: () => TypeCacheInvalidatedEvent.fromJS(),
|
|
698
|
+
[SessionEventName.TestPlanSettingsChanged]: () => TestPlanSettingsChangedEvent.fromJS(),
|
|
699
|
+
[SessionEventName.SessionTimeout]: () => SessionTimeoutEvent.fromJS(),
|
|
700
|
+
[SessionEventName.Starting]: () => StartingEvent.fromJS(),
|
|
701
|
+
[SessionEventName.Started]: () => StartedEvent.fromJS(),
|
|
702
|
+
[SessionEventName.Heartbeat]: payload => HeartbeatEvent.fromJS(payload),
|
|
703
|
+
[SessionEventName.Stopping]: () => StoppingEvent.fromJS(),
|
|
704
|
+
[SessionEventName.Stopped]: () => StoppedEvent.fromJS(),
|
|
705
|
+
[SessionEventName.TestPlanChanged]: () => TestPlanChangedEvent.fromJS(),
|
|
706
|
+
[SessionEventName.SessionStateChanged]: payload => SessionStateChangedEvent.fromJS(payload),
|
|
707
|
+
[SessionEventName.SettingsChanged]: payload => SettingsChangedEvent.fromJS(payload),
|
|
708
|
+
[SessionEventName.TestStepChanged]: payload => TestStepChangedEvent.fromJS(payload),
|
|
709
|
+
[SessionEventName.Break]: payload => BreakEvent.fromJS(payload),
|
|
710
|
+
[SessionEventName.UserInputRequested]: payload => UserInputRequestedEvent.fromJS(payload),
|
|
711
|
+
[SessionEventName.UserInputRequestCompleted]: payload => UserInputRequestCompletedEvent.fromJS(payload),
|
|
712
|
+
};
|