@@ -9,7 +9,7 @@ import assert from 'assert'
99import sinon from 'sinon'
1010import globals from '../../shared/extensionGlobals'
1111import { randomUUID } from '../../shared/crypto'
12- import * as setContext from '../../shared/vscode/setContext'
12+ import { getContext } from '../../shared/vscode/setContext'
1313import { assertTelemetry , installFakeClock } from '../testUtil'
1414import {
1515 NotificationFetcher ,
@@ -88,7 +88,7 @@ describe('Notifications Controller', function () {
8888 }
8989
9090 beforeEach ( async function ( ) {
91- panelNode . setNotifications ( [ ] , [ ] )
91+ await panelNode . setNotifications ( [ ] , [ ] )
9292 fetcher = new TestFetcher ( )
9393 controller = new NotificationsController ( panelNode , fetcher , '_aws.test.notification' as any )
9494
@@ -108,10 +108,6 @@ describe('Notifications Controller', function () {
108108 } )
109109
110110 it ( 'can fetch and store startup notifications' , async function ( ) {
111- // There seems to be a race condition with having a global spy object that is reset after each
112- // test. Doesn't seem to affect the other ones, for some reason.
113- const setContextSpy = sinon . spy ( setContext , 'setContext' )
114-
115111 const eTag = randomUUID ( )
116112 const content = {
117113 schemaVersion : '1.x' ,
@@ -140,14 +136,10 @@ describe('Notifications Controller', function () {
140136 assert . deepStrictEqual ( panelNode . startUpNotifications , [ content . notifications [ 0 ] ] )
141137 assert . equal ( panelNode . getChildren ( ) . length , 1 )
142138 assert . equal ( focusPanelSpy . callCount , 0 )
143- assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
144-
145- setContextSpy . restore ( )
139+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , true )
146140 } )
147141
148142 it ( 'can fetch and store emergency notifications' , async function ( ) {
149- const setContextSpy = sinon . spy ( setContext , 'setContext' )
150-
151143 const eTag = randomUUID ( )
152144 const content = {
153145 schemaVersion : '1.x' ,
@@ -176,14 +168,10 @@ describe('Notifications Controller', function () {
176168 assert . deepStrictEqual ( panelNode . emergencyNotifications , [ content . notifications [ 0 ] ] )
177169 assert . equal ( panelNode . getChildren ( ) . length , 1 )
178170 assert . equal ( focusPanelSpy . callCount , 1 )
179- assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
180-
181- setContextSpy . restore ( )
171+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , true )
182172 } )
183173
184174 it ( 'can fetch and store both startup and emergency notifications' , async function ( ) {
185- const setContextSpy = sinon . spy ( setContext , 'setContext' )
186-
187175 const eTag1 = randomUUID ( )
188176 const eTag2 = randomUUID ( )
189177 const startUpContent = {
@@ -239,14 +227,10 @@ describe('Notifications Controller', function () {
239227 assert . deepStrictEqual ( panelNode . emergencyNotifications , [ emergencyContent . notifications [ 0 ] ] )
240228 assert . equal ( panelNode . getChildren ( ) . length , 2 )
241229 assert . equal ( focusPanelSpy . callCount , 1 )
242- assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
243-
244- setContextSpy . restore ( )
230+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , true )
245231 } )
246232
247233 it ( 'dismisses a startup notification' , async function ( ) {
248- const setContextSpy = sinon . spy ( setContext , 'setContext' )
249-
250234 const eTag = randomUUID ( )
251235 const content = {
252236 schemaVersion : '1.x' ,
@@ -261,7 +245,7 @@ describe('Notifications Controller', function () {
261245
262246 assert . equal ( panelNode . getChildren ( ) . length , 2 )
263247 assert . equal ( panelNode . startUpNotifications . length , 2 )
264- assert . ok ( setContextSpy . calledWithExactly ( 'aws.toolkit.notifications.show' , true ) )
248+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , true )
265249
266250 assert . deepStrictEqual ( await globals . globalState . get ( controller . storageKey ) , {
267251 startUp : {
@@ -288,13 +272,9 @@ describe('Notifications Controller', function () {
288272
289273 assert . equal ( panelNode . getChildren ( ) . length , 1 )
290274 assert . equal ( panelNode . startUpNotifications . length , 1 )
291-
292- setContextSpy . restore ( )
293275 } )
294276
295277 it ( 'does not redisplay dismissed notifications' , async function ( ) {
296- const setContextSpy = sinon . spy ( setContext , 'setContext' )
297-
298278 const content = {
299279 schemaVersion : '1.x' ,
300280 notifications : [ getValidTestNotification ( 'id:startup1' ) ] ,
@@ -306,11 +286,11 @@ describe('Notifications Controller', function () {
306286
307287 await controller . pollForStartUp ( ruleEngine )
308288 assert . equal ( panelNode . getChildren ( ) . length , 1 )
309- assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
289+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , true )
310290
311291 await dismissNotification ( content . notifications [ 0 ] )
312292 assert . equal ( panelNode . getChildren ( ) . length , 0 )
313- assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , false ] )
293+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , false )
314294
315295 content . notifications . push ( getValidTestNotification ( 'id:startup2' ) )
316296 fetcher . setStartUpContent ( {
@@ -332,9 +312,7 @@ describe('Notifications Controller', function () {
332312 } )
333313
334314 assert . equal ( panelNode . getChildren ( ) . length , 1 )
335- assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
336-
337- setContextSpy . restore ( )
315+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , true )
338316 } )
339317
340318 it ( 'does not refocus emergency notifications' , async function ( ) {
@@ -406,8 +384,6 @@ describe('Notifications Controller', function () {
406384 } )
407385
408386 it ( 'cleans out dismissed state' , async function ( ) {
409- const setContextSpy = sinon . spy ( setContext , 'setContext' )
410-
411387 const startUpContent = {
412388 schemaVersion : '1.x' ,
413389 notifications : [ getValidTestNotification ( 'id:startup1' ) ] ,
@@ -466,7 +442,7 @@ describe('Notifications Controller', function () {
466442 newlyReceived : [ ] ,
467443 } )
468444 assert . equal ( panelNode . getChildren ( ) . length , 1 )
469- assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , true ] )
445+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , true )
470446
471447 fetcher . setEmergencyContent ( {
472448 eTag : '1' ,
@@ -488,9 +464,7 @@ describe('Notifications Controller', function () {
488464 } )
489465
490466 assert . equal ( panelNode . getChildren ( ) . length , 0 )
491- assert . deepStrictEqual ( setContextSpy . lastCall . args , [ 'aws.toolkit.notifications.show' , false ] )
492-
493- setContextSpy . restore ( )
467+ assert . equal ( getContext ( 'aws.toolkit.notifications.show' ) , false )
494468 } )
495469
496470 it ( 'does not rethrow errors when fetching' , async function ( ) {
0 commit comments