import * as path from 'path' ; import * as vscode from 'vscode' ; import { FuncVersion , funcVersionSetting , ProjectLanguage , projectLanguageSetting , TemplateSource } from '../../extension.bundle' ; import { allTemplateSources , shouldSkipVersion } from '../global.test' ; import { runWithFuncSetting } from '../runWithSetting' ; import { FunctionTesterBase } from './FunctionTesterBase' ; class JSFunctionTesterV1 extends FunctionTesterBase { public language : ProjectLanguage = ProjectLanguage . JavaScript ; public constructor ( source ) { super ( FuncVersion . v1 , source ) ; } public getExpectedPaths ( functionName ) { return [ path . join ( functionName , 'function.json' ) , path . join ( functionName , 'index.js' ) ] ; } } for ( const source of allTemplateSources ) { const jsTester = new JSFunctionTesterV1 ( source ) ; suite ( jsTester . suiteName , function ( this ) : void { suiteSetup ( async function ( this ) : Promise < void > { if ( shouldSkipVersion ( jsTester . version ) ) { this . skip ( ) ; } await jsTester . initAsync ( ) ; } ) ; suiteTeardown ( async ( ) => { if ( ! shouldSkipVersion ( jsTester . version ) ) { await jsTester . dispose ( ) ; } } ) ; const blobTrigger = 'Blob trigger' ; test ( blobTrigger , async ( ) => { await jsTester . testCreateFunction ( blobTrigger , 'AzureWebJobsStorage' , 'test-path/{name}' ) ; } ) ; const genericWebhook = 'Generic webhook' ; test ( genericWebhook , async ( ) => { await jsTester . testCreateFunction ( genericWebhook ) ; } ) ; const gitHubWebhook = 'GitHub webhook' ; test ( gitHubWebhook , async ( ) => { await jsTester . testCreateFunction ( gitHubWebhook ) ; } ) ; const httpTrigger = 'HTTP trigger' ; test ( httpTrigger , async ( ) => { await jsTester . testCreateFunction ( httpTrigger , 'Admin' ) ; } ) ; const httpTriggerWithParameters = 'HTTP trigger with parameters' ; test ( httpTriggerWithParameters , async ( ) => { await jsTester . testCreateFunction ( httpTriggerWithParameters , 'Anonymous' ) ; } ) ; const manualTrigger = 'Manual trigger' ; test ( manualTrigger , async ( ) => { await jsTester . testCreateFunction ( manualTrigger ) ; } ) ; const queueTrigger = 'Queue trigger' ; test ( queueTrigger , async ( ) => { await jsTester . testCreateFunction ( queueTrigger , 'AzureWebJobsStorage' , 'testqueue' ) ; } ) ; const timerTrigger = 'Timer trigger' ; test ( timerTrigger , async ( ) => { await jsTester . testCreateFunction ( timerTrigger , '0 * 0/5 * * *' ) ; } ) ; test ( 'createFunction API (deprecated)' , async ( ) => { const templateId = 'HttpTrigger-JavaScript' ; const functionName = 'createFunctionApi' ; const authLevel = 'Anonymous' ; await runWithFuncSetting ( projectLanguageSetting , ProjectLanguage . JavaScript , async ( ) => { await runWithFuncSetting ( funcVersionSetting , FuncVersion . v1 , async ( ) => { await vscode . commands . executeCommand ( 'azureFunctions.createFunction' , jsTester . projectPath , templateId , functionName , { aUtHLevel : authLevel } ) ; } ) ; } ) ; await jsTester . validateFunction ( jsTester . projectPath , functionName , [ authLevel ] ) ; } ) ; } ) ; }