mirror of
https://github.com/Microsoft/vscode
synced 2024-10-06 03:17:00 +00:00
add task quick pick smoke tests (#154532)
This commit is contained in:
parent
39319d4f21
commit
1076bf59dd
|
@ -85,6 +85,9 @@ export class Editor {
|
|||
}
|
||||
|
||||
async waitForTypeInEditor(filename: string, text: string, selectorPrefix = ''): Promise<any> {
|
||||
if (text.includes('\n')) {
|
||||
throw new Error('waitForTypeInEditor does not support new lines, use either a long single line or dispatchKeybinding(\'Enter\')');
|
||||
}
|
||||
const editor = [selectorPrefix || '', EDITOR(filename)].join(' ');
|
||||
|
||||
await this.code.waitForElement(editor);
|
||||
|
|
|
@ -25,4 +25,5 @@ export * from './terminal';
|
|||
export * from './viewlet';
|
||||
export * from './localization';
|
||||
export * from './workbench';
|
||||
export * from './task';
|
||||
export { getDevElectronPath, getBuildElectronPath, getBuildVersion } from './electron';
|
||||
|
|
86
test/automation/src/task.ts
Normal file
86
test/automation/src/task.ts
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Editor } from './editor';
|
||||
import { Code } from './code';
|
||||
import { QuickAccess } from './quickaccess';
|
||||
import { Editors } from './editors';
|
||||
import { QuickInput } from './quickinput';
|
||||
import { Terminal } from './terminal';
|
||||
|
||||
interface ITaskConfigurationProperties {
|
||||
label?: string;
|
||||
type?: string;
|
||||
command?: string;
|
||||
identifier?: string;
|
||||
group?: string;
|
||||
isBackground?: boolean;
|
||||
promptOnClose?: boolean;
|
||||
icon?: { id?: string; color?: string };
|
||||
hide?: boolean;
|
||||
}
|
||||
|
||||
export enum TaskCommandId {
|
||||
TerminalRename = 'workbench.action.terminal.rename'
|
||||
}
|
||||
|
||||
export class Task {
|
||||
|
||||
constructor(private code: Code, private editor: Editor, private editors: Editors, private quickaccess: QuickAccess, private quickinput: QuickInput, private terminal: Terminal) {
|
||||
|
||||
}
|
||||
|
||||
async assertTasks(filter: string, expected: ITaskConfigurationProperties[], type: 'run' | 'configure') {
|
||||
await this.code.dispatchKeybinding('right');
|
||||
await this.editors.saveOpenedFile();
|
||||
type === 'run' ? await this.quickaccess.runCommand('workbench.action.tasks.runTask', true) : await this.quickaccess.runCommand('workbench.action.tasks.configureTask', true);
|
||||
if (expected.length === 0) {
|
||||
await this.quickinput.waitForQuickInputElements(e => e.length > 1 && e.every(label => label.trim() !== filter.trim()));
|
||||
} else {
|
||||
await this.quickinput.waitForQuickInputElements(e => e.length > 1 && e.some(label => label.trim() === filter.trim()));
|
||||
}
|
||||
if (expected.length > 0 && !expected[0].hide) {
|
||||
// select the expected task
|
||||
await this.quickinput.selectQuickInputElement(0, true);
|
||||
// Continue without scanning the output
|
||||
await this.quickinput.selectQuickInputElement(0);
|
||||
if (expected[0].icon) {
|
||||
await this.terminal.assertSingleTab({ color: expected[0].icon.color, icon: expected[0].icon.id || 'tools' });
|
||||
}
|
||||
}
|
||||
await this.quickinput.closeQuickInput();
|
||||
}
|
||||
|
||||
async configureTask(properties: ITaskConfigurationProperties) {
|
||||
await this.quickaccess.openFileQuickAccessAndWait('tasks.json', 'tasks.json');
|
||||
await this.quickinput.selectQuickInputElement(0);
|
||||
await this.quickaccess.runCommand('editor.action.selectAll');
|
||||
await this.code.dispatchKeybinding('Delete');
|
||||
const taskStringLines: string[] = [
|
||||
'{', // Brackets auto close
|
||||
'"version": "2.0.0",',
|
||||
'"tasks": [{' // Brackets auto close
|
||||
];
|
||||
for (let [key, value] of Object.entries(properties)) {
|
||||
if (typeof value === 'object') {
|
||||
value = JSON.stringify(value);
|
||||
} else if (typeof value === 'boolean') {
|
||||
value = value;
|
||||
} else if (typeof value === 'string') {
|
||||
value = `"${value}"`;
|
||||
} else {
|
||||
throw new Error('Unsupported task property value type');
|
||||
}
|
||||
taskStringLines.push(`"${key}": ${value},`);
|
||||
}
|
||||
for (const [i, line] of taskStringLines.entries()) {
|
||||
await this.editor.waitForTypeInEditor('tasks.json', `${line}`);
|
||||
if (i !== taskStringLines.length - 1) {
|
||||
await this.code.dispatchKeybinding('Enter');
|
||||
}
|
||||
}
|
||||
await this.editors.saveOpenedFile();
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ import { Code } from './code';
|
|||
import { Terminal } from './terminal';
|
||||
import { Notebook } from './notebook';
|
||||
import { Localization } from './localization';
|
||||
import { Task } from './task';
|
||||
|
||||
export interface Commands {
|
||||
runCommand(command: string): Promise<any>;
|
||||
|
@ -45,6 +46,7 @@ export class Workbench {
|
|||
readonly terminal: Terminal;
|
||||
readonly notebook: Notebook;
|
||||
readonly localization: Localization;
|
||||
readonly task: Task;
|
||||
|
||||
constructor(code: Code) {
|
||||
this.editors = new Editors(code);
|
||||
|
@ -64,5 +66,6 @@ export class Workbench {
|
|||
this.terminal = new Terminal(code, this.quickaccess, this.quickinput);
|
||||
this.notebook = new Notebook(this.quickaccess, code);
|
||||
this.localization = new Localization(code);
|
||||
this.task = new Task(code, this.editor, this.editors, this.quickaccess, this.quickinput, this.terminal);
|
||||
}
|
||||
}
|
||||
|
|
71
test/smoke/src/areas/task/task-quick-pick.test.ts
Normal file
71
test/smoke/src/areas/task/task-quick-pick.test.ts
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Application, Task, Terminal, TerminalCommandId } from '../../../../automation/';
|
||||
|
||||
export function setup() {
|
||||
describe('Task Quick Pick', () => {
|
||||
let app: Application;
|
||||
let task: Task;
|
||||
let terminal: Terminal;
|
||||
|
||||
// Acquire automation API
|
||||
before(async function () {
|
||||
app = this.app as Application;
|
||||
task = app.workbench.task;
|
||||
terminal = app.workbench.terminal;
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
// Kill all terminals between every test for a consistent testing environment
|
||||
await terminal.runCommand(TerminalCommandId.KillAll);
|
||||
});
|
||||
|
||||
describe('Tasks: Run Task', () => {
|
||||
const label = "name";
|
||||
const type = "shell";
|
||||
const command = "echo 'test'";
|
||||
it('hide property - true', async () => {
|
||||
await task.configureTask({ type, command, label, hide: true });
|
||||
await task.assertTasks(label, [], 'run');
|
||||
});
|
||||
it('hide property - false', async () => {
|
||||
await task.configureTask({ type, command, label, hide: false });
|
||||
await task.assertTasks(label, [{ label }], 'run');
|
||||
});
|
||||
it('hide property - undefined', async () => {
|
||||
await task.configureTask({ type, command, label });
|
||||
await task.assertTasks(label, [{ label }], 'run');
|
||||
});
|
||||
it('icon - icon only', async () => {
|
||||
const config = { label, type, command, icon: { id: "lightbulb" } };
|
||||
await task.configureTask(config);
|
||||
await task.assertTasks(label, [config], 'run');
|
||||
});
|
||||
it('icon - color only', async () => {
|
||||
const config = { label, type, command, icon: { color: "terminal.ansiRed" } };
|
||||
await task.configureTask(config);
|
||||
await task.assertTasks(label, [{ label, type, command, icon: { color: "Red" } }], 'run');
|
||||
});
|
||||
it('icon - icon & color', async () => {
|
||||
const config = { label, type, command, icon: { id: "lightbulb", color: "terminal.ansiRed" } };
|
||||
await task.configureTask(config);
|
||||
await task.assertTasks(label, [{ label, type, command, icon: { id: "lightbulb", color: "Red" } }], 'run');
|
||||
});
|
||||
});
|
||||
//TODO: why won't this command run
|
||||
describe.skip('Tasks: Configure Task', () => {
|
||||
const label = "name";
|
||||
const type = "shell";
|
||||
const command = "echo 'test'";
|
||||
describe('hide', () => {
|
||||
it('true should still show the task', async () => {
|
||||
await task.configureTask({ type, command, label, hide: true });
|
||||
await task.assertTasks(label, [{ label }], 'configure');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
22
test/smoke/src/areas/task/task.test.ts
Normal file
22
test/smoke/src/areas/task/task.test.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Logger } from '../../../../automation';
|
||||
import { installAllHandlers } from '../../utils';
|
||||
import { setup as setupTaskQuickPickTests } from './task-quick-pick.test';
|
||||
|
||||
export function setup(logger: Logger) {
|
||||
describe('Task', function () {
|
||||
|
||||
// Retry tests 3 times to minimize build failures due to any flakiness
|
||||
this.retries(3);
|
||||
|
||||
// Shared before/after handling
|
||||
installAllHandlers(logger);
|
||||
|
||||
|
||||
setupTaskQuickPickTests();
|
||||
});
|
||||
}
|
|
@ -27,6 +27,7 @@ import { setup as setupMultirootTests } from './areas/multiroot/multiroot.test';
|
|||
import { setup as setupLocalizationTests } from './areas/workbench/localization.test';
|
||||
import { setup as setupLaunchTests } from './areas/workbench/launch.test';
|
||||
import { setup as setupTerminalTests } from './areas/terminal/terminal.test';
|
||||
import { setup as setupTaskTests } from './areas/task/task.test';
|
||||
|
||||
const rootPath = path.join(__dirname, '..', '..', '..');
|
||||
|
||||
|
@ -401,6 +402,7 @@ describe(`VSCode Smoke Tests (${opts.web ? 'Web' : 'Electron'})`, () => {
|
|||
setupNotebookTests(logger);
|
||||
setupLanguagesTests(logger);
|
||||
if (opts.web) { setupTerminalTests(logger); } // Not stable on desktop/remote https://github.com/microsoft/vscode/issues/146811
|
||||
setupTaskTests(logger);
|
||||
setupStatusbarTests(logger);
|
||||
if (quality !== Quality.Dev && quality !== Quality.OSS) { setupExtensionTests(logger); }
|
||||
setupMultirootTests(logger);
|
||||
|
|
Loading…
Reference in a new issue