|
1 | | -import { |
2 | | - mkdirpSync, |
3 | | - existsSync, |
4 | | - createWriteStream, |
5 | | - realpathSync, |
6 | | -} from "fs-extra"; |
7 | | -import { dirname } from "path"; |
8 | | -import fetch from "node-fetch"; |
9 | | -import { DB_URL, dbLoc, setStoragePath, storagePath } from "./global.helper"; |
10 | | -import * as tmp from "tmp"; |
11 | 1 | import { CUSTOM_CODEQL_PATH_SETTING } from "../../src/config"; |
12 | 2 | import { ConfigurationTarget, env, extensions } from "vscode"; |
13 | | -import { beforeEachAction } from "./test-config"; |
| 3 | +import { beforeEachAction as testConfigBeforeEachAction } from "./test-config"; |
14 | 4 |
|
15 | | -// create an extension storage location |
16 | | -let removeStorage: tmp.DirResult["removeCallback"] | undefined; |
17 | | - |
18 | | -beforeAll(async () => { |
| 5 | +export async function beforeAllAction() { |
19 | 6 | // Set the CLI version here before activation to ensure we don't accidentally try to download a cli |
20 | | - await beforeEachAction(); |
| 7 | + await testConfigBeforeEachAction(); |
21 | 8 | await CUSTOM_CODEQL_PATH_SETTING.updateValue( |
22 | 9 | process.env.CLI_PATH, |
23 | 10 | ConfigurationTarget.Workspace, |
24 | 11 | ); |
25 | 12 |
|
26 | | - // ensure the test database is downloaded |
27 | | - mkdirpSync(dirname(dbLoc)); |
28 | | - if (!existsSync(dbLoc)) { |
29 | | - console.log(`Downloading test database to ${dbLoc}`); |
30 | | - |
31 | | - await new Promise((resolve, reject) => { |
32 | | - return fetch(DB_URL).then((response) => { |
33 | | - const dest = createWriteStream(dbLoc); |
34 | | - response.body.pipe(dest); |
35 | | - |
36 | | - response.body.on("error", reject); |
37 | | - dest.on("error", reject); |
38 | | - dest.on("close", () => { |
39 | | - resolve(dbLoc); |
40 | | - }); |
41 | | - }); |
42 | | - }); |
43 | | - } |
44 | | - |
45 | | - // Create the temp directory to be used as extension local storage. |
46 | | - const dir = tmp.dirSync(); |
47 | | - let storagePath = realpathSync(dir.name); |
48 | | - if (storagePath.substring(0, 2).match(/[A-Z]:/)) { |
49 | | - storagePath = |
50 | | - storagePath.substring(0, 1).toLocaleLowerCase() + |
51 | | - storagePath.substring(1); |
52 | | - } |
53 | | - setStoragePath(storagePath); |
54 | | - |
55 | | - removeStorage = dir.removeCallback; |
56 | | - |
57 | 13 | // Activate the extension |
58 | 14 | await extensions.getExtension("GitHub.vscode-codeql")?.activate(); |
59 | | -}); |
| 15 | +} |
60 | 16 |
|
61 | | -beforeEach(async () => { |
| 17 | +export async function beforeEachAction() { |
62 | 18 | jest.spyOn(env, "openExternal").mockResolvedValue(false); |
63 | 19 |
|
64 | | - await beforeEachAction(); |
| 20 | + await testConfigBeforeEachAction(); |
65 | 21 |
|
66 | 22 | await CUSTOM_CODEQL_PATH_SETTING.updateValue( |
67 | 23 | process.env.CLI_PATH, |
68 | 24 | ConfigurationTarget.Workspace, |
69 | 25 | ); |
70 | | -}); |
71 | | - |
72 | | -// ensure extension is cleaned up. |
73 | | -afterAll(async () => { |
74 | | - // ensure temp directory is cleaned up. |
75 | | - try { |
76 | | - removeStorage?.(); |
77 | | - } catch (e) { |
78 | | - // we are exiting anyway so don't worry about it. |
79 | | - // most likely the directory this is a test on Windows and some files are locked. |
80 | | - console.warn(`Failed to remove storage directory '${storagePath}': ${e}`); |
81 | | - } |
82 | | -}); |
| 26 | +} |
0 commit comments