Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoke tests: Adding acceptance condition to dispatchKey #239902

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/automation/src/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export class Code {
return await this.driver.stopTracing(name, persist);
}

async dispatchKeybinding(keybinding: string): Promise<void> {
await this.driver.dispatchKeybinding(keybinding);
async dispatchKeybinding(keybinding: string, acceptFn: () => Promise<void> | void): Promise<void> {
await this.driver.dispatchKeybinding(keybinding, acceptFn);
}

async didFinishLoad(): Promise<void> {
Expand Down
23 changes: 13 additions & 10 deletions test/automation/src/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ export class Debug extends Viewlet {
}

async openDebugViewlet(): Promise<any> {
const acceptFn = async () => {
await this.code.waitForElement(DEBUG_VIEW);
};
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+shift+d');
await this.code.dispatchKeybinding('cmd+shift+d', acceptFn);
} else {
await this.code.dispatchKeybinding('ctrl+shift+d');
await this.code.dispatchKeybinding('ctrl+shift+d', acceptFn);
}

await this.code.waitForElement(DEBUG_VIEW);
}

async configure(): Promise<any> {
Expand All @@ -79,9 +80,10 @@ export class Debug extends Viewlet {
}

async startDebugging(): Promise<number> {
await this.code.dispatchKeybinding('f5');
await this.code.waitForElement(PAUSE);
await this.code.waitForElement(DEBUG_STATUS_BAR);
await this.code.dispatchKeybinding('f5', async () => {
await this.code.waitForElement(PAUSE);
await this.code.waitForElement(DEBUG_STATUS_BAR);
});
const portPrefix = 'Port: ';

const output = await this.waitForOutput(output => output.some(line => line.indexOf(portPrefix) >= 0));
Expand Down Expand Up @@ -135,9 +137,10 @@ export class Debug extends Viewlet {

// Wait for the keys to be picked up by the editor model such that repl evaluates what just got typed
await this.editor.waitForEditorContents('debug:replinput', s => s.indexOf(text) >= 0);
await this.code.dispatchKeybinding('enter');
await this.code.waitForElements(CONSOLE_EVALUATION_RESULT, false,
elements => !!elements.length && accept(elements[elements.length - 1].textContent));
await this.code.dispatchKeybinding('enter', async () => {
await this.code.waitForElements(CONSOLE_EVALUATION_RESULT, false,
elements => !!elements.length && accept(elements[elements.length - 1].textContent));
});
}

// Different node versions give different number of variables. As a workaround be more relaxed when checking for variable count
Expand Down
2 changes: 1 addition & 1 deletion test/automation/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Editor {
await this.code.waitForActiveElement(RENAME_INPUT);
await this.code.waitForSetValue(RENAME_INPUT, to);

await this.code.dispatchKeybinding('enter');
await this.code.dispatchKeybinding('enter', () => { });
}

async gotoDefinition(filename: string, term: string, line: number): Promise<void> {
Expand Down
14 changes: 6 additions & 8 deletions test/automation/src/editors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class Editors {

async saveOpenedFile(): Promise<any> {
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+s');
await this.code.dispatchKeybinding('cmd+s', () => { });
} else {
await this.code.dispatchKeybinding('ctrl+s');
await this.code.dispatchKeybinding('ctrl+s', () => { });
}
}

Expand All @@ -29,10 +29,8 @@ export class Editors {
let retries = 0;
while (retries < 10) {
await this.code.waitAndClick(`.tabs-container div.tab[data-resource-name$="${fileName}"]`);
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+1' : 'ctrl+1'); // make editor really active if click failed somehow

try {
await this.waitForEditorFocus(fileName, 50 /* 50 retries * 100ms delay = 5s */);
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+1' : 'ctrl+1', () => this.waitForEditorFocus(fileName, 50 /* 50 retries * 100ms delay = 5s */));
return;
} catch (e) {
error = e;
Expand Down Expand Up @@ -63,12 +61,12 @@ export class Editors {
}

async newUntitledFile(): Promise<void> {
const acceptFn = () => this.waitForEditorFocus('Untitled-1');
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+n');
await this.code.dispatchKeybinding('cmd+n', acceptFn);
} else {
await this.code.dispatchKeybinding('ctrl+n');
await this.code.dispatchKeybinding('ctrl+n', acceptFn);
}

await this.waitForEditorFocus('Untitled-1');
}
}
4 changes: 2 additions & 2 deletions test/automation/src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class Explorer extends Viewlet {

async openExplorerView(): Promise<any> {
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+shift+e');
await this.code.dispatchKeybinding('cmd+shift+e', () => { });
} else {
await this.code.dispatchKeybinding('ctrl+shift+e');
await this.code.dispatchKeybinding('ctrl+shift+e', () => { });
}
}

Expand Down
15 changes: 6 additions & 9 deletions test/automation/src/keybindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ export class KeybindingsEditor {
constructor(private code: Code) { }

async updateKeybinding(command: string, commandName: string | undefined, keybinding: string, keybindingTitle: string): Promise<any> {
const acceptFn = async () => this.code.waitForActiveElement(SEARCH_INPUT);
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+k cmd+s');
await this.code.dispatchKeybinding('cmd+k cmd+s', acceptFn);
} else {
await this.code.dispatchKeybinding('ctrl+k ctrl+s');
await this.code.dispatchKeybinding('ctrl+k ctrl+s', acceptFn);
}

await this.code.waitForActiveElement(SEARCH_INPUT);
await this.code.waitForSetValue(SEARCH_INPUT, `@command:${command}`);

const commandTitle = commandName ? `${commandName} (${command})` : command;
await this.code.waitAndClick(`.keybindings-table-container .monaco-list-row .command[aria-label="${commandTitle}"]`);
await this.code.waitForElement(`.keybindings-table-container .monaco-list-row.focused.selected .command[aria-label="${commandTitle}"]`);
await this.code.dispatchKeybinding('enter');

await this.code.waitForActiveElement('.defineKeybindingWidget .monaco-inputbox input');
await this.code.dispatchKeybinding(keybinding);
await this.code.dispatchKeybinding('enter');
await this.code.waitForElement(`.keybindings-table-container .keybinding-label div[aria-label="${keybindingTitle}"]`);
await this.code.dispatchKeybinding('enter', () => this.code.waitForActiveElement('.defineKeybindingWidget .monaco-inputbox input'));
await this.code.dispatchKeybinding(keybinding, () => { });
await this.code.dispatchKeybinding('enter', async () => { await this.code.waitForElement(`.keybindings-table-container .keybinding-label div[aria-label="${keybindingTitle}"]`); });
}
}
4 changes: 2 additions & 2 deletions test/automation/src/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export class Notebook {
}

async focusNextCell() {
await this.code.dispatchKeybinding('down');
await this.code.dispatchKeybinding('down', () => { });
}

async focusFirstCell() {
await this.quickAccess.runCommand('notebook.focusTop');
}

async editCell() {
await this.code.dispatchKeybinding('enter');
await this.code.dispatchKeybinding('enter', () => { });
}

async stopEditingCell() {
Expand Down
3 changes: 1 addition & 2 deletions test/automation/src/peek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ export class References {
// Sometimes someone else eats up the `Escape` key
let count = 0;
while (true) {
await this.code.dispatchKeybinding('escape');

try {
await this.code.waitForElement(References.REFERENCES_WIDGET, el => !el, 10);
await this.code.dispatchKeybinding('escape', async () => { await this.code.waitForElement(References.REFERENCES_WIDGET, el => !el, 10); });
return;
} catch (err) {
if (++count > 5) {
Expand Down
4 changes: 2 additions & 2 deletions test/automation/src/playwrightDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class PlaywrightDriver {
}
}

async dispatchKeybinding(keybinding: string) {
async dispatchKeybinding(keybinding: string, acceptFn: () => Promise<void> | void) {
const chords = keybinding.split(' ');
for (let i = 0; i < chords.length; i++) {
const chord = chords[i];
Expand All @@ -256,7 +256,7 @@ export class PlaywrightDriver {
}
}

await this.wait(100);
await acceptFn();
}

async click(selector: string, xoffset?: number | undefined, yoffset?: number | undefined) {
Expand Down
30 changes: 14 additions & 16 deletions test/automation/src/quickaccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,30 +137,28 @@ export class QuickAccess {
// Other parts of code might steal focus away from quickinput :(
while (retries < 5) {

// Open via keybinding
switch (kind) {
case QuickAccessKind.Files:
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+p' : 'ctrl+p');
break;
case QuickAccessKind.Symbols:
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+shift+o' : 'ctrl+shift+o');
break;
case QuickAccessKind.Commands:
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+shift+p' : 'ctrl+shift+p');
break;
}

// Await for quick input widget opened
try {
await this.quickInput.waitForQuickInputOpened(10);
const acceptFn = () => this.quickInput.waitForQuickInputOpened(10);
// Open via keybinding
switch (kind) {
case QuickAccessKind.Files:
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+p' : 'ctrl+p', acceptFn);
break;
case QuickAccessKind.Symbols:
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+shift+o' : 'ctrl+shift+o', acceptFn);
break;
case QuickAccessKind.Commands:
await this.code.dispatchKeybinding(process.platform === 'darwin' ? 'cmd+shift+p' : 'ctrl+shift+p', acceptFn);
break;
}
break;
} catch (err) {
if (++retries > 5) {
throw new Error(`QuickAccess.openQuickAccessWithRetry(kind: ${kind}) failed: ${err}`);
}

// Retry
await this.code.dispatchKeybinding('escape');
await this.code.dispatchKeybinding('escape', () => { });
}
}

Expand Down
14 changes: 7 additions & 7 deletions test/automation/src/quickinput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export class QuickInput {
}

async closeQuickInput(): Promise<void> {
await this.code.dispatchKeybinding('escape');
await this.waitForQuickInputClosed();
await this.code.dispatchKeybinding('escape', () => this.waitForQuickInputClosed());
}

async waitForQuickInputElements(accept: (names: string[]) => boolean): Promise<void> {
Expand All @@ -49,11 +48,12 @@ export class QuickInput {
async selectQuickInputElement(index: number, keepOpen?: boolean): Promise<void> {
await this.waitForQuickInputOpened();
for (let from = 0; from < index; from++) {
await this.code.dispatchKeybinding('down');
}
await this.code.dispatchKeybinding('enter');
if (!keepOpen) {
await this.waitForQuickInputClosed();
await this.code.dispatchKeybinding('down', () => { });
}
await this.code.dispatchKeybinding('enter', async () => {
if (!keepOpen) {
await this.waitForQuickInputClosed();
}
});
}
}
3 changes: 1 addition & 2 deletions test/automation/src/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export class SCM extends Viewlet {
}

async openSCMViewlet(): Promise<any> {
await this.code.dispatchKeybinding('ctrl+shift+g');
await this.code.waitForElement(this._editContextSelector());
await this.code.dispatchKeybinding('ctrl+shift+g', async () => { await this.code.waitForElement(this._editContextSelector()); });
}

async waitForChange(name: string, type?: string): Promise<void> {
Expand Down
14 changes: 6 additions & 8 deletions test/automation/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ export class Search extends Viewlet {
}

async openSearchViewlet(): Promise<any> {
const acceptFn = async () => await this.waitForInputFocus(INPUT);
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+shift+f');
await this.code.dispatchKeybinding('cmd+shift+f', acceptFn);
} else {
await this.code.dispatchKeybinding('ctrl+shift+f');
await this.code.dispatchKeybinding('ctrl+shift+f', acceptFn);
}

await this.waitForInputFocus(INPUT);
}

async getSearchTooltip(): Promise<any> {
Expand All @@ -69,18 +68,17 @@ export class Search extends Viewlet {
}

async waitForPageUp(): Promise<void> {
await this.code.dispatchKeybinding('PageUp');
await this.code.dispatchKeybinding('PageUp', () => { });
}

async waitForPageDown(): Promise<void> {
await this.code.dispatchKeybinding('PageDown');
await this.code.dispatchKeybinding('PageDown', () => { });
}

async submitSearch(): Promise<void> {
await this.waitForInputFocus(INPUT);

await this.code.dispatchKeybinding('enter');
await this.code.waitForElement(`${VIEWLET} .messages`);
await this.code.dispatchKeybinding('enter', async () => { await this.code.waitForElement(`${VIEWLET} .messages`); });
}

async setFilesToIncludeText(text: string): Promise<void> {
Expand Down
24 changes: 14 additions & 10 deletions test/automation/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export class SettingsEditor {
async addUserSetting(setting: string, value: string): Promise<void> {
await this.openUserSettingsFile();

await this.code.dispatchKeybinding('right');
await this.editor.waitForEditorSelection('settings.json', (s) => this._acceptEditorSelection(this.code.quality, s));
await this.code.dispatchKeybinding('right', async () => {
await this.editor.waitForEditorSelection('settings.json', (s) => this._acceptEditorSelection(this.code.quality, s));
});
await this.editor.waitForTypeInEditor('settings.json', `"${setting}": ${value},`);
await this.editors.saveOpenedFile();
}
Expand All @@ -39,17 +40,19 @@ export class SettingsEditor {
async addUserSettings(settings: [key: string, value: string][]): Promise<void> {
await this.openUserSettingsFile();

await this.code.dispatchKeybinding('right');
await this.editor.waitForEditorSelection('settings.json', (s) => this._acceptEditorSelection(this.code.quality, s));
await this.code.dispatchKeybinding('right', async () => {
await this.editor.waitForEditorSelection('settings.json', (s) => this._acceptEditorSelection(this.code.quality, s));
});
await this.editor.waitForTypeInEditor('settings.json', settings.map(v => `"${v[0]}": ${v[1]},`).join(''));
await this.editors.saveOpenedFile();
}

async clearUserSettings(): Promise<void> {
await this.openUserSettingsFile();
await this.quickaccess.runCommand('editor.action.selectAll');
await this.code.dispatchKeybinding('Delete');
await this.editor.waitForEditorContents('settings.json', contents => contents === '');
await this.code.dispatchKeybinding('Delete', async () => {
await this.editor.waitForEditorContents('settings.json', contents => contents === '');
});
await this.editor.waitForTypeInEditor('settings.json', `{`); // will auto close }
await this.editors.saveOpenedFile();
await this.quickaccess.runCommand('workbench.action.closeActiveEditor');
Expand All @@ -70,12 +73,13 @@ export class SettingsEditor {

await this.code.waitAndClick(this._editContextSelector());
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+a');
await this.code.dispatchKeybinding('cmd+a', () => { });
} else {
await this.code.dispatchKeybinding('ctrl+a');
await this.code.dispatchKeybinding('ctrl+a', () => { });
}
await this.code.dispatchKeybinding('Delete');
await this.code.waitForElements('.settings-editor .settings-count-widget', false, results => !results || (results?.length === 1 && !results[0].textContent));
await this.code.dispatchKeybinding('Delete', async () => {
await this.code.waitForElements('.settings-editor .settings-count-widget', false, results => !results || (results?.length === 1 && !results[0].textContent));
});
await this.code.waitForTypeInEditor(this._editContextSelector(), query);
await this.code.waitForElements('.settings-editor .settings-count-widget', false, results => results?.length === 1 && results[0].textContent.includes('Found'));
}
Expand Down
6 changes: 3 additions & 3 deletions test/automation/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Task {
}

async assertTasks(filter: string, expected: ITaskConfigurationProperties[], type: 'run' | 'configure') {
await this.code.dispatchKeybinding('right');
await this.code.dispatchKeybinding('right', () => { });
await this.editors.saveOpenedFile();
type === 'run' ? await this.quickaccess.runCommand('workbench.action.tasks.runTask', { keepOpen: true }) : await this.quickaccess.runCommand('workbench.action.tasks.configureTask', { keepOpen: true });
if (expected.length === 0) {
Expand All @@ -57,7 +57,7 @@ export class Task {
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');
await this.code.dispatchKeybinding('Delete', () => { });
const taskStringLines: string[] = [
'{', // Brackets auto close
'"version": "2.0.0",',
Expand All @@ -78,7 +78,7 @@ export class Task {
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.code.dispatchKeybinding('Enter', () => { });
}
}
await this.editors.saveOpenedFile();
Expand Down
Loading
Loading