@itwin/insights-client
Version:
Insights client for the iTwin platform
38 lines • 1.45 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as fs from "fs";
import * as path from "path";
export class TestSetupError extends Error {
constructor(message) {
super(message);
this.name = "TestSetupFailed";
}
}
export function createDirectory(directoryPath) {
if (fs.existsSync(directoryPath))
return;
const parentDirectory = path.dirname(directoryPath);
createDirectory(parentDirectory);
fs.mkdirSync(directoryPath);
}
export function cleanupDirectory(directory) {
if (fs.existsSync(directory)) {
fs.rmSync(directory, { recursive: true });
fs.mkdirSync(directory);
}
}
export function createGuidValue() {
// https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
// cspell:disable-next-line
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c === "x" ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
export async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
//# sourceMappingURL=CommonTestUtils.js.map