Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/extensions.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Viewlet } from './viewlet';
7
import { Code } from './code';
8
import { ncp } from 'ncp';
9
import { promisify } from 'util';
10
import { Commands } from './workbench';
11
import path = require('path');
12
import fs = require('fs');
13
14
15
export class Extensions extends Viewlet {
16
17
constructor(code: Code, private commands: Commands) {
18
super(code);
19
}
20
21
async searchForExtension(id: string): Promise<any> {
22
await this.commands.runCommand('Extensions: Focus on Extensions View', { exactLabelMatch: true });
23
await this.code.waitForTypeInEditor(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-editor ${!this.code.editContextEnabled ? 'textarea' : '.native-edit-context'}`, `@id:${id}`);
24
await this.code.waitForTextContent(`div.part.sidebar div.composite.title h2`, 'Extensions: Marketplace');
25
26
let retrials = 1;
27
while (retrials++ < 10) {
28
try {
29
return await this.code.waitForElement(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[data-extension-id="${id}"]`, undefined, 100);
30
} catch (error) {
31
this.code.logger.log(`Extension '${id}' is not found. Retrying count: ${retrials}`);
32
await this.commands.runCommand('workbench.extensions.action.refreshExtension');
33
}
34
}
35
throw new Error(`Extension ${id} is not found`);
36
}
37
38
async openExtension(id: string): Promise<any> {
39
await this.searchForExtension(id);
40
await this.code.waitAndClick(`div.extensions-viewlet[id="workbench.view.extensions"] .monaco-list-row[data-extension-id="${id}"]`);
41
}
42
43
async closeExtension(title: string): Promise<any> {
44
try {
45
await this.code.waitAndClick(`.tabs-container div.tab[aria-label="Extension: ${title}, preview"] div.tab-actions a.action-label.codicon.codicon-close`);
46
} catch (e) {
47
this.code.logger.log(`Extension '${title}' not opened as preview. Trying without 'preview'.`);
48
await this.code.waitAndClick(`.tabs-container div.tab[aria-label="Extension: ${title}"] div.tab-actions a.action-label.codicon.codicon-close`);
49
}
50
}
51
52
async installExtension(id: string, waitUntilEnabled: boolean): Promise<void> {
53
await this.searchForExtension(id);
54
55
// try to install extension 3 times
56
let attempt = 1;
57
while (true) {
58
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`);
59
60
try {
61
await this.waitForExtensionToBeInstalled();
62
break;
63
} catch (err) {
64
if (attempt++ === 3) {
65
throw err;
66
}
67
}
68
}
69
70
if (waitUntilEnabled) {
71
await this.code.waitForElement(`.extension-editor .monaco-action-bar .action-item:not(.disabled) a[aria-label="Disable this extension"]`);
72
}
73
}
74
75
private async waitForExtensionToBeInstalled(): Promise<void> {
76
let attempt = 1;
77
while (true) {
78
try {
79
await this.code.waitForElement(`.extension-editor .monaco-action-bar .action-item:not(.disabled) .extension-action.uninstall`, undefined);
80
break;
81
} catch (err) {
82
if (await this.code.getElement(`.extension-editor .monaco-action-bar .action-item .extension-action.install.installing`)) {
83
if (attempt++ === 3) {
84
throw err;
85
}
86
this.code.logger.log('Extension is still being installed. Waiting...');
87
} else {
88
throw err;
89
}
90
}
91
}
92
}
93
}
94
95
export async function copyExtension(repoPath: string, extensionsPath: string, extId: string): Promise<void> {
96
const dest = path.join(extensionsPath, extId);
97
if (!fs.existsSync(dest)) {
98
const orig = path.join(repoPath, 'extensions', extId);
99
100
return promisify(ncp)(orig, dest);
101
}
102
}
103
104