import * as path from 'path' ; import { Extension , extensions } from "vscode" ; import { runWithInputs } from 'vscode-azureextensiondev' ; import { AzureExtensionApiProvider } from "vscode-azureextensionui/api" ; import { nonNullValue , ProjectLanguage , registerOnActionStartHandler } from '../extension.bundle' ; import { AzureFunctionsExtensionApi } from '../src/vscode-azurefunctions.api' ; import { getTestWorkspaceFolder , testFolderPath } from './global.test' ; import { getJavaScriptValidateOptions , IValidateProjectOptions , validateProject } from './project/validateProject' ; suite ( `AzureFunctionsExtensionApi` , ( ) => { let api ; suiteSetup ( ( ) => { const extension = extensions . getExtension ( 'ms-azuretools.vscode-azurefunctions' ) ; api = nonNullValue ( extension ) . exports . getApi < AzureFunctionsExtensionApi > ( '^1.0.0' ) ; } ) ; test ( 'createFunction in a subfolder of a workspace' , async ( ) => { const functionName = 'endpoint1' ; const language = ProjectLanguage . JavaScript ; const workspaceFolder = getTestWorkspaceFolder ( ) ; const projectSubpath = 'api' ; const folderPath = path . join ( workspaceFolder , projectSubpath ) ; await runWithInputs ( 'api.createFunction' , [ language , functionName ] , registerOnActionStartHandler , async ( ) => { await api . createFunction ( { folderPath , suppressCreateProjectPrompt : true , suppressOpenFolder : true , templateId : 'HttpTrigger' , languageFilter : /Python|C\#|^(Java|Type)Script$/i , functionSettings : { authLevel : 'anonymous' } , targetFramework : [ 'netcoreapp3.1' , 'net6.0' ] } ) ; } ) ; const validateOptions = getJavaScriptValidateOptions ( true , undefined , projectSubpath , workspaceFolder ) ; validateOptions . expectedPaths . push ( path . join ( projectSubpath , functionName , 'index.js' ) , path . join ( projectSubpath , functionName , 'function.json' ) , path . join ( projectSubpath , 'package.json' ) ) ; validateOptions . excludedPaths ?. push ( '.git' ) ; await validateProject ( folderPath , validateOptions ) ; } ) ; test ( 'createFunction' , async ( ) => { const functionName = 'endpoint1' ; const language = ProjectLanguage . JavaScript ; const folderPath = path . join ( testFolderPath , language + 'createFunctionApi2' ) ; await runWithInputs ( 'api.createFunction' , [ language ] , registerOnActionStartHandler , async ( ) => { await api . createFunction ( { folderPath , functionName , templateId : 'HttpTrigger' , languageFilter : /^(Java|Type)Script$/i , functionSettings : { authLevel : 'anonymous' } , suppressCreateProjectPrompt : true , suppressOpenFolder : true } ) ; } ) ; const validateOptions = getJavaScriptValidateOptions ( true ) ; validateOptions . expectedPaths . push ( path . join ( functionName , 'index.js' ) , path . join ( functionName , 'function.json' ) ) ; await validateProject ( folderPath , validateOptions ) ; } ) ; } ) ;