1- import * as sinon from "sinon" ;
21import * as path from "path" ;
3- import { fail } from "assert" ;
4- import { expect } from "chai" ;
52import { extensions , CancellationToken , Uri , window } from "vscode" ;
63
74import { CodeQLExtensionInterface } from "../../extension" ;
@@ -12,64 +9,51 @@ import {
129 importArchiveDatabase ,
1310 promptImportInternetDatabase ,
1411} from "../../databaseFetcher" ;
15- import { ProgressCallback } from "../../commandRunner" ;
1612import { cleanDatabases , dbLoc , DB_URL , storagePath } from "./global.helper" ;
1713
14+ jest . setTimeout ( 60_000 ) ;
15+
1816/**
1917 * Run various integration tests for databases
2018 */
21- describe ( "Databases" , function ( ) {
22- this . timeout ( 60000 ) ;
23-
19+ describe ( "Databases" , ( ) => {
2420 const LGTM_URL =
2521 "https://lgtm.com/projects/g/aeisenberg/angular-bind-notifier/" ;
2622
2723 let databaseManager : DatabaseManager ;
28- let sandbox : sinon . SinonSandbox ;
29- let inputBoxStub : sinon . SinonStub ;
24+ let inputBoxStub : jest . SpiedFunction < typeof window . showInputBox > ;
3025 let cli : CodeQLCliServer ;
31- let progressCallback : ProgressCallback ;
26+ const progressCallback = jest . fn ( ) ;
3227
3328 beforeEach ( async ( ) => {
34- try {
35- sandbox = sinon . createSandbox ( ) ;
36- // the uri.fsPath function on windows returns a lowercase drive letter
37- // so, force the storage path string to be lowercase, too.
38- progressCallback = sandbox . spy ( ) ;
39- inputBoxStub = sandbox . stub ( window , "showInputBox" ) ;
40- sandbox . stub ( window , "showErrorMessage" ) ;
41- sandbox . stub ( window , "showInformationMessage" ) ;
29+ inputBoxStub = jest
30+ . spyOn ( window , "showInputBox" )
31+ . mockResolvedValue ( undefined ) ;
4232
43- const extension = await extensions
44- . getExtension < CodeQLExtensionInterface | Record < string , never > > (
45- "GitHub.vscode-codeql" ,
46- ) !
47- . activate ( ) ;
48- if ( "databaseManager" in extension ) {
49- databaseManager = extension . databaseManager ;
50- } else {
51- throw new Error (
52- "Extension not initialized. Make sure cli is downloaded and installed properly." ,
53- ) ;
54- }
33+ jest . spyOn ( window , "showErrorMessage" ) . mockResolvedValue ( undefined ) ;
34+ jest . spyOn ( window , "showInformationMessage" ) . mockResolvedValue ( undefined ) ;
5535
56- await cleanDatabases ( databaseManager ) ;
57- } catch ( e ) {
58- fail ( e as Error ) ;
36+ const extension = await extensions
37+ . getExtension < CodeQLExtensionInterface | Record < string , never > > (
38+ "GitHub.vscode-codeql" ,
39+ ) !
40+ . activate ( ) ;
41+ if ( "databaseManager" in extension ) {
42+ databaseManager = extension . databaseManager ;
43+ } else {
44+ throw new Error (
45+ "Extension not initialized. Make sure cli is downloaded and installed properly." ,
46+ ) ;
5947 }
48+
49+ await cleanDatabases ( databaseManager ) ;
6050 } ) ;
6151
6252 afterEach ( async ( ) => {
63- try {
64- sandbox . restore ( ) ;
65- await cleanDatabases ( databaseManager ) ;
66- } catch ( e ) {
67- fail ( e as Error ) ;
68- }
53+ await cleanDatabases ( databaseManager ) ;
6954 } ) ;
7055
7156 it ( "should add a database from a folder" , async ( ) => {
72- const progressCallback = sandbox . spy ( ) as ProgressCallback ;
7357 const uri = Uri . file ( dbLoc ) ;
7458 let dbItem = await importArchiveDatabase (
7559 uri . toString ( true ) ,
@@ -79,27 +63,27 @@ describe("Databases", function () {
7963 { } as CancellationToken ,
8064 cli ,
8165 ) ;
82- expect ( dbItem ) . to . be . eq ( databaseManager . currentDatabaseItem ) ;
83- expect ( dbItem ) . to . be . eq ( databaseManager . databaseItems [ 0 ] ) ;
84- expect ( dbItem ) . not . to . be . undefined ;
66+ expect ( dbItem ) . toBe ( databaseManager . currentDatabaseItem ) ;
67+ expect ( dbItem ) . toBe ( databaseManager . databaseItems [ 0 ] ) ;
68+ expect ( dbItem ) . toBeDefined ( ) ;
8569 dbItem = dbItem ! ;
86- expect ( dbItem . name ) . to . eq ( "db" ) ;
87- expect ( dbItem . databaseUri . fsPath ) . to . eq ( path . join ( storagePath , "db" , "db" ) ) ;
70+ expect ( dbItem . name ) . toBe ( "db" ) ;
71+ expect ( dbItem . databaseUri . fsPath ) . toBe ( path . join ( storagePath , "db" , "db" ) ) ;
8872 } ) ;
8973
9074 it ( "should add a database from lgtm with only one language" , async ( ) => {
91- inputBoxStub . resolves ( LGTM_URL ) ;
75+ inputBoxStub . mockResolvedValue ( LGTM_URL ) ;
9276 let dbItem = await promptImportLgtmDatabase (
9377 databaseManager ,
9478 storagePath ,
9579 progressCallback ,
9680 { } as CancellationToken ,
9781 cli ,
9882 ) ;
99- expect ( dbItem ) . not . to . be . undefined ;
83+ expect ( dbItem ) . toBeDefined ( ) ;
10084 dbItem = dbItem ! ;
101- expect ( dbItem . name ) . to . eq ( "aeisenberg_angular-bind-notifier_106179a" ) ;
102- expect ( dbItem . databaseUri . fsPath ) . to . eq (
85+ expect ( dbItem . name ) . toBe ( "aeisenberg_angular-bind-notifier_106179a" ) ;
86+ expect ( dbItem . databaseUri . fsPath ) . toBe (
10387 path . join (
10488 storagePath ,
10589 "javascript" ,
@@ -109,7 +93,7 @@ describe("Databases", function () {
10993 } ) ;
11094
11195 it ( "should add a database from a url" , async ( ) => {
112- inputBoxStub . resolves ( DB_URL ) ;
96+ inputBoxStub . mockResolvedValue ( DB_URL ) ;
11397
11498 let dbItem = await promptImportInternetDatabase (
11599 databaseManager ,
@@ -118,10 +102,10 @@ describe("Databases", function () {
118102 { } as CancellationToken ,
119103 cli ,
120104 ) ;
121- expect ( dbItem ) . not . to . be . undefined ;
105+ expect ( dbItem ) . toBeDefined ( ) ;
122106 dbItem = dbItem ! ;
123- expect ( dbItem . name ) . to . eq ( "db" ) ;
124- expect ( dbItem . databaseUri . fsPath ) . to . eq (
107+ expect ( dbItem . name ) . toBe ( "db" ) ;
108+ expect ( dbItem . databaseUri . fsPath ) . toBe (
125109 path . join ( storagePath , "simple-db" , "db" ) ,
126110 ) ;
127111 } ) ;
0 commit comments