1/* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16class SpecEvent { 17 constructor(attr) { 18 this.id = attr.id; 19 this.coreContext = attr.context; 20 this.eventMonitors = []; 21 } 22 23 subscribeEvent(service) { 24 this.eventMonitors.push(service); 25 } 26 27 async specStart() { 28 for (const monitor of this.eventMonitors) { 29 await monitor['specStart'](); 30 } 31 } 32 33 async specDone() { 34 for (const monitor of this.eventMonitors) { 35 await monitor['specDone'](); 36 } 37 } 38} 39 40class SuiteEvent { 41 constructor(attr) { 42 this.id = attr.id; 43 this.suiteContext = attr.coreContext; 44 this.eventMonitors = []; 45 } 46 47 subscribeEvent(service) { 48 this.eventMonitors.push(service); 49 } 50 51 async suiteStart() { 52 for (const monitor of this.eventMonitors) { 53 await monitor['suiteStart'](); 54 } 55 } 56 57 async suiteDone() { 58 for (const monitor of this.eventMonitors) { 59 await monitor['suiteDone'](); 60 } 61 } 62} 63 64class TaskEvent { 65 constructor(attr) { 66 this.id = attr.id; 67 this.coreContext = attr.coreContext; 68 this.eventMonitors = []; 69 } 70 71 subscribeEvent(service) { 72 this.eventMonitors.push(service); 73 } 74 75 async taskStart() { 76 for (const monitor of this.eventMonitors) { 77 await monitor['taskStart'](); 78 } 79 } 80 81 async taskDone() { 82 for (const monitor of this.eventMonitors) { 83 await monitor['taskDone'](); 84 } 85 } 86 87 incorrectFormat() { 88 for (const monitor of this.eventMonitors) { 89 monitor['incorrectFormat'](); 90 } 91 } 92} 93 94export {SpecEvent, TaskEvent, SuiteEvent}; 95