import * as sinon from 'sinon' ; import * as vscode from 'vscode' ; import { forceLightningLwcStop } from '../../../src/commands/forceLightningLwcStop' ; import { DevServerService } from '../../../src/service/devServerService' ; import { nls } from '../../../src/messages' ; import { ChannelService , notificationService } from '@salesforce/salesforcedx-utils-vscode/out/src/commands' ; describe ( 'forceLightningLwcStop' , ( ) => { let sandbox ; let devService ; let appendLineStub ; let notificationServiceStubs ; beforeEach ( ( ) => { sandbox = sinon . createSandbox ( ) ; devService = new DevServerService ( ) ; sandbox . stub ( DevServerService , 'instance' ) . get ( ( ) => devService ) ; notificationServiceStubs = { } ; appendLineStub = sandbox . stub ( ChannelService . prototype , 'appendLine' as any ) ; notificationServiceStubs . showSuccessfulExecutionStub = sandbox . stub ( notificationService , 'showSuccessfulExecution' ) . returns ( Promise . resolve ( ) ) ; notificationServiceStubs . showErrorMessageStub = sandbox . stub ( notificationService , 'showErrorMessage' ) ; } ) ; afterEach ( ( ) => { sandbox . restore ( ) ; } ) ; it ( 'calls stopServer when a server is already running' , async ( ) => { const stopStub = sinon . stub ( ) ; devService . registerServerHandler ( { stop : stopStub } ) ; await forceLightningLwcStop ( ) ; sinon . assert . calledOnce ( stopStub ) ; } ) ; it ( 'shows successful server stop' , async ( ) => { let devServiceStub = sinon . createStubInstance ( DevServerService ) ; devServiceStub . isServerHandlerRegistered . returns ( true ) ; sandbox . stub ( DevServerService , 'instance' ) . get ( ( ) => devServiceStub ) ; await forceLightningLwcStop ( ) ; sinon . assert . notCalled ( notificationServiceStubs . showErrorMessageStub ) ; sinon . assert . calledOnce ( appendLineStub ) ; sinon . assert . calledWith ( appendLineStub , sinon . match ( nls . localize ( 'force_lightning_lwc_stop_in_progress' ) ) ) ; sinon . assert . calledOnce ( notificationServiceStubs . showSuccessfulExecutionStub ) ; sinon . assert . calledWith ( notificationServiceStubs . showSuccessfulExecutionStub , sinon . match ( nls . localize ( 'force_lightning_lwc_stop_text' ) ) ) ; } ) ; } ) ;