@@ -42,6 +42,8 @@ describe("Variant Analysis Monitor", () => {
4242 typeof variantAnalysisManager . autoDownloadVariantAnalysisResult
4343 > ;
4444
45+ const onVariantAnalysisChangeSpy = jest . fn ( ) ;
46+
4547 beforeEach ( async ( ) => {
4648 jest
4749 . spyOn ( config , "isVariantAnalysisLiveResultsEnabled" )
@@ -57,6 +59,7 @@ describe("Variant Analysis Monitor", () => {
5759 ) !
5860 . activate ( ) ;
5961 variantAnalysisMonitor = new VariantAnalysisMonitor ( extension . ctx ) ;
62+ variantAnalysisMonitor . onVariantAnalysisChange ( onVariantAnalysisChangeSpy ) ;
6063
6164 variantAnalysisManager = extension . variantAnalysisManager ;
6265 mockGetDownloadResult = jest
@@ -103,12 +106,12 @@ describe("Variant Analysis Monitor", () => {
103106 it ( "should return early if variant analysis is cancelled" , async ( ) => {
104107 cancellationTokenSource . cancel ( ) ;
105108
106- const result = await variantAnalysisMonitor . monitorVariantAnalysis (
109+ await variantAnalysisMonitor . monitorVariantAnalysis (
107110 variantAnalysis ,
108111 cancellationTokenSource . token ,
109112 ) ;
110113
111- expect ( result ) . toEqual ( { status : "Canceled" } ) ;
114+ expect ( onVariantAnalysisChangeSpy ) . not . toHaveBeenCalled ( ) ;
112115 } ) ;
113116
114117 describe ( "when the variant analysis fails" , ( ) => {
@@ -119,34 +122,22 @@ describe("Variant Analysis Monitor", () => {
119122 mockGetVariantAnalysis . mockResolvedValue ( mockFailedApiResponse ) ;
120123 } ) ;
121124
122- it ( "should mark as failed locally and stop monitoring" , async ( ) => {
123- const result = await variantAnalysisMonitor . monitorVariantAnalysis (
125+ it ( "should mark as failed and stop monitoring" , async ( ) => {
126+ await variantAnalysisMonitor . monitorVariantAnalysis (
124127 variantAnalysis ,
125128 cancellationTokenSource . token ,
126129 ) ;
127130
128131 expect ( mockGetVariantAnalysis ) . toHaveBeenCalledTimes ( 1 ) ;
129- expect ( result . status ) . toEqual ( "Completed" ) ;
130- expect ( result . variantAnalysis ?. status ) . toBe (
131- VariantAnalysisStatus . Failed ,
132- ) ;
133- expect ( result . variantAnalysis ?. failureReason ) . toBe (
134- processFailureReason (
135- mockFailedApiResponse . failure_reason as VariantAnalysisFailureReason ,
136- ) ,
137- ) ;
138- } ) ;
139-
140- it ( "should emit `onVariantAnalysisChange`" , async ( ) => {
141- const spy = jest . fn ( ) ;
142- variantAnalysisMonitor . onVariantAnalysisChange ( spy ) ;
143132
144- const result = await variantAnalysisMonitor . monitorVariantAnalysis (
145- variantAnalysis ,
146- cancellationTokenSource . token ,
133+ expect ( onVariantAnalysisChangeSpy ) . toHaveBeenCalledWith (
134+ expect . objectContaining ( {
135+ status : VariantAnalysisStatus . Failed ,
136+ failureReason : processFailureReason (
137+ mockFailedApiResponse . failure_reason as VariantAnalysisFailureReason ,
138+ ) ,
139+ } ) ,
147140 ) ;
148-
149- expect ( spy ) . toBeCalledWith ( result . variantAnalysis ) ;
150141 } ) ;
151142 } ) ;
152143
@@ -173,18 +164,6 @@ describe("Variant Analysis Monitor", () => {
173164 ) ;
174165 } ) ;
175166
176- it ( "should succeed and return a list of scanned repo ids" , async ( ) => {
177- const result = await variantAnalysisMonitor . monitorVariantAnalysis (
178- variantAnalysis ,
179- cancellationTokenSource . token ,
180- ) ;
181-
182- expect ( result . status ) . toBe ( "Completed" ) ;
183- expect ( result . scannedReposDownloaded ) . toEqual (
184- succeededRepos . map ( ( r ) => r . repository . id ) ,
185- ) ;
186- } ) ;
187-
188167 it ( "should trigger a download extension command for each repo" , async ( ) => {
189168 const succeededRepos = scannedRepos . filter (
190169 ( r ) => r . analysis_status === "succeeded" ,
@@ -238,14 +217,17 @@ describe("Variant Analysis Monitor", () => {
238217 mockGetVariantAnalysis . mockResolvedValue ( mockApiResponse ) ;
239218 } ) ;
240219
241- it ( "should succeed and return an empty list of scanned repo ids" , async ( ) => {
242- const result = await variantAnalysisMonitor . monitorVariantAnalysis (
220+ it ( "should succeed and not download any repos via a command" , async ( ) => {
221+ const commandSpy = jest
222+ . spyOn ( commands , "executeCommand" )
223+ . mockResolvedValue ( undefined ) ;
224+
225+ await variantAnalysisMonitor . monitorVariantAnalysis (
243226 variantAnalysis ,
244227 cancellationTokenSource . token ,
245228 ) ;
246229
247- expect ( result . status ) . toBe ( "Completed" ) ;
248- expect ( result . scannedReposDownloaded ) . toEqual ( [ ] ) ;
230+ expect ( commandSpy ) . not . toHaveBeenCalled ( ) ;
249231 } ) ;
250232
251233 it ( "should not try to download any repos" , async ( ) => {
@@ -265,16 +247,6 @@ describe("Variant Analysis Monitor", () => {
265247 mockGetVariantAnalysis . mockResolvedValue ( mockApiResponse ) ;
266248 } ) ;
267249
268- it ( "should succeed and return an empty list of scanned repo ids" , async ( ) => {
269- const result = await variantAnalysisMonitor . monitorVariantAnalysis (
270- variantAnalysis ,
271- cancellationTokenSource . token ,
272- ) ;
273-
274- expect ( result . status ) . toBe ( "Completed" ) ;
275- expect ( result . scannedReposDownloaded ) . toEqual ( [ ] ) ;
276- } ) ;
277-
278250 it ( "should not try to download any repos" , async ( ) => {
279251 await variantAnalysisMonitor . monitorVariantAnalysis (
280252 variantAnalysis ,
0 commit comments