1/* 2* Copyright (c) 2023 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 16export function logGenerator(tag: string): (arg1: string) => void { 17 return (msg = '') => { 18 console.log(tag, msg); 19 }; 20}; 21 22export function exitGenerator(tag: string, reject): (arg1: string) => void { 23 return (errMsg = 'exit for error') => { 24 // Current xts log cannot capture error log. Do not use `console.error`. 25 console.log(tag, 'error', errMsg); 26 reject(errMsg); 27 }; 28}; 29 30// Unlike testcase in `it`, current test hooks `beforeAll, beforeEach, afterEach, afterAll` 31// need to call done even if reject is called. 32export function exitSpecialGenerator(tag: string, reject, done): (arg1: string) => void { 33 return (errMsg = 'exit for error') => { 34 // Current xts log cannot capture error log. Do not use `console.error`. 35 console.log(tag, 'error', errMsg); 36 reject(errMsg); 37 done(); 38 }; 39}; 40 41export async function sleep(ms: number): Promise<void> { 42 return new Promise(resolve => setTimeout(resolve, ms)); 43}; 44