Run "env refresh" command as task (#2060)

This gives the user a chance to interact with the command and fixes https://github.com/Azure/azure-dev/issues/2045

Also refactors the code that runs VS Code unit tests, and upgrades `test-electron` library to fix tests failing with `Error: spawn UNKNOWN` message on Windows
This commit is contained in:
Karol Zadora-Przylecki 2023-05-01 12:01:00 -07:00 коммит произвёл GitHub
Родитель c669a0af21
Коммит f8ebe0208d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 955 добавлений и 5014 удалений

3
ext/vscode/.vscode/cspell-dictionary.txt поставляемый
Просмотреть файл

@ -5,4 +5,5 @@ hostapi
azureresourcegroups
azureresources
walkthrough
walkthroughs
walkthroughs
DEBUGTELEMETRY

15
ext/vscode/.vscode/launch.json поставляемый
Просмотреть файл

@ -19,15 +19,16 @@
"DEBUGTELEMETRY": "true"
},
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
"${workspaceFolder}/dist/**/*.js",
"${workspaceFolder}/*.js"
],
},
{
"name": "Run AZD + Azure Resources Extensions",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/../../../../vscode-azureresourcegroups",
"--extensionDevelopmentPath=${workspaceFolder}/../../../vscode-azureresourcegroups",
"--extensionDevelopmentPath=${workspaceFolder}",
],
"preLaunchTask": "${defaultBuildTask}",
@ -35,7 +36,13 @@
// Disable telemetry when running the extension under the debugger.
// Set this to "verbose" to show telemetry in the console during debugging.
"DEBUGTELEMETRY": "true"
}
},
"outFiles": [
"${workspaceFolder}/dist/**/*.js",
"${workspaceFolder}/*.js",
"${workspaceFolder}/../../../vscode-azureresourcegroups/dist/**/*.js",
"${workspaceFolder}/../../../vscode-azureresourcegroups/*.js"
],
},
{
"name": "Debug Unit Tests",

5831
ext/vscode/package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -485,7 +485,7 @@
"@types/vscode": "~1.76",
"@typescript-eslint/eslint-plugin": "~5",
"@typescript-eslint/parser": "~5",
"@vscode/test-electron": "~2.1",
"@vscode/test-electron": "~2.3",
"@vscode/vsce": "~2",
"chai": "~4.3",
"copy-webpack-plugin": "~11.0",

Просмотреть файл

@ -168,32 +168,23 @@ export async function refreshEnvironment(context: IActionContext, selectedItem?:
if (!folder) {
folder = await quickPickWorkspaceFolder(context, vscode.l10n.t("To run '{0}' command you must first open a folder or workspace in VS Code", 'env refresh'));
}
const cwd = folder.uri.fsPath;
const azureCli = await createAzureDevCli(context);
const progressOptions: vscode.ProgressOptions = {
location: vscode.ProgressLocation.Notification,
title: vscode.l10n.t('Refreshing environment values...'),
};
azureCli.commandBuilder.withArg('env').withArg('refresh');
let command = azureCli.commandBuilder.withArg('env').withArg('refresh');
if (selectedEnvironment) {
azureCli.commandBuilder.withNamedArg('--environment', selectedEnvironment.name);
command = command.withNamedArg('--environment', selectedEnvironment.name);
}
let errorMsg: string | undefined = undefined;
await vscode.window.withProgress(progressOptions, async () => {
try {
await spawnAsync(azureCli.commandBuilder.build(), azureCli.spawnOptions(cwd));
} catch(err) {
errorMsg = parseError(err).message;
void executeAsTask(command.build(), getAzDevTerminalTitle(), {
focus: true,
alwaysRunNew: true,
cwd: folder.uri.fsPath,
env: azureCli.env
}, TelemetryId.EnvRefreshCli).then(() => {
if (selectedEnvironment) {
selectedEnvironment.context.refreshEnvironments();
}
});
if (errorMsg) {
await promptCreateNewEnvironment(
vscode.l10n.t('Environment values could not be refreshed. Infrastructure might have never been provisioned in Azure, or there might be no environments. Would you like to create one?'), errorMsg);
}
}
async function promptCreateNewEnvironment(message: string, details?: string): Promise<void> {

Просмотреть файл

@ -54,6 +54,9 @@ export enum TelemetryId {
// Reported when 'env new' CLI command is invoked.
EnvNewCli = 'azure-dev.commands.cli.env-new.task',
// Reported when 'env refresh' CLI command is invoked.
EnvRefreshCli = 'azure-dev.commands.cli.env-refresh.task',
// Reported when the product evaluates whether to prompt the user for a survey.
// We capture

Просмотреть файл

@ -1,26 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
import { runExtensionTests } from "./runExtensionTests";
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/allTests');
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
try {
await runExtensionTests('suite', 'allTests');
} catch (err) {
console.error('Failed to run tests: ', err);
process.exit(1);
}
}
void main();
void main();

Просмотреть файл

@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import { runTests, downloadAndUnzipVSCode } from '@vscode/test-electron';
export async function runExtensionTests(...testPath: string[] ) {
try {
const vsCodePath = await downloadAndUnzipVSCode('stable');
// The folder containing the Extension Manifest package.json
const extensionDevelopmentPath = path.resolve(__dirname, '..', '..');
// The path to test runner
const extensionTestsPath = path.resolve(__dirname, ...testPath);
await runTests({
vscodeExecutablePath: vsCodePath,
extensionDevelopmentPath: extensionDevelopmentPath,
extensionTestsPath: extensionTestsPath,
extensionTestsEnv: {
DEBUGTELEMETRY: 'true',
}
});
} catch (err) {
console.error('Failed to run tests: ', err);
process.exit(1);
}
}

Просмотреть файл

@ -1,26 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as path from 'path';
import { runTests } from '@vscode/test-electron';
import { runExtensionTests } from "./runExtensionTests";
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/unitTests');
// Download VS Code, unzip it and run unit tests
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
try {
await runExtensionTests('suite', 'unitTests');
} catch (err) {
console.error('Failed to run tests: ', err);
process.exit(1);
}
}
void main();
void main();

Просмотреть файл

@ -17,7 +17,7 @@ export function run(): Promise<void> {
const testsRoot = path.resolve(__dirname, '..');
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
glob('suite/**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}