1/* 2 * Copyright (c) 2025 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 */ 15import { Core } from '../../core'; 16import { OhReport } from '../report/OhReport'; 17import { ReportService } from './ReportService'; 18import { EventAttrIF } from '../../interface'; 19class SpecEvent { 20 public id: string; 21 public coreContext: Core; 22 private eventMonitors: Array<ReportService>; 23 private eventOhMonitors: Array<OhReport>; 24 constructor(attr: EventAttrIF) { 25 this.id = attr.id; 26 this.coreContext = attr.coreContext; 27 this.eventMonitors = new Array<ReportService>(); 28 this.eventOhMonitors = new Array<OhReport>(); 29 } 30 31 subscribeEvent(service: ReportService) { 32 this.eventMonitors.push(service); 33 } 34 35 subscribeEvent(service: OhReport) { 36 this.eventOhMonitors.push(service); 37 } 38 39 async specStart() { 40 for (const monitor of this.eventMonitors) { 41 monitor.specStart(); 42 } 43 for (const ohMonitor of this.eventOhMonitors) { 44 await ohMonitor.specStart(); 45 } 46 } 47 48 async specDone() { 49 for (const monitor of this.eventMonitors) { 50 monitor.specDone(); 51 } 52 for (const ohMonitor of this.eventOhMonitors) { 53 await ohMonitor.specDone(); 54 } 55 } 56} 57 58class SuiteEvent { 59 public id: string; 60 public coreContext: Core; 61 private eventMonitors: Array<ReportService>; 62 private eventOhMonitors: Array<OhReport>; 63 constructor(attr: EventAttrIF) { 64 this.id = attr.id; 65 this.coreContext = attr.coreContext; 66 this.eventMonitors = new Array<ReportService>(); 67 this.eventOhMonitors = new Array<OhReport>(); 68 } 69 70 subscribeEvent(service: ReportService) { 71 this.eventMonitors.push(service); 72 } 73 74 subscribeEvent(service: OhReport) { 75 this.eventOhMonitors.push(service); 76 } 77 78 async suiteStart() { 79 for (const monitor of this.eventMonitors) { 80 monitor.suiteStart(); 81 } 82 for (const ohMonitor of this.eventOhMonitors) { 83 await ohMonitor.suiteStart(); 84 } 85 } 86 87 async suiteDone() { 88 for (const monitor of this.eventMonitors) { 89 monitor.suiteDone(); 90 } 91 for (const ohMonitor of this.eventOhMonitors) { 92 await ohMonitor.suiteDone(); 93 } 94 } 95} 96 97class TaskEvent { 98 public id: string; 99 public coreContext: Core; 100 private eventMonitors: Array<ReportService>; 101 private eventOhMonitors: Array<OhReport>; 102 constructor(attr: EventAttrIF) { 103 this.id = attr.id; 104 this.coreContext = attr.coreContext; 105 this.eventMonitors = new Array<ReportService>(); 106 this.eventOhMonitors = new Array<OhReport>(); 107 } 108 109 subscribeEvent(service: ReportService) { 110 this.eventMonitors.push(service); 111 } 112 113 subscribeEvent(service: OhReport) { 114 this.eventOhMonitors.push(service); 115 } 116 117 async taskStart() { 118 for (const monitor of this.eventMonitors) { 119 monitor.taskStart(); 120 } 121 for (const ohMonitor of this.eventOhMonitors) { 122 ohMonitor.taskStart(); 123 } 124 } 125 126 async taskDone() { 127 for (const monitor of this.eventMonitors) { 128 monitor.taskDone(); 129 } 130 for (const ohMonitor of this.eventOhMonitors) { 131 await ohMonitor.taskDone(); 132 } 133 } 134 135 incorrectFormat() { 136 for (const monitor of this.eventMonitors) { 137 monitor.incorrectFormat(); 138 } 139 for (const monitor of this.eventOhMonitors) { 140 monitor.incorrectFormat(); 141 } 142 } 143 144 incorrectTestSuiteFormat() { 145 for (const monitor of this.eventMonitors) { 146 monitor.incorrectTestSuiteFormat(); 147 } 148 for (const monitor of this.eventOhMonitors) { 149 monitor.incorrectTestSuiteFormat(); 150 } 151 } 152} 153 154export { SpecEvent, TaskEvent, SuiteEvent }; 155