-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathparallelTests.ts
More file actions
96 lines (81 loc) · 5.21 KB
/
parallelTests.ts
File metadata and controls
96 lines (81 loc) · 5.21 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { runWithTestActionContext } from "@microsoft/vscode-azext-dev";
import * as assert from "assert";
import * as path from "path";
import { workspace, type Uri, type WorkspaceFolder } from "vscode";
import { AzExtFsExtra, deployWorkspaceProject, dwpSettingUtilsV2, ext, parseError, settingUtils, type DeploymentConfigurationSettings, type DeployWorkspaceProjectResults, type IParsedError } from "../../../extension.bundle";
import { assertStringPropsMatch, getWorkspaceFolderUri } from "../../testUtils";
import { resourceGroupsToDelete } from "../global.nightly.test";
import { type DeployWorkspaceProjectTestScenario } from "./scenarios/DeployWorkspaceProjectTestScenario";
import { generateTestScenarios } from "./scenarios/testScenarios";
export interface DwpParallelTestScenario {
title: string;
callback(): Promise<void>;
scenario?: Promise<void>;
}
export function generateParallelTests(): DwpParallelTestScenario[] {
return generateTestScenarios().map(scenario => {
return {
title: scenario.label,
callback: runTestScenario(scenario),
};
});
}
function runTestScenario(scenario: DeployWorkspaceProjectTestScenario): DwpParallelTestScenario['callback'] {
return async () => {
const workspaceFolderUri: Uri = getWorkspaceFolderUri(scenario.folderName);
const rootFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(workspaceFolderUri);
assert.ok(rootFolder, 'Could not retrieve root workspace folder.');
await cleanWorkspaceFolderSettings(rootFolder);
for (const testCase of scenario.testCases) {
ext.outputChannel.appendLog(`[[[ *** ${scenario.label} - ${testCase.label} *** ]]]`);
await runWithTestActionContext('deployWorkspaceProject', async context => {
await context.ui.runWithInputs(testCase.inputs, async () => {
let results: DeployWorkspaceProjectResults;
let perr: IParsedError | undefined;
try {
results = await deployWorkspaceProject(context);
} catch (e) {
results = {};
perr = parseError(e);
console.log(perr);
}
if (testCase.resourceGroupToDelete) {
resourceGroupsToDelete.add(testCase.resourceGroupToDelete);
}
// Verify 'expectedErrMsg'
if (perr || testCase.expectedErrMsg) {
if (testCase.expectedErrMsg instanceof RegExp) {
assert.match(perr?.message ?? "", testCase.expectedErrMsg, 'DeployWorkspaceProject thrown and expected error message did not match.');
} else {
assert.strictEqual(perr?.message ?? "", testCase.expectedErrMsg, 'DeployWorkspaceProject thrown and expected error message did not match.');
}
}
// Verify 'expectedResults'
assertStringPropsMatch(results as Partial<Record<string, string>>, (testCase.expectedResults ?? {}) as Record<string, string | RegExp>, 'DeployWorkspaceProject results mismatch.');
// Verify 'expectedVSCodeSettings'
const deploymentConfigurationsV2: DeploymentConfigurationSettings[] = await dwpSettingUtilsV2.getWorkspaceDeploymentConfigurations(rootFolder) ?? [];
const expectedDeploymentConfigurations = testCase.expectedVSCodeSettings?.deploymentConfigurations ?? [];
assert.strictEqual(deploymentConfigurationsV2.length, expectedDeploymentConfigurations.length, 'DeployWorkspaceProject ".vscode" saved settings mismatch.');
for (const [i, expectedDeploymentConfiguration] of expectedDeploymentConfigurations.entries()) {
const deploymentConfiguration: DeploymentConfigurationSettings = deploymentConfigurationsV2[i] ?? {};
assertStringPropsMatch(deploymentConfiguration as Partial<Record<string, string>>, expectedDeploymentConfiguration, 'DeployWorkspaceProject ".vscode" saved settings mismatch.');
}
// Verify 'postTestAssertion'
await testCase.postTestAssertion?.(context, results, 'DeployWorkspaceProject resource settings mismatch.');
});
});
}
await cleanWorkspaceFolderSettings(rootFolder);
}
}
async function cleanWorkspaceFolderSettings(rootFolder: WorkspaceFolder) {
const settingsPath: string = settingUtils.getDefaultRootWorkspaceSettingsPath(rootFolder);
const vscodeFolderPath: string = path.dirname(settingsPath);
if (await AzExtFsExtra.pathExists(vscodeFolderPath)) {
await AzExtFsExtra.deleteResource(vscodeFolderPath, { recursive: true });
}
}