import * as assert from 'assert' ; import { runWithTestActionContext } from 'vscode-azureextensiondev' ; import { CentralTemplateProvider , FuncVersion , IFunctionTemplate , ProjectLanguage , TemplateFilter , TemplateSource } from '../extension.bundle' ; import { getTestWorkspaceFolder , longRunningTestsEnabled , runForTemplateSource , shouldSkipVersion , skipStagingTemplateSource } from './global.test' ; import { javaUtils } from './utils/javaUtils' ; addSuite ( undefined ) ; addSuite ( TemplateSource . Latest ) ; addSuite ( TemplateSource . Staging ) ; addSuite ( TemplateSource . Backup ) ; interface TestCase { language : ProjectLanguage ; version : FuncVersion ; expectedCount : number ; projectTemplateKey ? : string ; } function addSuite ( source ) { suite ( `Template Count - ${ source === undefined ? 'defaultOnExtensionActivation' : source }` , ( ) => { const cases = [ { language : ProjectLanguage . JavaScript , version : FuncVersion . v1 , expectedCount : 8 } , { language : ProjectLanguage . JavaScript , version : FuncVersion . v2 , expectedCount : 14 } , { language : ProjectLanguage . JavaScript , version : FuncVersion . v3 , expectedCount : 14 } , { language : ProjectLanguage . JavaScript , version : FuncVersion . v4 , expectedCount : 14 } , { language : ProjectLanguage . CSharp , version : FuncVersion . v1 , expectedCount : 12 } , { language : ProjectLanguage . CSharp , version : FuncVersion . v2 , expectedCount : 11 } , { language : ProjectLanguage . CSharp , version : FuncVersion . v3 , expectedCount : 12 , projectTemplateKey : 'netcoreapp3.1' } , { language : ProjectLanguage . CSharp , version : FuncVersion . v3 , expectedCount : 9 , projectTemplateKey : 'net5.0-isolated' } , { language : ProjectLanguage . CSharp , version : FuncVersion . v4 , expectedCount : 12 , projectTemplateKey : 'net6.0' } , { language : ProjectLanguage . CSharp , version : FuncVersion . v4 , expectedCount : 9 , projectTemplateKey : 'net5.0-isolated' } , { language : ProjectLanguage . CSharp , version : FuncVersion . v4 , expectedCount : 9 , projectTemplateKey : 'net6.0-isolated' } , { language : ProjectLanguage . Python , version : FuncVersion . v2 , expectedCount : 12 } , { language : ProjectLanguage . Python , version : FuncVersion . v3 , expectedCount : 12 } , { language : ProjectLanguage . Python , version : FuncVersion . v4 , expectedCount : 12 } , { language : ProjectLanguage . TypeScript , version : FuncVersion . v2 , expectedCount : 14 } , { language : ProjectLanguage . TypeScript , version : FuncVersion . v3 , expectedCount : 14 } , { language : ProjectLanguage . TypeScript , version : FuncVersion . v4 , expectedCount : 14 } , { language : ProjectLanguage . PowerShell , version : FuncVersion . v2 , expectedCount : 14 } , { language : ProjectLanguage . PowerShell , version : FuncVersion . v3 , expectedCount : 14 } , { language : ProjectLanguage . PowerShell , version : FuncVersion . v4 , expectedCount : 14 } , { language : ProjectLanguage . Java , version : FuncVersion . v2 , expectedCount : 4 } ] ; let testWorkspacePath ; suiteSetup ( async ( ) => { testWorkspacePath = getTestWorkspaceFolder ( ) ; } ) ; for ( const { language , version , expectedCount , projectTemplateKey } of cases ) { let testName = `${ language } ${ version }` ; if ( projectTemplateKey ) { testName += ` ${ projectTemplateKey }` ; } test ( testName , async function ( this ) : Promise < void > { if ( ( source === TemplateSource . Staging && skipStagingTemplateSource ) || shouldSkipVersion ( version ) ) { this . skip ( ) ; } if ( language === ProjectLanguage . Java ) { await javaPreTest ( this , testWorkspacePath ) ; } await runWithTestActionContext ( 'getFunctionTemplates' , async ( context ) => { await runForTemplateSource ( context , source , async ( provider ) => { const templates = await provider . getFunctionTemplates ( context , testWorkspacePath , language , version , TemplateFilter . Verified , projectTemplateKey ) ; assert . equal ( templates . length , expectedCount ) ; } ) ; } ) ; } ) ; } } ) ; } async function javaPreTest ( testContext , testWorkspacePath ) { if ( ! longRunningTestsEnabled ) { testContext . skip ( ) ; } testContext . timeout ( 120 * 1000 ) ; await javaUtils . addJavaProjectToWorkspace ( testWorkspacePath ) ; }