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- import { CUSTOM_CODEQL_PATH_SETTING } from "../../../src/config" ;
12- import { ConfigurationTarget , env , extensions , workspace } from "vscode" ;
13- import { beforeEachAction } from "../test-config" ;
1+ import { workspace } from "vscode" ;
142
15- // create an extension storage location
16- let removeStorage : tmp . DirResult [ "removeCallback" ] | undefined ;
17-
18- beforeAll ( async ( ) => {
19- // Set the CLI version here before activation to ensure we don't accidentally try to download a cli
20- await beforeEachAction ( ) ;
21- await CUSTOM_CODEQL_PATH_SETTING . updateValue (
22- process . env . CLI_PATH ,
23- ConfigurationTarget . Workspace ,
24- ) ;
25-
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 ;
3+ import "../jest.activated-extension.setup" ;
564
5+ beforeAll ( ( ) => {
576 // check that the codeql folder is found in the workspace
587 const folders = workspace . workspaceFolders ;
598 if ( ! folders ) {
@@ -70,30 +19,4 @@ beforeAll(async () => {
7019 ) ;
7120 }
7221 }
73-
74- // Activate the extension
75- await extensions . getExtension ( "GitHub.vscode-codeql" ) ?. activate ( ) ;
76- } ) ;
77-
78- beforeEach ( async ( ) => {
79- jest . spyOn ( env , "openExternal" ) . mockResolvedValue ( false ) ;
80-
81- await beforeEachAction ( ) ;
82-
83- await CUSTOM_CODEQL_PATH_SETTING . updateValue (
84- process . env . CLI_PATH ,
85- ConfigurationTarget . Workspace ,
86- ) ;
87- } ) ;
88-
89- // ensure extension is cleaned up.
90- afterAll ( async ( ) => {
91- // ensure temp directory is cleaned up.
92- try {
93- removeStorage ?.( ) ;
94- } catch ( e ) {
95- // we are exiting anyway so don't worry about it.
96- // most likely the directory this is a test on Windows and some files are locked.
97- console . warn ( `Failed to remove storage directory '${ storagePath } ': ${ e } ` ) ;
98- }
9922} ) ;
0 commit comments