import { createTestActionContext } from 'vscode-azureextensiondev' ; import { CentralTemplateProvider , FuncVersion , ProjectLanguage , supportedLanguages as resourceLanguages , TemplateProviderBase } from '../extension.bundle' ; import { getTestWorkspaceFolder , updateBackupTemplates } from './global.test' ; import { javaUtils } from './utils/javaUtils' ; type WorkerRuntime = { language : ProjectLanguage ; projectTemplateKey ? : string ; versions : FuncVersion [ ] ; } ; /**
 * This is not actually a test, but a tool for updating backup templates.
 * The benefit of running as a test (as opposed to for example a gulp task) is that it can run within the context of VS Code and our extension
 * Set the environment variable `AZFUNC_UPDATE_BACKUP_TEMPLATES` to `1` to run this
 */ suite ( 'Backup templates' , ( ) => { suiteSetup ( async function ( this ) : Promise < void > { if ( ! updateBackupTemplates ) { this . skip ( ) ; } } ) ; test ( 'Update' , async ( ) => { const testWorkspacePath = getTestWorkspaceFolder ( ) ; await javaUtils . addJavaProjectToWorkspace ( testWorkspacePath ) ; const allVersions = Object . values ( FuncVersion ) ; const workers = [ { language : ProjectLanguage . JavaScript , versions : allVersions } , { language : ProjectLanguage . CSharp , versions : [ FuncVersion . v1 , FuncVersion . v2 ] } , { language : ProjectLanguage . CSharp , projectTemplateKey : 'netcoreapp3.1' , versions : [ FuncVersion . v3 ] } , { language : ProjectLanguage . CSharp , projectTemplateKey : 'net5.0-isolated' , versions : [ FuncVersion . v3 , FuncVersion . v4 ] } , { language : ProjectLanguage . CSharp , projectTemplateKey : 'net6.0' , versions : [ FuncVersion . v4 ] } , { language : ProjectLanguage . CSharp , projectTemplateKey : 'net6.0-isolated' , versions : [ FuncVersion . v4 ] } , { language : ProjectLanguage . Java , versions : [ FuncVersion . v2 , FuncVersion . v3 , FuncVersion . v4 ] } ] ; for ( const worker of workers ) { for ( const version of Object . values ( FuncVersion ) ) { if ( ! worker . versions ?. includes ( version ) ) { continue ; } const providers = CentralTemplateProvider . getProviders ( testWorkspacePath , worker . language , version , worker . projectTemplateKey ) ; const context = await createTestActionContext ( ) ; for ( const provider of providers ) { const templateVersion = await provider . getLatestTemplateVersion ( context ) ; async function updateBackupTemplatesInternal ( ) { await provider . getLatestTemplates ( context , templateVersion ) ; await provider . updateBackupTemplates ( context ) ; } if ( worker . language === ProjectLanguage . JavaScript ) { for ( const resourcesLanguage of resourceLanguages ) { provider . resourcesLanguage = resourcesLanguage ; await updateBackupTemplatesInternal ( ) ; } } else { await updateBackupTemplatesInternal ( ) ; } await provider . updateBackupTemplateVersion ( templateVersion ) ; } } } } ) ; } ) ;