vscode/test/automation/src/extensions.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
3.1 KiB
TypeScript
Raw Normal View History

2017-09-04 09:51:50 +00:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Viewlet } from './viewlet';
import { Code } from './code';
import path = require('path');
import fs = require('fs');
import { ncp } from 'ncp';
import { promisify } from 'util';
2023-09-04 11:30:46 +00:00
import { Commands } from './workbench';
2017-09-04 09:51:50 +00:00
2017-10-10 12:18:55 +00:00
2017-09-06 08:48:20 +00:00
export class Extensions extends Viewlet {
2017-09-04 09:51:50 +00:00
2023-09-04 11:30:46 +00:00
constructor(code: Code, private commands: Commands) {
2018-04-11 14:20:09 +00:00
super(code);
2017-09-04 09:51:50 +00:00
}
async searchForExtension(id: string): Promise<any> {
await this.commands.runCommand('Extensions: Focus on Extensions View', { exactLabelMatch: true });
2023-09-04 11:30:46 +00:00
await this.code.waitForTypeInEditor('div.extensions-viewlet[id="workbench.view.extensions"] .monaco-editor textarea', `@id:${id}`);
2021-09-06 12:32:19 +00:00
await this.code.waitForTextContent(`div.part.sidebar div.composite.title h2`, 'Extensions: Marketplace');
2022-01-18 16:43:05 +00:00
let retrials = 1;
while (retrials++ < 10) {
try {
return await this.code.waitForElement(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[data-extension-id="${id}"]`, undefined, 100);
} catch (error) {
this.code.logger.log(`Extension '${id}' is not found. Retrying count: ${retrials}`);
2023-09-04 11:30:46 +00:00
await this.commands.runCommand('workbench.extensions.action.refreshExtension');
2022-01-18 16:43:05 +00:00
}
}
throw new Error(`Extension ${id} is not found`);
2021-02-03 20:42:12 +00:00
}
async openExtension(id: string): Promise<any> {
await this.searchForExtension(id);
await this.code.waitAndClick(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[data-extension-id="${id}"]`);
2017-09-04 09:51:50 +00:00
}
2021-03-09 08:30:43 +00:00
async closeExtension(title: string): Promise<any> {
try {
await this.code.waitAndClick(`.tabs-container div.tab[aria-label="Extension: ${title}, preview"] div.tab-actions a.action-label.codicon.codicon-close`);
} catch (e) {
this.code.logger.log(`Extension '${title}' not opened as preview. Trying without 'preview'.`);
await this.code.waitAndClick(`.tabs-container div.tab[aria-label="Extension: ${title}"] div.tab-actions a.action-label.codicon.codicon-close`);
}
2021-03-09 08:30:43 +00:00
}
2020-11-30 19:25:44 +00:00
async installExtension(id: string, waitUntilEnabled: boolean): Promise<void> {
await this.searchForExtension(id);
2020-10-23 07:20:36 +00:00
await this.code.waitAndClick(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[data-extension-id="${id}"] .extension-list-item .monaco-action-bar .action-item:not(.disabled) .extension-action.install`);
2020-11-30 19:25:44 +00:00
await this.code.waitForElement(`.extension-editor .monaco-action-bar .action-item:not(.disabled) .extension-action.uninstall`);
if (waitUntilEnabled) {
await this.code.waitForElement(`.extension-editor .monaco-action-bar .action-item:not(.disabled) a[aria-label="Disable this extension"]`);
2020-11-30 19:25:44 +00:00
}
2017-09-04 09:51:50 +00:00
}
}
export async function copyExtension(repoPath: string, extensionsPath: string, extId: string): Promise<void> {
const dest = path.join(extensionsPath, extId);
if (!fs.existsSync(dest)) {
const orig = path.join(repoPath, 'extensions', extId);
2020-11-30 19:25:44 +00:00
return promisify(ncp)(orig, dest);
}
}