import * as vscode from 'vscode' ; import * as myExtension from '../extension/extension' ; import * as chai from 'chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import * as sinon from 'sinon' ; import * as sinonChai from 'sinon-chai' ; import * as path from 'path' ; import { version as currentExtensionVersion } from '../package.json' ; import { ExtensionUtil } from '../extension/util/ExtensionUtil' ; import { DependencyManager } from '../extension/dependencies/DependencyManager' ; import { VSCodeBlockchainOutputAdapter } from '../extension/logging/VSCodeBlockchainOutputAdapter' ; import { TemporaryCommandRegistry } from '../extension/dependencies/TemporaryCommandRegistry' ; import { TestUtil } from './TestUtil' ; import { Reporter } from '../extension/util/Reporter' ; import { ExtensionCommands } from '../ExtensionCommands' ; import { LogType , FabricGatewayRegistry , FabricGatewayRegistryEntry , FabricEnvironmentRegistry , FabricEnvironmentRegistryEntry , EnvironmentType , EnvironmentFlags , FabricRuntimeUtil } from 'ibm-blockchain-platform-common' ; import { SettingConfigurations } from '../extension/configurations' ; import { UserInputUtil } from '../extension/commands/UserInputUtil' ; import { dependencies } from '../package.json' ; import { GlobalState , DEFAULT_EXTENSION_DATA , ExtensionData } from '../extension/util/GlobalState' ; import { BlockchainGatewayExplorerProvider } from '../extension/explorer/gatewayExplorer' ; import { BlockchainEnvironmentExplorerProvider } from '../extension/explorer/environmentExplorer' ; import { BlockchainWalletExplorerProvider } from '../extension/explorer/walletExplorer' ; import { LocalMicroEnvironmentManager } from '../extension/fabric/environments/LocalMicroEnvironmentManager' ; chai . use ( sinonChai ) ; chai . use ( chaiAsPromised ) ; describe ( 'Extension Tests' , ( ) => { const mySandBox = sinon . createSandbox ( ) ; let sendTelemetryStub ; let getPackageJSONStub ; let reporterDisposeStub ; let logSpy ; let setupCommandsStub ; let completeActivationStub ; let setExtensionContextStub ; let hasPreReqsInstalledStub ; let registerPreActivationCommandsStub ; let createTempCommandsStub ; let showConfirmationWarningMessageStub ; before ( async ( ) => { await TestUtil . setupTests ( mySandBox ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . HOME_SHOW_ON_STARTUP , false , vscode . ConfigurationTarget . Global ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . HOME_SHOW_ON_NEXT_ACTIVATION , false , vscode . ConfigurationTarget . Global ) ; } ) ; beforeEach ( async ( ) => { mySandBox . restore ( ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . dockerForWindows = true ; await GlobalState . update ( extensionData ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . FABRIC_RUNTIME , { } , vscode . ConfigurationTarget . Global ) ; sendTelemetryStub = mySandBox . stub ( Reporter . instance ( ) , 'sendTelemetryEvent' ) . resolves ( ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , false , vscode . ConfigurationTarget . Global ) ; reporterDisposeStub = mySandBox . stub ( Reporter . instance ( ) , 'dispose' ) ; getPackageJSONStub = mySandBox . stub ( ExtensionUtil , 'getPackageJSON' ) . returns ( { production : true } ) ; logSpy = mySandBox . spy ( VSCodeBlockchainOutputAdapter . instance ( ) , 'log' ) ; setupCommandsStub = mySandBox . stub ( ExtensionUtil , 'setupCommands' ) ; completeActivationStub = mySandBox . stub ( ExtensionUtil , 'completeActivation' ) ; setExtensionContextStub = mySandBox . stub ( GlobalState , 'setExtensionContext' ) ; hasPreReqsInstalledStub = mySandBox . stub ( DependencyManager . instance ( ) , 'hasPreReqsInstalled' ) ; registerPreActivationCommandsStub = mySandBox . stub ( ExtensionUtil , 'registerPreActivationCommands' ) ; createTempCommandsStub = mySandBox . stub ( TemporaryCommandRegistry . instance ( ) , 'createTempCommands' ) ; showConfirmationWarningMessageStub = mySandBox . stub ( UserInputUtil , 'showConfirmationWarningMessage' ) . withArgs ( `Detected old local environments which can not be used with this upgrade. Would you like to teardown these environments?` ) . resolves ( false ) ; } ) ; afterEach ( async ( ) => { await GlobalState . reset ( ) ; mySandBox . restore ( ) ; } ) ; describe ( 'activate' , ( ) => { it ( 'should refresh the tree when a gateway connection is added' , async ( ) => { await FabricGatewayRegistry . instance ( ) . clear ( ) ; const treeDataProvider = ExtensionUtil . getBlockchainGatewayExplorerProvider ( ) ; const treeSpy = mySandBox . spy ( treeDataProvider [ '_onDidChangeTreeData' ] , 'fire' ) ; const gateway = new FabricGatewayRegistryEntry ( { name : 'myGateway' , associatedWallet : '' , connectionProfilePath : path . join ( 'blockchain' , 'extension' , 'directory' , 'gatewayOne' , 'connection.json' ) } ) ; await FabricGatewayRegistry . instance ( ) . add ( gateway ) ; treeSpy . should . have . been . called ; } ) ; it ( 'should refresh all the trees when a environment connection is added' , async ( ) => { await FabricEnvironmentRegistry . instance ( ) . clear ( ) ; const gatewayTreeDataProvider = ExtensionUtil . getBlockchainGatewayExplorerProvider ( ) ; const gatewayTreeSpy = mySandBox . spy ( gatewayTreeDataProvider [ '_onDidChangeTreeData' ] , 'fire' ) ; const environmentTreeDataProvider = ExtensionUtil . getBlockchainEnvironmentExplorerProvider ( ) ; const environmentTreeSpy = mySandBox . spy ( environmentTreeDataProvider [ '_onDidChangeTreeData' ] , 'fire' ) ; const walletTreeDataProvider = ExtensionUtil . getBlockchainWalletExplorerProvider ( ) ; const walletTreeSpy = mySandBox . spy ( walletTreeDataProvider [ '_onDidChangeTreeData' ] , 'fire' ) ; const environment = new FabricEnvironmentRegistryEntry ( { name : 'myEnvironment' , environmentType : EnvironmentType . ENVIRONMENT } ) ; await FabricEnvironmentRegistry . instance ( ) . add ( environment ) ; environmentTreeSpy . should . have . been . called ; gatewayTreeSpy . should . have . been . called ; walletTreeSpy . should . have . been . called ; } ) ; it ( 'should activate if required dependencies are installed and prereq page has been shown before' , async ( ) => { setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; hasPreReqsInstalledStub . resolves ( true ) ; const executeCommandSpy = mySandBox . spy ( vscode . commands , 'executeCommand' ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = currentExtensionVersion ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandSpy . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; completeActivationStub . should . have . been . called ; } ) ; it ( 'should dispose of the reporter instance production flag is false on extension activiation' , async ( ) => { getPackageJSONStub . returns ( { production : false } ) ; reporterDisposeStub . resolves ( ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; hasPreReqsInstalledStub . resolves ( true ) ; const executeCommandSpy = mySandBox . spy ( vscode . commands , 'executeCommand' ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . migrationCheck = 2 ; extensionData . version = currentExtensionVersion ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandSpy . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; completeActivationStub . should . have . been . called ; reporterDisposeStub . should . have . been . called ; } ) ; it ( 'should open prereq page if not shown before' , async ( ) => { setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const updateGlobalStateSpy = mySandBox . spy ( GlobalState , 'update' ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = false ; extensionData . dockerForWindows = true ; extensionData . version = currentExtensionVersion ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; const preReqPageShown = updateGlobalStateSpy . getCalls ( ) [ 1 ] . args [ 0 ] . preReqPageShown ; preReqPageShown . should . equal ( true ) ; completeActivationStub . should . have . been . calledOnce ; } ) ; it ( 'should open prereq page if required dependencies aren\'t installed' , async ( ) => { setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( false ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = currentExtensionVersion ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( false , ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; setupCommandsStub . should . not . have . been . called ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; completeActivationStub . should . not . have . been . called ; } ) ; it ( 'should activate if the extension has been updated' , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '2.0.0-beta.9' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . have . been . calledWith ( 'markdown.showPreview' , releaseNotesUri ) ; completeActivationStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; } ) ; it ( `should delete any local environments or ansible environments` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . DELETE_ENVIRONMENT ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '2.0.0-beta.9' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; const oldOtherEntry = new FabricEnvironmentRegistryEntry ( { name : 'oldlocal' , environmentType : EnvironmentType . LOCAL_ENVIRONMENT , numberOfOrgs : 1 } ) ; const ansibleEntry = new FabricEnvironmentRegistryEntry ( { name : 'oldAnsible' , environmentType : EnvironmentType . ANSIBLE_ENVIRONMENT , environmentDirectory : '/some/path' } ) ; const getAllEnvironmentsStub = mySandBox . stub ( FabricEnvironmentRegistry . instance ( ) , 'getAll' ) ; getAllEnvironmentsStub . resolves ( [ oldOtherEntry , ansibleEntry ] ) ; const initializeStub = mySandBox . stub ( LocalMicroEnvironmentManager . instance ( ) , 'initialize' ) . resolves ( ) ; await myExtension . activate ( context ) ; getAllEnvironmentsStub . should . have . been . calledOnceWithExactly ( [ EnvironmentFlags . ANSIBLE ] ) ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT , oldOtherEntry , true ) ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT , ansibleEntry , true ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; initializeStub . should . not . have . been . called ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . have . been . calledWith ( 'markdown.showPreview' , releaseNotesUri ) ; completeActivationStub . should . have . been . calledOnce ; } ) ; it ( `should delete any local environments and start a new ${ FabricRuntimeUtil . LOCAL_FABRIC } if an older version existed` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . DELETE_ENVIRONMENT ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '2.0.0-beta.9' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; const oldOneOrgEntry = new FabricEnvironmentRegistryEntry ( { name : FabricRuntimeUtil . LOCAL_FABRIC , environmentType : EnvironmentType . LOCAL_ENVIRONMENT , numberOfOrgs : 1 } ) ; const oldOtherEntry = new FabricEnvironmentRegistryEntry ( { name : 'oldlocal' , environmentType : EnvironmentType . LOCAL_ENVIRONMENT , numberOfOrgs : 1 } ) ; const getAllEnvironmentsStub = mySandBox . stub ( FabricEnvironmentRegistry . instance ( ) , 'getAll' ) ; getAllEnvironmentsStub . resolves ( [ oldOneOrgEntry , oldOtherEntry ] ) ; const initializeStub = mySandBox . stub ( LocalMicroEnvironmentManager . instance ( ) , 'initialize' ) . resolves ( ) ; await myExtension . activate ( context ) ; getAllEnvironmentsStub . should . have . been . calledOnceWithExactly ( [ EnvironmentFlags . ANSIBLE ] ) ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT , oldOneOrgEntry , true ) ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT , oldOtherEntry , true ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; initializeStub . should . have . been . calledOnceWithExactly ( FabricRuntimeUtil . LOCAL_FABRIC , 1 ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . have . been . calledWith ( 'markdown.showPreview' , releaseNotesUri ) ; completeActivationStub . should . have . been . calledOnce ; } ) ; it ( 'should remove any old settings' , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . DELETE_ENVIRONMENT ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '2.0.0-beta.9' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; const oldOneOrgEntry = new FabricEnvironmentRegistryEntry ( { name : FabricRuntimeUtil . LOCAL_FABRIC , environmentType : EnvironmentType . LOCAL_ENVIRONMENT , numberOfOrgs : 1 } ) ; const oldOtherEntry = new FabricEnvironmentRegistryEntry ( { name : 'oldlocal' , environmentType : EnvironmentType . LOCAL_ENVIRONMENT , numberOfOrgs : 1 } ) ; const getAllEnvironmentsStub = mySandBox . stub ( FabricEnvironmentRegistry . instance ( ) , 'getAll' ) ; getAllEnvironmentsStub . resolves ( [ oldOneOrgEntry , oldOtherEntry ] ) ; const initializeStub = mySandBox . stub ( LocalMicroEnvironmentManager . instance ( ) , 'initialize' ) . resolves ( ) ; const originalSettings = vscode . workspace . getConfiguration ( ) . get ( SettingConfigurations . FABRIC_RUNTIME , vscode . ConfigurationTarget . Global ) ; const newSettings = Object . assign ( { otherLocal : { startPort : 1000 , endPort : 2000 } , anotherLocal : { startPort : 3000 , endPort : 4000 } , microfabLocal : 9001 } , originalSettings ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . FABRIC_RUNTIME , newSettings , vscode . ConfigurationTarget . Global ) ; await myExtension . activate ( context ) ; const finalSettings = vscode . workspace . getConfiguration ( ) . get ( SettingConfigurations . FABRIC_RUNTIME , vscode . ConfigurationTarget . Global ) ; finalSettings . should . deep . equal ( { microfabLocal : 9001 } ) ; getAllEnvironmentsStub . should . have . been . calledOnceWithExactly ( [ EnvironmentFlags . ANSIBLE ] ) ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT , oldOneOrgEntry , true ) ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT , oldOtherEntry , true ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; initializeStub . should . have . been . calledOnceWithExactly ( FabricRuntimeUtil . LOCAL_FABRIC , 1 ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . have . been . calledWith ( 'markdown.showPreview' , releaseNotesUri ) ; completeActivationStub . should . have . been . calledOnce ; } ) ; it ( 'should set global state properties if a previous version has been used' , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = undefined ; extensionData . deletedOneOrgLocalFabric = undefined ; await GlobalState . update ( extensionData ) ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( undefined ) ; await myExtension . activate ( context ) ; const newExtData = GlobalState . get ( ) ; newExtData . createOneOrgLocalFabric . should . equal ( true ) ; newExtData . deletedOneOrgLocalFabric . should . equal ( false ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . have . been . calledWith ( 'markdown.showPreview' , releaseNotesUri ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; completeActivationStub . should . have . been . calledOnce ; } ) ; it ( 'should not open release notes on first ever install' , async ( ) => { setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandSpy = mySandBox . spy ( vscode . commands , 'executeCommand' ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = null ; extensionData . generatorVersion = null ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'newInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandSpy . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandSpy . should . not . have . been . calledWith ( 'markdown.showPreview' ) ; completeActivationStub . should . have . been . calledOnce ; } ) ; it ( `should report that the release notes can't be opened` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; const error = new Error ( 'unable to preview markdown' ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . throws ( error ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( undefined ) ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; logSpy . should . have . been . calledWith ( LogType . ERROR , `Unable to open release notes: ${ error . toString ( ) }` ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . have . been . calledOnce ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . have . been . calledWith ( 'markdown.showPreview' , releaseNotesUri ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; completeActivationStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( 'should activate extension and bypass prereqs' , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( undefined ) ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . not . have . been . called ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; completeActivationStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( `should open 'whats new page' when major extension version has been updated and user selects 'Read more'` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( 'Learn more' ) ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . not . have . been . called ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; completeActivationStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( 'should report if a new user has installed the extension' , async ( ) => { setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = null ; extensionData . generatorVersion = null ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'newInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; hasPreReqsInstalledStub . should . have . been . calledOnce ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; completeActivationStub . should . have . been . calledOnce ; } ) ; it ( 'should handle any errors when the extension fails to activate' , async ( ) => { const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = currentExtensionVersion ; extensionData . generatorVersion = '1.0.6' ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( undefined ) ; await GlobalState . update ( extensionData ) ; const error = new Error ( 'some error' ) ; hasPreReqsInstalledStub . rejects ( error ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; const failedActivationWindowStub = mySandBox . stub ( UserInputUtil , 'failedActivationWindow' ) . resolves ( ) ; await myExtension . activate ( context ) ; setExtensionContextStub . should . have . been . calledOnce ; hasPreReqsInstalledStub . should . have . been . called ; failedActivationWindowStub . should . have . been . calledOnceWithExactly ( 'some error' ) ; sendTelemetryStub . should . have . been . calledWith ( 'activationFailed' , { activationError : 'some error' } ) ; logSpy . should . have . been . calledWith ( LogType . ERROR , undefined , `Failed to activate extension: ${ error . toString ( ) }` , error . stack ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; showInformationMessageStub . should . not . have . been . called ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( 'should add home page button to the status bar' , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; await GlobalState . update ( extensionData ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( undefined ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; setExtensionContextStub . should . have . been . calledTwice ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; completeActivationStub . should . have . been . calledOnce ; const newContext = GlobalState . getExtensionContext ( ) ; const homePageButton = newContext . subscriptions . find ( ( subscription ) => { return subscription . text === 'Blockchain Home' ; } ) ; homePageButton . tooltip . should . equal ( 'View Homepage' ) ; homePageButton . command . should . equal ( ExtensionCommands . OPEN_HOME_PAGE ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( `should ask user if they want to teardown old (v1 extension) local ansible environments if present when major extension version has been updated` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; const v1AnsibleLocal = new FabricEnvironmentRegistryEntry ( { name : 'v1Ansible' , environmentType : EnvironmentType . MANAGED , environmentDirectory : '/some/path' } ) ; const getAllEnvironmentsStub = mySandBox . stub ( FabricEnvironmentRegistry . instance ( ) , 'getAll' ) ; getAllEnvironmentsStub . onFirstCall ( ) . resolves ( [ v1AnsibleLocal ] ) ; getAllEnvironmentsStub . onSecondCall ( ) . resolves ( [ ] ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , v1AnsibleLocal . name , true ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( 'Learn more' ) ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; showConfirmationWarningMessageStub . should . have . been . calledOnce ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . not . have . been . called ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , v1AnsibleLocal . name , true ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; completeActivationStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( `should teardown old v1 ansible local environments if present and user agrees when major extension version has been updated` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; const v1AnsibleLocal = new FabricEnvironmentRegistryEntry ( { name : 'v1Ansible' , environmentType : EnvironmentType . MANAGED , environmentDirectory : '/some/path' } ) ; const getAllEnvironmentsStub = mySandBox . stub ( FabricEnvironmentRegistry . instance ( ) , 'getAll' ) ; getAllEnvironmentsStub . onFirstCall ( ) . resolves ( [ v1AnsibleLocal ] ) ; getAllEnvironmentsStub . onSecondCall ( ) . resolves ( [ ] ) ; showConfirmationWarningMessageStub . resolves ( true ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , v1AnsibleLocal . name , true ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( 'Learn more' ) ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , `Successful teardown of ${ v1AnsibleLocal . name } environment.` ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; showConfirmationWarningMessageStub . should . have . been . calledOnce ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . not . have . been . called ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , v1AnsibleLocal . name , true ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; completeActivationStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( `should log error if teardown of old v1 ansible local environments fails when major extension version has been updated` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; const v1AnsibleLocal = new FabricEnvironmentRegistryEntry ( { name : 'v1Ansible' , environmentType : EnvironmentType . MANAGED , environmentDirectory : '/some/path' } ) ; const getAllEnvironmentsStub = mySandBox . stub ( FabricEnvironmentRegistry . instance ( ) , 'getAll' ) ; getAllEnvironmentsStub . onFirstCall ( ) . resolves ( [ v1AnsibleLocal ] ) ; getAllEnvironmentsStub . onSecondCall ( ) . resolves ( [ ] ) ; showConfirmationWarningMessageStub . resolves ( true ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , v1AnsibleLocal . name , true ) . rejects ( 'some error' ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( 'Learn more' ) ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . ERROR , undefined , `Unable to teardown ${ v1AnsibleLocal . name } environment: some error.` ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; showConfirmationWarningMessageStub . should . have . been . calledOnce ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . not . have . been . called ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , v1AnsibleLocal . name , true ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; completeActivationStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; it ( `should not ask user if they want to teardown old (v1 extension) local ansible environments if none present when major extension version has been updated` , async ( ) => { const releaseNotesPath = path . join ( ExtensionUtil . getExtensionPath ( ) , 'RELEASE-NOTES.md' ) ; const releaseNotesUri = vscode . Uri . file ( releaseNotesPath ) ; const v1OpsTools = new FabricEnvironmentRegistryEntry ( { name : 'v1Ansible' , environmentType : 3 as EnvironmentType , environmentDirectory : '/some/path' } ) ; const getAllEnvironmentsStub = mySandBox . stub ( FabricEnvironmentRegistry . instance ( ) , 'getAll' ) ; getAllEnvironmentsStub . onFirstCall ( ) . resolves ( [ v1OpsTools ] ) ; getAllEnvironmentsStub . onSecondCall ( ) . resolves ( [ ] ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; setupCommandsStub . resolves ( ) ; completeActivationStub . resolves ( ) ; const context = GlobalState . getExtensionContext ( ) ; setExtensionContextStub . returns ( undefined ) ; const executeCommandStub = mySandBox . stub ( vscode . commands , 'executeCommand' ) ; executeCommandStub . callThrough ( ) ; executeCommandStub . withArgs ( 'markdown.showPreview' , releaseNotesUri ) . resolves ( ) ; executeCommandStub . withArgs ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) . resolves ( ) ; hasPreReqsInstalledStub . resolves ( true ) ; registerPreActivationCommandsStub . resolves ( context ) ; createTempCommandsStub . returns ( undefined ) ; const extensionData = DEFAULT_EXTENSION_DATA ; extensionData . preReqPageShown = true ; extensionData . dockerForWindows = true ; extensionData . version = '1.0.6' ; extensionData . generatorVersion = dependencies [ 'generator-fabric' ] ; extensionData . migrationCheck = 2 ; extensionData . createOneOrgLocalFabric = true ; extensionData . deletedOneOrgLocalFabric = false ; const showInformationMessageStub = mySandBox . stub ( vscode . window , 'showInformationMessage' ) . resolves ( 'Learn more' ) ; await GlobalState . update ( extensionData ) ; await myExtension . activate ( context ) ; sendTelemetryStub . should . have . been . calledWith ( 'updatedInstall' , { IBM : sinon . match . string } ) ; logSpy . should . have . been . calledWith ( LogType . IMPORTANT , undefined , 'Log files can be found by running the `Developer: Open Logs Folder` command from the palette' , undefined , true ) ; logSpy . should . have . been . calledWith ( LogType . INFO , undefined , 'Starting IBM Blockchain Platform Extension' ) ; showConfirmationWarningMessageStub . should . have . not . been . calledOnce ; setExtensionContextStub . should . have . been . calledTwice ; hasPreReqsInstalledStub . should . not . have . been . called ; createTempCommandsStub . should . have . been . calledOnceWith ( true ) ; setupCommandsStub . should . have . been . calledOnce ; registerPreActivationCommandsStub . should . have . been . calledOnce ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , v1OpsTools . name , true ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . OPEN_PRE_REQ_PAGE ) ; executeCommandStub . should . not . have . been . calledWith ( ExtensionCommands . DELETE_ENVIRONMENT ) ; completeActivationStub . should . have . been . calledOnce ; showInformationMessageStub . should . have . been . calledOnce ; executeCommandStub . should . have . been . calledWith ( ExtensionCommands . OPEN_FABRIC_2_PAGE ) ; } ) ; } ) ; describe ( 'deactivate' , ( ) => { it ( 'should deactivate extension' , async ( ) => { const context = GlobalState . getExtensionContext ( ) ; const getExtensionContextStub = mySandBox . stub ( GlobalState , 'getExtensionContext' ) . returns ( context ) ; const disposeExtensionStub = mySandBox . stub ( ExtensionUtil , 'disposeExtension' ) . returns ( undefined ) ; await myExtension . deactivate ( ) ; getExtensionContextStub . should . have . been . calledOnce ; reporterDisposeStub . should . have . been . calledOnce ; disposeExtensionStub . should . have . been . calledOnceWithExactly ( context ) ; } ) ; } ) ; describe ( 'txdata files' , ( ) => { it ( 'should associate .txdata files with JSON language' , async ( ) => { getPackageJSONStub . callThrough ( ) ; const packageJSON = ExtensionUtil . getPackageJSON ( ) ; const languages = packageJSON . contributes . languages ; languages . should . deep . equal ( [ { id : 'json' , extensions : [ '.txdata' ] } ] ) ; } ) ; it ( 'should associate a schema with .txdata files for validation' , async ( ) => { getPackageJSONStub . callThrough ( ) ; const packageJSON = ExtensionUtil . getPackageJSON ( ) ; const jsonValidation = packageJSON . contributes . jsonValidation ; jsonValidation . should . deep . equal ( [ { fileMatch : '*.txdata' , url : './txdata.schema.json' } ] ) ; } ) ; } ) ; } ) ;