UNPKG

@intuitionrobotics/testelot

Version:
97 lines 3.02 kB
/* * Testelot is a typescript scenario composing framework * * Copyright (C) 2020 Intuition Robotics * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Created by IR on 3/18/17. */ import { Action, ErrorPolicy, Status } from "./Action.js"; import { ContextKey, TypedHashMap } from "./ContainerContext.js"; export class Action_Container extends Action { context = new TypedHashMap(); actions = []; isProxy = false; constructor(type, tag) { super(type, tag); } isContainer() { return true; } add(...steps) { this.actions.push(...steps); return this; } setProxy(isProxy) { this.isProxy = isProxy; return this; } get(key) { if (this.isProxy) return super.get(key); const value = this.context.get(key); if (value) return value; return super.get(key); } remove(key) { if (this.isProxy) return super.remove(key); const value = this.context.delete(key); if (value) return value; return super.remove(key); } set(key, value) { if (this.isProxy) return super.set(key, value); this.logDebug(` Storing: ${key.key} => ${JSON.stringify(value)}`); const prevValue = this.context.get(key); this.context.set(key, value); return prevValue; } getSteps() { return this.actions; } reset() { this.context.clear(); super.reset(); this.actions.forEach(action => action.reset()); } async execute() { for (const action of this.actions) { if (this.status !== Status.Running) action.setStatus(Status.Skipped); await this._executeSubAction(action); if (action.status !== Status.Error) continue; // noinspection FallThroughInSwitchStatementJS switch (action.policy) { case ErrorPolicy.ContinueOnError: continue; case ErrorPolicy.HaltOnError: this.setErrorPolicy(ErrorPolicy.SkipOnError); this.setStatus(Status.Error); case ErrorPolicy.SkipOnError: this.setStatus(Status.Skipped); break; } } } isEmpty() { return this.actions && this.actions.length === 0; } } //# sourceMappingURL=Action_Container.js.map