Fix tests (fixes #70887)

This commit is contained in:
Christof Marti 2020-06-22 14:02:42 +02:00
parent a8dd98d6a1
commit 4242275cb1

View file

@ -4,11 +4,11 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { workspace, window, commands, ViewColumn, TextEditorViewColumnChangeEvent, Uri, Selection, Position, CancellationTokenSource, TextEditorSelectionChangeKind } from 'vscode';
import { workspace, window, commands, ViewColumn, TextEditorViewColumnChangeEvent, Uri, Selection, Position, CancellationTokenSource, TextEditorSelectionChangeKind, QuickPickItem } from 'vscode';
import { join } from 'path';
import { closeAllEditors, pathEquals, createRandomFile } from '../utils';
suite('vscode API - window', () => {
suite.only('vscode API - window', () => {
teardown(closeAllEditors);
@ -383,33 +383,31 @@ suite('vscode API - window', () => {
assert.equal(await two, 'notempty');
});
// TODO@chrmarti Disabled due to flaky behaviour (https://github.com/Microsoft/vscode/issues/70887)
// test('showQuickPick, accept first', async function () {
// const pick = window.showQuickPick(['eins', 'zwei', 'drei']);
// await new Promise(resolve => setTimeout(resolve, 10)); // Allow UI to update.
// await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
// assert.equal(await pick, 'eins');
// });
test('showQuickPick, accept second', async function () {
const resolves: ((value: string) => void)[] = [];
let done: () => void;
const unexpected = new Promise((resolve, reject) => {
done = () => resolve();
resolves.push(reject);
});
const first = new Promise(resolve => resolves.push(resolve));
test('showQuickPick, accept first', async function () {
const tracker = createQuickPickTracker<string>();
const first = tracker.nextItem();
const pick = window.showQuickPick(['eins', 'zwei', 'drei'], {
onDidSelectItem: item => resolves.pop()!(item as string)
onDidSelectItem: tracker.onDidSelectItem
});
assert.equal(await first, 'eins');
const second = new Promise(resolve => resolves.push(resolve));
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick, 'eins');
return tracker.done();
});
test('showQuickPick, accept second', async function () {
const tracker = createQuickPickTracker<string>();
const first = tracker.nextItem();
const pick = window.showQuickPick(['eins', 'zwei', 'drei'], {
onDidSelectItem: tracker.onDidSelectItem
});
assert.equal(await first, 'eins');
const second = tracker.nextItem();
await commands.executeCommand('workbench.action.quickOpenSelectNext');
assert.equal(await second, 'zwei');
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick, 'zwei');
done!();
return unexpected;
return tracker.done();
});
test('showQuickPick, select first two', async function () {
@ -438,19 +436,22 @@ suite('vscode API - window', () => {
return unexpected;
});
// TODO@chrmarti Disabled due to flaky behaviour (https://github.com/Microsoft/vscode/issues/70887)
// test('showQuickPick, keep selection (Microsoft/vscode-azure-account#67)', async function () {
// const picks = window.showQuickPick([
// { label: 'eins' },
// { label: 'zwei', picked: true },
// { label: 'drei', picked: true }
// ], {
// canPickMany: true
// });
// await new Promise(resolve => setTimeout(resolve, 10)); // Allow UI to update.
// await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
// assert.deepStrictEqual((await picks)!.map(pick => pick.label), ['zwei', 'drei']);
// });
test('showQuickPick, keep selection (Microsoft/vscode-azure-account#67)', async function () {
const tracker = createQuickPickTracker<string>();
const first = tracker.nextItem();
const picks = window.showQuickPick([
{ label: 'eins' },
{ label: 'zwei', picked: true },
{ label: 'drei', picked: true }
], {
onDidSelectItem: tracker.onDidSelectItem,
canPickMany: true
});
assert.equal(await first, 'eins');
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.deepStrictEqual((await picks)!.map(pick => pick.label), ['zwei', 'drei']);
return tracker.done();
});
test('showQuickPick, undefined on cancel', function () {
const source = new CancellationTokenSource();
@ -521,20 +522,24 @@ suite('vscode API - window', () => {
return Promise.all([a, b]);
});
// TODO@chrmarti Disabled due to flaky behaviour (https://github.com/Microsoft/vscode/issues/70887)
// test('showWorkspaceFolderPick', async function () {
// const p = window.showWorkspaceFolderPick(undefined);
test('showWorkspaceFolderPick', async function () {
const p = window.showWorkspaceFolderPick(undefined);
// await timeout(10);
// await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
// try {
// await p;
// assert.ok(true);
// }
// catch (_error) {
// assert.ok(false);
// }
// });
await new Promise(resolve => setTimeout(resolve, 10));
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
const r1 = await Promise.race([p, new Promise<boolean>(resolve => setTimeout(() => resolve(false), 100))]);
if (r1 !== false) {
return;
}
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
const r2 = await Promise.race([p, new Promise<boolean>(resolve => setTimeout(() => resolve(false), 1000))]);
if (r2 !== false) {
return;
}
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
const r3 = await Promise.race([p, new Promise<boolean>(resolve => setTimeout(() => resolve(false), 1000))]);
assert.ok(r3 !== false);
});
test('Default value for showInput Box not accepted when it fails validateInput, reversing #33691', async function () {
const result = window.showInputBox({
@ -551,6 +556,23 @@ suite('vscode API - window', () => {
assert.equal(await result, undefined);
});
function createQuickPickTracker<T extends string | QuickPickItem>() {
const resolves: ((value: T) => void)[] = [];
let done: () => void;
const unexpected = new Promise((resolve, reject) => {
done = () => resolve();
resolves.push(reject);
});
return {
onDidSelectItem: (item: T) => resolves.pop()!(item),
nextItem: () => new Promise<T>(resolve => resolves.push(resolve)),
done: () => {
done!();
return unexpected;
},
};
}
test('editor, selection change kind', () => {
return workspace.openTextDocument(join(workspace.rootPath || '', './far.js')).then(doc => window.showTextDocument(doc)).then(editor => {