import { expect } from 'chai' ; import { Notification , NotificationType , VSBrowser , Workbench } from 'vscode-extension-tester' ; describe ( 'Sample notifications tests' , ( ) => { beforeEach ( async ( ) => { await new Workbench ( ) . executeCommand ( 'hello world' ) ; await VSBrowser . instance . driver . wait ( ( ) => { return notificationExists ( 'Hello' ) ; } , 2000 ) as Notification ; } ) ; it ( 'Standalone notifications' , async ( ) => { const notifications = await new Workbench ( ) . getNotifications ( ) ; let notification ! ; for ( const not of notifications ) { const message = await not . getMessage ( ) ; if ( message . includes ( 'Hello' ) ) { notification = not ; } } expect ( await notification . getText ( ) ) . equals ( 'Hello World!' ) ; expect ( await notification . getSource ( ) ) . has . string ( 'helloworld-sample' ) ; expect ( await notification . getType ( ) ) . equals ( NotificationType . Info ) ; await notification . dismiss ( ) ; } ) ; it ( 'Notifications Center' , async ( ) => { const center = await new Workbench ( ) . openNotificationsCenter ( ) ; const notifications = await center . getNotifications ( NotificationType . Info ) ; let notification ! ; for ( const not of notifications ) { const message = await not . getMessage ( ) ; if ( message . includes ( 'Hello' ) ) { notification = not ; } } expect ( await notification . getText ( ) ) . equals ( 'Hello World!' ) ; expect ( await notification . getSource ( ) ) . has . string ( 'helloworld-sample' ) ; expect ( await notification . getType ( ) ) . equals ( NotificationType . Info ) ; await center . clearAllNotifications ( ) ; } ) ; } ) ; /**
 * Example wait condition for WebDriver. Wait for a notification with given text to appear.
 * Wait conditions resolve when the first truthy value is returned.
 * In this case we choose to return the first matching notification object we find,
 * or undefined if no such notification is found.
 */ async function notificationExists ( text ) { const notifications = await new Workbench ( ) . getNotifications ( ) ; for ( const notification of notifications ) { const message = await notification . getMessage ( ) ; if ( message . indexOf ( text ) >= 0 ) { return notification ; } } }