'use strict' ; import * as vscode from 'vscode' ; import * as chai from 'chai' ; import * as sinon from 'sinon' ; import * as sinonChai from 'sinon-chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import * as path from 'path' ; import * as fs from 'fs-extra' ; import { ExtensionCommands } from '../../ExtensionCommands' ; import { TestUtil } from '../../test/TestUtil' ; import { VSCodeBlockchainOutputAdapter } from '../../extension/logging/VSCodeBlockchainOutputAdapter' ; import { SettingConfigurations } from '../../extension/configurations' ; import { UserInputUtilHelper } from '../helpers/userInputUtilHelper' ; import { SmartContractHelper } from '../helpers/smartContractHelper' ; import { GeneratedTestsHelper } from '../helpers/generatedTestsHelper' ; import { WalletAndIdentityHelper } from '../helpers/walletAndIdentityHelper' ; import { GatewayHelper } from '../helpers/gatewayHelper' ; import { EnvironmentHelper } from '../helpers/environmentHelper' ; import { SampleHelper } from '../helpers/sampleHelper' ; import { FabricRuntimeUtil , LogType } from 'ibm-blockchain-platform-common' ; import { ModuleUtilHelper } from '../helpers/moduleUtilHelper' ; import { TimerUtil } from '../../extension/util/TimerUtil' ; import { ExtensionUtil } from '../../extension/util/ExtensionUtil' ; import { ExtensionsInteractionUtilHelper } from '../helpers/extensionsInteractionUtilHelper' ; chai . use ( sinonChai ) ; chai . use ( chaiAsPromised ) ; export enum LanguageType { CHAINCODE = 'chaincode' , CONTRACT = 'contract' } let firstTime = true ; module . exports = function ( ) : any { this . timeout = { timeout : 120000 * 1000 } ; this . cucumberDir = path . join ( __dirname , '..' , '..' , '..' , 'cucumber' ) ; this . Before ( this . timeout , async ( ) => { if ( firstTime ) { await TestUtil . storeRuntimesConfig ( ) ; await TestUtil . storeExtensionDirectoryConfig ( ) ; const extDir = path . join ( __dirname , '..' , '..' , '..' , 'cucumber' , 'tmp' ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_DIRECTORY , extDir , vscode . ConfigurationTarget . Global ) ; this . mySandBox = sinon . createSandbox ( ) ; this . userInputUtilHelper = new UserInputUtilHelper ( this . mySandBox ) ; this . moduleUtilHelper = new ModuleUtilHelper ( this . mySandBox ) ; this . smartContractHelper = new SmartContractHelper ( this . mySandBox , this . userInputUtilHelper ) ; this . generatedTestsHelper = new GeneratedTestsHelper ( this . mySandBox , this . userInputUtilHelper , this . smartContractHelper ) ; this . walletAndIdentityHelper = new WalletAndIdentityHelper ( this . mySandBox , this . userInputUtilHelper ) ; this . gatewayHelper = new GatewayHelper ( this . mySandBox , this . userInputUtilHelper ) ; this . extensionsInteractionUtilHelper = new ExtensionsInteractionUtilHelper ( this . mySandBox ) ; this . fabricEnvironmentHelper = new EnvironmentHelper ( this . mySandbox , this . userInputUtilHelper , this . moduleUtilHelper , this . extensionsInteractionUtilHelper ) ; this . sampleHelper = new SampleHelper ( this . mySandBox , this . userInputUtilHelper , this . smartContractHelper ) ; VSCodeBlockchainOutputAdapter . instance ( ) . setConsole ( true ) ; await TestUtil . storeBypassPreReqs ( ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . EXTENSION_BYPASS_PREREQS , true , vscode . ConfigurationTarget . Global ) ; await vscode . workspace . getConfiguration ( ) . update ( SettingConfigurations . FABRIC_RUNTIME , { } , vscode . ConfigurationTarget . Global ) ; this . userInputUtilHelper . showConfirmationWarningMessageStub . reset ( ) ; firstTime = false ; const extDirExists = await fs . pathExists ( extDir ) ; if ( extDirExists ) { await fs . remove ( extDir ) ; } await fs . ensureDir ( extDir ) ; await ExtensionUtil . activateExtension ( ) ; await vscode . commands . executeCommand ( 'environmentExplorer.focus' ) ; await TimerUtil . sleep ( 3000 ) ; this . userInputUtilHelper . logSpy . should . not . have . been . calledWith ( LogType . ERROR ) ; this . userInputUtilHelper . logSpy . resetHistory ( ) ; if ( ! process . env . OTHER_FABRIC && ! process . env . TWO_ORG_FABRIC && ! process . env . OPSTOOLS_FABRIC ) { try { await vscode . commands . executeCommand ( ExtensionCommands . TEARDOWN_FABRIC , undefined , true , FabricRuntimeUtil . LOCAL_FABRIC ) ; } catch ( error ) { } } } } ) ; this . After ( this . timeout , async ( ) => { await vscode . commands . executeCommand ( ExtensionCommands . DISCONNECT_GATEWAY ) ; await vscode . commands . executeCommand ( ExtensionCommands . DISCONNECT_ENVIRONMENT ) ; await TimerUtil . sleep ( 3000 ) ; } ) ; } ;