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 succeedGenerator(tag: string, resolve: () => void, done: () => void): (arg1: string) => void { 23 return (msg = 'succeeded') => { 24 console.log(tag, msg); 25 resolve(); 26 done(); 27 }; 28}; 29 30export function exitGenerator(tag: string, reject: (arg1: Error) => void): (arg1: string) => void { 31 return (errMsg = 'exit for error') => { 32 // Current xts log cannot capture error log. Do not use `console.error`. 33 console.log(tag, 'error', errMsg); 34 reject(new Error(errMsg)); 35 }; 36}; 37 38// Unlike testcase in `it`, current test hooks `beforeAll, beforeEach, afterEach, afterAll` 39// need to call done even if reject is called. 40export function exitSpecialGenerator(tag: string, reject: (arg1: Error) => void, done: () => void): 41(arg1: string) => void { 42 return (errMsg = 'exit for error') => { 43 // Current xts log cannot capture error log. Do not use `console.error`. 44 console.log(tag, 'error', errMsg); 45 reject(new Error(errMsg)); 46 done(); 47 }; 48}; 49 50export async function sleep(ms: number): Promise<void> { 51 return new Promise(resolve => setTimeout(resolve, ms)); 52}; 53