@opentap/runner-client
Version:
This is the web client for the OpenTAP Runner.
132 lines (131 loc) • 6.25 kB
JavaScript
import { AssetUpdatedEvent, RunnerEvent, TestPlanRunCompletedEvent, TestPlanRunStartEvent } from './DTOs';
import { JSONCodec } from 'nats.ws';
import { BaseClient } from './BaseClient';
export class SystemClient extends BaseClient {
constructor(baseSubject, options) {
super(baseSubject, options);
}
/**
* Subscribe to the lifetime event.
* @param listener
* @param {SubscriptionOptions} options
* @returns {Subscription}
*/
subscribeLifetimeEventListener(listener, options) {
const subject = 'Runner.*.Events.Lifetime';
return this.subscribe(subject, Object.assign(Object.assign({}, options), { callback: (error, message) => {
if (error) {
listener(this.natsErrorHandler(error, subject), null);
return;
}
try {
const jsonCodec = JSONCodec();
const data = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
listener(null, data);
}
catch (error) {
listener(this.natsErrorHandler(error, subject), null);
}
} }));
}
/**
* Subscribe to the runner updated events for the given Runner ID.
* Wildcard can be used to receive all runner updated events.
* @param {string} runnerId
* @param {(error:ErrorResponse|null,message:RunnerEvent|null)=>void} listener
* @param {SubscriptionOptions} options?
*/
subscribeRunnerUpdatedEvents(runnerId, listener, options) {
const subject = `RunnerRegistry.${runnerId}.Events.Updated`;
return this.subscribe(subject, Object.assign(Object.assign({}, options), { callback: (error, message) => {
if (error) {
listener(this.natsErrorHandler(error, subject), null);
return;
}
try {
const jsonCodec = JSONCodec();
const data = RunnerEvent.fromJS(jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data));
listener(null, data);
}
catch (error) {
listener(this.natsErrorHandler(error, subject), null);
}
} }));
}
/**
* Subscribe to the test plan run start events for the given Runner and Run ID.
* Wildcard can be used for the Runner or Run ID to receive all test plan run start events.
* @param {string} runnerId
* @param {string} runId
* @param {(error:ErrorResponse|null,message:TestStepRunStartEventArgs|null)=>void} listener
* @param {SubscriptionOptions} options?
*/
subscribeTestPlanRunStartEventListener(runnerId, runId, listener, options) {
const subject = `Runner.${runnerId}.Runs.${runId}.Events.TestPlanRunStart`;
return this.subscribe(subject, Object.assign(Object.assign({}, options), { callback: (error, message) => {
if (error) {
listener(this.natsErrorHandler(error, subject), null);
return;
}
try {
const jsonCodec = JSONCodec();
const eventJson = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
const testPlanRunStartEventArgs = TestPlanRunStartEvent.fromJS(eventJson);
listener(null, testPlanRunStartEventArgs);
}
catch (error) {
listener(this.natsErrorHandler(error, subject), null);
}
} }));
}
/**
* Subscribe to the test plan run completed events for the given Runner and Run ID.
* Wildcard can be used for the Runner or Run ID to receive all test plan run completed events.
* @param {string} runnerId
* @param {string} runId
* @param {(error:ErrorResponse|null,message:TestStepRunStartEventArgs|null)=>void} listener
* @param {SubscriptionOptions} options?
*/
subscribeTestPlanRunCompletedEventListener(runnerId, runId, listener, options) {
const subject = `Runner.${runnerId}.Runs.${runId}.Events.TestPlanRunCompleted`;
return this.subscribe(subject, Object.assign(Object.assign({}, options), { callback: (error, message) => {
if (error) {
listener(this.natsErrorHandler(error, subject), null);
return;
}
try {
const jsonCodec = JSONCodec();
const eventJson = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
const testPlanRunCompletedEventArgs = TestPlanRunCompletedEvent.fromJS(eventJson);
listener(null, testPlanRunCompletedEventArgs);
}
catch (error) {
listener(this.natsErrorHandler(error, subject), null);
}
} }));
}
/**
* Subscribe to the asset update events for the given Runner ID.
* Wildcard can be used to receive all asset update events.
* @param {string} runnerId
* @param {(error:ErrorResponse|null,message:AssetUpdatedEvent|null)=>void} listener
* @param {SubscriptionOptions} options?
*/
subscribeAssetUpdatedEvents(runnerId, listener, options) {
const subject = `RunnerRegistry.${runnerId}.Events.AssetsUpdated`;
return this.subscribe(subject, Object.assign(Object.assign({}, options), { callback: (error, message) => {
if (error) {
listener(this.natsErrorHandler(error, subject), null);
return;
}
try {
const jsonCodec = JSONCodec();
const data = AssetUpdatedEvent.fromJS(jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data));
listener(null, data);
}
catch (error) {
listener(this.natsErrorHandler(error, subject), null);
}
} }));
}
}