Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/task.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 { Editor } from './editor';
7
import { Code } from './code';
8
import { QuickAccess } from './quickaccess';
9
import { Editors } from './editors';
10
import { QuickInput } from './quickinput';
11
import { Terminal } from './terminal';
12
import { wait } from './playwrightDriver';
13
14
interface ITaskConfigurationProperties {
15
label?: string;
16
type?: string;
17
command?: string;
18
identifier?: string;
19
group?: string;
20
isBackground?: boolean;
21
promptOnClose?: boolean;
22
icon?: { id?: string; color?: string };
23
hide?: boolean;
24
}
25
26
export enum TaskCommandId {
27
TerminalRename = 'workbench.action.terminal.rename'
28
}
29
30
export class Task {
31
32
constructor(private code: Code, private editor: Editor, private editors: Editors, private quickaccess: QuickAccess, private quickinput: QuickInput, private terminal: Terminal) {
33
34
}
35
36
async assertTasks(filter: string, expected: ITaskConfigurationProperties[], type: 'run' | 'configure') {
37
// TODO https://github.com/microsoft/vscode/issues/242535
38
// Artificial delay before running non hidden tasks
39
// so that entries from configureTask show up in the quick access.
40
await wait(1000);
41
type === 'run' ? await this.quickaccess.runCommand('workbench.action.tasks.runTask', { keepOpen: true }) : await this.quickaccess.runCommand('workbench.action.tasks.configureTask', { keepOpen: true });
42
if (expected.length === 0) {
43
await this.quickinput.waitForQuickInputElements(e => e.length > 1 && e.every(label => label.trim() !== filter.trim()));
44
}
45
if (expected.length > 0 && !expected[0].hide) {
46
await this.quickinput.waitForQuickInputElements(e => e.length > 1 && e.some(label => label.trim() === filter.trim()));
47
// select the expected task
48
await this.quickinput.selectQuickInputElement(0, true);
49
// Continue without scanning the output
50
await this.quickinput.selectQuickInputElement(0);
51
if (expected[0].icon) {
52
await this.terminal.assertSingleTab({ color: expected[0].icon.color, icon: expected[0].icon.id || 'tools' });
53
}
54
}
55
await this.quickinput.closeQuickInput();
56
}
57
58
async configureTask(properties: ITaskConfigurationProperties) {
59
await this.quickaccess.openFileQuickAccessAndWait('tasks.json', 'tasks.json');
60
await this.quickinput.selectQuickInputElement(0);
61
await this.quickaccess.runCommand('editor.action.selectAll');
62
await this.code.dispatchKeybinding('Delete', async () => {
63
// TODO https://github.com/microsoft/vscode/issues/242535
64
await wait(100);
65
});
66
const taskStringLines: string[] = [
67
'{', // Brackets auto close
68
'"version": "2.0.0",',
69
'"tasks": [{' // Brackets auto close
70
];
71
for (let [key, value] of Object.entries(properties)) {
72
if (typeof value === 'object') {
73
value = JSON.stringify(value);
74
} else if (typeof value === 'boolean') {
75
value = value;
76
} else if (typeof value === 'string') {
77
value = `"${value}"`;
78
} else {
79
throw new Error('Unsupported task property value type');
80
}
81
taskStringLines.push(`"${key}": ${value},`);
82
}
83
for (const [i, line] of taskStringLines.entries()) {
84
await this.editor.waitForTypeInEditor('tasks.json', `${line}`);
85
if (i !== taskStringLines.length - 1) {
86
await this.code.dispatchKeybinding('Enter', async () => {
87
// TODO https://github.com/microsoft/vscode/issues/242535
88
await wait(100);
89
});
90
}
91
}
92
await this.editors.saveOpenedFile();
93
}
94
}
95
96