-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathjest.activated-extension.setup.ts
More file actions
58 lines (50 loc) · 1.57 KB
/
jest.activated-extension.setup.ts
File metadata and controls
58 lines (50 loc) · 1.57 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
55
56
57
58
import { env } from "vscode";
import { beforeEachAction as testConfigBeforeEachAction } from "./test-config";
import type { DirResult } from "tmp";
import { dirSync } from "tmp";
import { realpathSync } from "fs-extra";
import {
getActivatedExtension,
setStoragePath,
storagePath,
} from "./global.helper";
import { getErrorMessage } from "../../src/common/helpers-pure";
if (process.env.CI) {
jest.retryTimes(3, {
logErrorsBeforeRetry: true,
});
}
// create an extension storage location
let removeStorage: DirResult["removeCallback"] | undefined;
export async function beforeAllAction() {
// Create the temp directory to be used as extension local storage.
const dir = dirSync({
unsafeCleanup: true,
});
let storagePath = realpathSync(dir.name);
if (storagePath.substring(0, 2).match(/[A-Z]:/)) {
storagePath =
storagePath.substring(0, 1).toLocaleLowerCase() +
storagePath.substring(1);
}
setStoragePath(storagePath);
removeStorage = dir.removeCallback;
// Activate the extension
await getActivatedExtension();
}
export async function beforeEachAction() {
jest.spyOn(env, "openExternal").mockResolvedValue(false);
await testConfigBeforeEachAction();
}
export async function afterAllAction() {
// ensure temp directory is cleaned up
try {
removeStorage?.();
} catch (e) {
// we are exiting anyway so don't worry about it.
// most likely the directory this is a test on Windows and some files are locked.
console.warn(
`Failed to remove storage directory '${storagePath}': ${getErrorMessage(e)}`,
);
}
}