@@ -4,6 +4,8 @@ import { join } from "path";
44import { autoPickExtensionsDirectory } from "../../../../src/model-editor/extensions-workspace-folder" ;
55import * as files from "../../../../src/common/files" ;
66import { mkdirp } from "fs-extra" ;
7+ import { NotificationLogger } from "../../../../src/common/logging" ;
8+ import { createMockLogger } from "../../../__mocks__/loggerMock" ;
79
810describe ( "autoPickExtensionsDirectory" , ( ) => {
911 let tmpDir : DirectoryResult ;
@@ -19,6 +21,7 @@ describe("autoPickExtensionsDirectory", () => {
1921 typeof workspace . updateWorkspaceFolders
2022 > ;
2123 let mockedTmpDirUri : Uri ;
24+ let logger : NotificationLogger ;
2225
2326 beforeEach ( async ( ) => {
2427 tmpDir = await dir ( {
@@ -47,6 +50,8 @@ describe("autoPickExtensionsDirectory", () => {
4750 . mockReturnValue ( true ) ;
4851
4952 jest . spyOn ( files , "tmpdir" ) . mockReturnValue ( mockedTmpDir ) ;
53+
54+ logger = createMockLogger ( ) ;
5055 } ) ;
5156
5257 afterEach ( async ( ) => {
@@ -72,7 +77,9 @@ describe("autoPickExtensionsDirectory", () => {
7277 } ,
7378 ] ) ;
7479
75- expect ( await autoPickExtensionsDirectory ( ) ) . toEqual ( extensionsDirectory ) ;
80+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual (
81+ extensionsDirectory ,
82+ ) ;
7683 expect ( updateWorkspaceFoldersSpy ) . not . toHaveBeenCalled ( ) ;
7784 } ) ;
7885
@@ -94,7 +101,9 @@ describe("autoPickExtensionsDirectory", () => {
94101 Uri . joinPath ( rootDirectory , "workspace.code-workspace" ) ,
95102 ) ;
96103
97- expect ( await autoPickExtensionsDirectory ( ) ) . toEqual ( extensionsDirectory ) ;
104+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual (
105+ extensionsDirectory ,
106+ ) ;
98107 expect ( updateWorkspaceFoldersSpy ) . toHaveBeenCalledWith ( 2 , 0 , {
99108 name : "CodeQL Extension Packs" ,
100109 uri : extensionsDirectory ,
@@ -121,7 +130,7 @@ describe("autoPickExtensionsDirectory", () => {
121130 Uri . joinPath ( rootDirectory , "workspace.code-workspace" ) ,
122131 ) ;
123132
124- expect ( await autoPickExtensionsDirectory ( ) ) . toEqual ( undefined ) ;
133+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual ( undefined ) ;
125134 } ) ;
126135
127136 it ( "when a workspace file does not exist and there is a common root directory" , async ( ) => {
@@ -138,7 +147,9 @@ describe("autoPickExtensionsDirectory", () => {
138147 } ,
139148 ] ) ;
140149
141- expect ( await autoPickExtensionsDirectory ( ) ) . toEqual ( extensionsDirectory ) ;
150+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual (
151+ extensionsDirectory ,
152+ ) ;
142153 expect ( updateWorkspaceFoldersSpy ) . toHaveBeenCalledWith ( 2 , 0 , {
143154 name : "CodeQL Extension Packs" ,
144155 uri : extensionsDirectory ,
@@ -164,7 +175,9 @@ describe("autoPickExtensionsDirectory", () => {
164175 } ,
165176 ] ) ;
166177
167- expect ( await autoPickExtensionsDirectory ( ) ) . toEqual ( extensionsDirectory ) ;
178+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual (
179+ extensionsDirectory ,
180+ ) ;
168181 expect ( updateWorkspaceFoldersSpy ) . toHaveBeenCalledWith ( 3 , 0 , {
169182 name : "CodeQL Extension Packs" ,
170183 uri : extensionsDirectory ,
@@ -185,7 +198,7 @@ describe("autoPickExtensionsDirectory", () => {
185198 } ,
186199 ] ) ;
187200
188- expect ( await autoPickExtensionsDirectory ( ) ) . toEqual ( undefined ) ;
201+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual ( undefined ) ;
189202 expect ( updateWorkspaceFoldersSpy ) . not . toHaveBeenCalled ( ) ;
190203 } ) ;
191204
@@ -205,10 +218,28 @@ describe("autoPickExtensionsDirectory", () => {
205218 } ,
206219 ] ) ;
207220
208- expect ( await autoPickExtensionsDirectory ( ) ) . toEqual ( extensionsDirectory ) ;
221+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual (
222+ extensionsDirectory ,
223+ ) ;
209224 expect ( updateWorkspaceFoldersSpy ) . toHaveBeenCalledWith ( 2 , 0 , {
210225 name : "CodeQL Extension Packs" ,
211226 uri : extensionsDirectory ,
212227 } ) ;
213228 } ) ;
229+
230+ it ( "when there is no on-disk workspace folder" , async ( ) => {
231+ workspaceFoldersSpy . mockReturnValue ( [
232+ {
233+ uri : Uri . parse ( "codeql-zip-archive://codeql_db" ) ,
234+ name : "my-db" ,
235+ index : 0 ,
236+ } ,
237+ ] ) ;
238+
239+ expect ( await autoPickExtensionsDirectory ( logger ) ) . toEqual ( undefined ) ;
240+ expect ( updateWorkspaceFoldersSpy ) . not . toHaveBeenCalled ( ) ;
241+ expect ( logger . showErrorMessage ) . toHaveBeenCalledWith (
242+ "Could not find any on-disk workspace folders. Please ensure that you have opened a folder or workspace." ,
243+ ) ;
244+ } ) ;
214245} ) ;
0 commit comments