import * as sinon from 'sinon' ; import { TestUtil } from '../../TestUtil' ; import { LocalEnvironment } from '../../../extension/fabric/environments/LocalEnvironment' ; import { CommandUtil } from '../../../extension/util/CommandUtil' ; describe ( 'LocalEnvironment' , ( ) => { let sendCommandWithOutputStub ; let sandbox ; before ( async ( ) => { await TestUtil . setupTests ( sandbox ) ; } ) ; beforeEach ( async ( ) => { sandbox = sinon . createSandbox ( ) ; sendCommandWithOutputStub = sandbox . stub ( CommandUtil , 'sendCommandWithOutput' ) ; sendCommandWithOutputStub . resolves ( ) ; } ) ; afterEach ( async ( ) => { sandbox . restore ( ) ; } ) ; it ( 'should teardown (windows)' , async ( ) => { const enviroment = new LocalEnvironment ( 'localenvironment' , 'somepath' ) ; sandbox . stub ( process , 'platform' ) . value ( 'win32' ) ; await enviroment . teardown ( ) ; sendCommandWithOutputStub . should . have . been . calledOnceWithExactly ( 'cmd' , [ '/c' , `teardown.cmd` ] , 'somepath' ) ; } ) ; it ( 'should teardown (mac)' , async ( ) => { const enviroment = new LocalEnvironment ( 'localenvironment' , 'somepath' ) ; sandbox . stub ( process , 'platform' ) . value ( 'darwin' ) ; await enviroment . teardown ( ) ; sendCommandWithOutputStub . should . have . been . calledOnceWithExactly ( '/bin/sh' , [ `teardown.sh` ] , 'somepath' ) ; } ) ; it ( 'should teardown (linux)' , async ( ) => { const enviroment = new LocalEnvironment ( 'localenvironment' , 'somepath' ) ; sandbox . stub ( process , 'platform' ) . value ( 'linux' ) ; await enviroment . teardown ( ) ; sendCommandWithOutputStub . should . have . been . calledOnceWithExactly ( '/bin/sh' , [ `teardown.sh` ] , 'somepath' ) ; } ) ; it ( `should do nothing if there's an error on teardown` , async ( ) => { const enviroment = new LocalEnvironment ( 'localenvironment' , 'somepath' ) ; sandbox . stub ( process , 'platform' ) . value ( 'linux' ) ; const error = new Error ( 'some error' ) ; sendCommandWithOutputStub . rejects ( error ) ; await enviroment . teardown ( ) ; sendCommandWithOutputStub . should . have . been . calledOnceWithExactly ( '/bin/sh' , [ `teardown.sh` ] , 'somepath' ) ; } ) ; } ) ;