import { WebSiteManagementClient } from '@azure/arm-appservice' ; import { ResourceManagementClient } from '@azure/arm-resources' ; import * as vscode from 'vscode' ; import { createTestActionContext , TestAzureAccount } from 'vscode-azureextensiondev' ; import { AzExtTreeDataProvider , AzureAccountTreeItemWithProjects , createAzureClient , ext } from '../../extension.bundle' ; import { longRunningTestsEnabled } from '../global.test' ; export let testAccount ; export let testClient ; export const resourceGroupsToDelete = [ ] ; suiteSetup ( async function ( this ) : Promise < void > { if ( longRunningTestsEnabled ) { this . timeout ( 2 * 60 * 1000 ) ; testAccount = new TestAzureAccount ( vscode ) ; await testAccount . signIn ( ) ; ext . azureAccountTreeItem = new AzureAccountTreeItemWithProjects ( testAccount ) ; ext . tree = new AzExtTreeDataProvider ( ext . azureAccountTreeItem , 'azureFunctions.loadMore' ) ; testClient = createAzureClient ( [ await createTestActionContext ( ) , testAccount . getSubscriptionContext ( ) ] , WebSiteManagementClient ) ; } } ) ; suiteTeardown ( async function ( this ) : Promise < void > { if ( longRunningTestsEnabled ) { this . timeout ( 10 * 60 * 1000 ) ; await deleteResourceGroups ( ) ; ext . azureAccountTreeItem . dispose ( ) ; } } ) ; async function deleteResourceGroups ( ) { const rgClient = createAzureClient ( [ await createTestActionContext ( ) , testAccount . getSubscriptionContext ( ) ] , ResourceManagementClient ) ; await Promise . all ( resourceGroupsToDelete . map ( async ( resourceGroup ) => { if ( ( await rgClient . resourceGroups . checkExistence ( resourceGroup ) ) . body ) { console . log ( `Started delete of resource group "${ resourceGroup }"...` ) ; await rgClient . resourceGroups . beginDeleteMethod ( resourceGroup ) ; console . log ( `Successfully started delete of resource group "${ resourceGroup }".` ) ; } else { console . log ( `Ignoring resource group "${ resourceGroup }" because it does not exist.` ) ; } } ) ) ; }