-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
54 lines (50 loc) · 2.13 KB
/
Copy pathvitest.setup.ts
File metadata and controls
54 lines (50 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import { afterAll, beforeAll } from "vitest";
vi.mock("crypto", async () => {
const actual = await vi.importActual<typeof import("crypto")>("crypto");
return {
...actual,
randomUUID: vi.fn(() => "test-uuid-1234-5678-9abc"),
};
});
beforeAll(async () => {
try {
const imperative = await import("@zowe/imperative");
const Censor = (imperative as any).Censor;
if (Censor && !Censor.__zeTestPatched) {
const originalCensorRawData = Censor.censorRawData?.bind(Censor);
const originalCensorObject = Censor.censorObject?.bind(Censor);
Censor.censorRawData = function (data: unknown, category = ""): unknown {
const config = this.mConfig ?? (imperative as any).ImperativeConfig?.instance?.config;
if (config?.exists && (config.mProperties == null || config.mProperties.profiles == null)) {
return data;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return originalCensorRawData ? originalCensorRawData(data, category) : data;
};
Censor.censorObject = function (data: unknown): unknown {
const config = this.mConfig ?? (imperative as any).ImperativeConfig?.instance?.config;
if (config?.exists && (config.mProperties == null || config.mProperties.profiles == null)) {
return data;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return originalCensorObject ? originalCensorObject(data) : data;
};
Censor.__zeTestPatched = true;
}
} catch {
// Imperative is not always available in every test context — ignore.
}
});
afterAll(() => {
vi.resetModules();
});