-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathapi.test.ts
More file actions
118 lines (104 loc) · 5.77 KB
/
api.test.ts
File metadata and controls
118 lines (104 loc) · 5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { runWithInputs } from '@microsoft/vscode-azext-dev';
import { type apiUtils } from "@microsoft/vscode-azext-utils";
import * as path from 'path';
import { extensions, type Extension } from "vscode";
import { FuncVersion, ProjectLanguage, extensionId, nonNullValue, registerOnActionStartHandler } from '../extension.bundle';
// eslint-disable-next-line no-restricted-imports
import { type AzureFunctionsExtensionApi } from '../src/vscode-azurefunctions.api';
import { getTestWorkspaceFolder, testFolderPath } from './global.test';
import { getCSharpValidateOptions, getJavaScriptValidateOptions, validateProject, type IValidateProjectOptions } from './project/validateProject';
suite(`AzureFunctionsExtensionApi`, () => {
let api: AzureFunctionsExtensionApi;
suiteSetup(() => {
const extension: Extension<apiUtils.AzureExtensionApiProvider> | undefined = extensions.getExtension(extensionId);
api = nonNullValue(extension).exports.getApi<AzureFunctionsExtensionApi>('^1.0.0');
});
test('createFunction in a subfolder of a workspace', async () => {
const functionName: string = 'endpoint1';
const language: string = ProjectLanguage.JavaScript;
const workspaceFolder = getTestWorkspaceFolder();
const projectSubpath = 'api';
const folderPath: string = path.join(workspaceFolder, projectSubpath);
await runWithInputs('api.createFunction', [language, /Model V3/, functionName], registerOnActionStartHandler, async () => {
await api.createFunction({
folderPath,
suppressOpenFolder: true,
templateId: 'HttpTrigger',
languageFilter: /Python|C\#|^(Java|Type)Script$/i,
functionSettings: { authLevel: 'anonymous' },
targetFramework: ['netcoreapp3.1', 'net6.0'] // Will only work on functions api v1.4.0, but won't hurt on v1.3.0
});
});
const validateOptions: IValidateProjectOptions = 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')
);
// Exclude .git because the test workspace folders are already inside a git repo so we don't do git init.
validateOptions.excludedPaths?.push('.git');
await validateProject(folderPath, validateOptions);
});
test('createFunction', async () => {
const functionName: string = 'endpoint1';
const language: string = ProjectLanguage.JavaScript;
const folderPath: string = path.join(testFolderPath, language + 'createFunctionApi2');
await runWithInputs('api.createFunction', [language, /Model V3/], registerOnActionStartHandler, async () => {
await api.createFunction({
folderPath,
functionName,
templateId: 'HttpTrigger',
languageFilter: /^(Java|Type)Script$/i,
functionSettings: { authLevel: 'anonymous' },
suppressOpenFolder: true
});
});
const validateOptions: IValidateProjectOptions = getJavaScriptValidateOptions(true);
validateOptions.expectedPaths.push(
path.join(functionName, 'index.js'),
path.join(functionName, 'function.json')
);
await validateProject(folderPath, validateOptions);
});
test('createFunction dotnet with targetFramework', async () => {
const functionName: string = 'endpoint1';
const language: string = ProjectLanguage.CSharp;
const workspaceFolder = getTestWorkspaceFolder();
const projectSubpath = 'api';
const folderPath: string = path.join(workspaceFolder, projectSubpath);
await runWithInputs('api.createFunction', [language, /6/i, 'Company.Function', 'Anonymous'], registerOnActionStartHandler, async () => {
await api.createFunction({
folderPath,
functionName,
templateId: 'HttpTrigger',
languageFilter: /^C\#$/i,
functionSettings: { authLevel: 'anonymous' },
targetFramework: ['net8.0', 'net7.0', 'net6.0']
});
});
const validateOptions: IValidateProjectOptions = getCSharpValidateOptions('net6.0', FuncVersion.v4);
await validateProject(folderPath, validateOptions);
});
// When passing in a language version that is not in the target framework the last two inputs should not be prompted if they are this test will fail
test('createFunction with language not in targetFramework', async () => {
const functionName: string = 'endpoint1';
const language: string = ProjectLanguage.CSharp;
const workspaceFolder = getTestWorkspaceFolder();
const projectSubpath = 'api';
const folderPath: string = path.join(workspaceFolder, projectSubpath);
await runWithInputs('api.createFunction', [language, /8/i], registerOnActionStartHandler, async () => {
await api.createFunction({
folderPath,
functionName,
templateId: 'HttpTrigger',
languageFilter: /^C\#$/i,
functionSettings: { authLevel: 'anonymous' },
targetFramework: ['net7.0', 'net6.0']
})
});
});
});