提交 03e65ebe 编写于 作者: M Matt Bierner

Use await/async in tests

上级 6d521405
......@@ -39,20 +39,18 @@ suite('commands namespace tests', () => {
}, done);
});
test('command with args', function () {
test('command with args', async function () {
let args: IArguments;
let registration = commands.registerCommand('t1', function () {
args = arguments;
});
return commands.executeCommand('t1', 'start').then(() => {
registration.dispose();
assert.ok(args);
assert.equal(args.length, 1);
assert.equal(args[0], 'start');
});
await commands.executeCommand('t1', 'start');
registration.dispose();
assert.ok(args!);
assert.equal(args!.length, 1);
assert.equal(args![0], 'start');
});
test('editorCommand with extra args', function () {
......@@ -76,7 +74,7 @@ suite('commands namespace tests', () => {
});
test('api-command: vscode.previewHtml', function () {
test('api-command: vscode.previewHtml', async function () {
let registration = workspace.registerTextDocumentContentProvider('speciale', {
provideTextDocumentContent(uri) {
......@@ -87,10 +85,9 @@ suite('commands namespace tests', () => {
let virtualDocumentUri = Uri.parse('speciale://authority/path');
let title = 'A title';
return commands.executeCommand('vscode.previewHtml', virtualDocumentUri, ViewColumn.Three, title).then(success => {
assert.ok(success);
registration.dispose();
});
const success = await commands.executeCommand('vscode.previewHtml', virtualDocumentUri, ViewColumn.Three, title);
assert.ok(success);
registration.dispose();
});
......
......@@ -77,7 +77,7 @@ suite('languages namespace tests', () => {
assert.ok(found);
});
test('diagnostics & CodeActionProvider', function () {
test('diagnostics & CodeActionProvider', async function () {
class D2 extends vscode.Diagnostic {
customProp = { complex() { } };
......@@ -117,15 +117,13 @@ suite('languages namespace tests', () => {
let r4 = vscode.languages.createDiagnosticCollection();
r4.set(uri, [diag2]);
return vscode.workspace.openTextDocument(uri).then(_doc => {
return vscode.commands.executeCommand('vscode.executeCodeActionProvider', uri, new vscode.Range(0, 0, 0, 10));
}).then(_commands => {
assert.ok(ran);
vscode.Disposable.from(r1, r2, r3, r4).dispose();
});
await vscode.workspace.openTextDocument(uri);
await vscode.commands.executeCommand('vscode.executeCodeActionProvider', uri, new vscode.Range(0, 0, 0, 10));
assert.ok(ran);
vscode.Disposable.from(r1, r2, r3, r4).dispose();
});
test('completions with document filters', function () {
test('completions with document filters', async function () {
let ran = false;
let uri = vscode.Uri.file(join(vscode.workspace.rootPath || '', './bower.json'));
......@@ -140,12 +138,10 @@ suite('languages namespace tests', () => {
}
});
return vscode.workspace.openTextDocument(uri).then(_doc => {
return vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', uri, new vscode.Position(1, 0));
}).then((result: vscode.CompletionList | undefined) => {
r1.dispose();
assert.ok(ran);
assert.equal(result!.items[0].label, 'foo');
});
const _doc = await vscode.workspace.openTextDocument(uri);
const result = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', uri, new vscode.Position(1, 0));
r1.dispose();
assert.ok(ran);
assert.equal(result!.items[0].label, 'foo');
});
});
......@@ -12,14 +12,12 @@ suite('window namespace tests', () => {
teardown(closeAllEditors);
test('editor, active text editor', () => {
return workspace.openTextDocument(join(workspace.rootPath || '', './far.js')).then(doc => {
return window.showTextDocument(doc).then((_editor) => {
const active = window.activeTextEditor;
assert.ok(active);
assert.ok(pathEquals(active!.document.uri.fsPath, doc.uri.fsPath));
});
});
test('editor, active text editor', async () => {
const doc = await workspace.openTextDocument(join(workspace.rootPath || '', './far.js'));
await window.showTextDocument(doc);
const active = window.activeTextEditor;
assert.ok(active);
assert.ok(pathEquals(active!.document.uri.fsPath, doc.uri.fsPath));
});
test('editor, opened via resource', () => {
......@@ -36,47 +34,37 @@ suite('window namespace tests', () => {
// assert.ok(window.activeTextEditor === undefined);
// });
test('editor, assign and check view columns', () => {
return workspace.openTextDocument(join(workspace.rootPath || '', './far.js')).then(doc => {
let p1 = window.showTextDocument(doc, ViewColumn.One).then(editor => {
assert.equal(editor.viewColumn, ViewColumn.One);
});
let p2 = window.showTextDocument(doc, ViewColumn.Two).then(editor => {
assert.equal(editor.viewColumn, ViewColumn.Two);
});
let p3 = window.showTextDocument(doc, ViewColumn.Three).then(editor => {
assert.equal(editor.viewColumn, ViewColumn.Three);
});
return Promise.all([p1, p2, p3]);
test('editor, assign and check view columns', async () => {
const doc = await workspace.openTextDocument(join(workspace.rootPath || '', './far.js'));
let p1 = window.showTextDocument(doc, ViewColumn.One).then(editor => {
assert.equal(editor.viewColumn, ViewColumn.One);
});
let p2 = window.showTextDocument(doc, ViewColumn.Two).then(editor_1 => {
assert.equal(editor_1.viewColumn, ViewColumn.Two);
});
let p3 = window.showTextDocument(doc, ViewColumn.Three).then(editor_2 => {
assert.equal(editor_2.viewColumn, ViewColumn.Three);
});
return Promise.all([p1, p2, p3]);
});
test('editor, onDidChangeVisibleTextEditors', () => {
test('editor, onDidChangeVisibleTextEditors', async () => {
let eventCounter = 0;
let reg = window.onDidChangeVisibleTextEditors(_editor => {
eventCounter += 1;
});
return workspace.openTextDocument(join(workspace.rootPath || '', './far.js')).then(doc => {
return window.showTextDocument(doc, ViewColumn.One).then(_editor => {
assert.equal(eventCounter, 1);
return doc;
});
}).then(doc => {
return window.showTextDocument(doc, ViewColumn.Two).then(_editor => {
assert.equal(eventCounter, 2);
return doc;
});
}).then(doc => {
return window.showTextDocument(doc, ViewColumn.Three).then(_editor => {
assert.equal(eventCounter, 3);
return doc;
});
}).then(_doc => {
reg.dispose();
});
const doc = await workspace.openTextDocument(join(workspace.rootPath || '', './far.js'));
await window.showTextDocument(doc, ViewColumn.One);
assert.equal(eventCounter, 1);
await window.showTextDocument(doc, ViewColumn.Two);
assert.equal(eventCounter, 2);
await window.showTextDocument(doc, ViewColumn.Three);
assert.equal(eventCounter, 3);
reg.dispose();
});
test('editor, onDidChangeTextEditorViewColumn (close editor)', () => {
......@@ -92,28 +80,24 @@ suite('window namespace tests', () => {
return Promise.all([
workspace.openTextDocument(Uri.parse('bikes://testing/one')).then(doc => window.showTextDocument(doc, ViewColumn.One)),
workspace.openTextDocument(Uri.parse('bikes://testing/two')).then(doc => window.showTextDocument(doc, ViewColumn.Two))
]).then(editors => {
]).then(async editors => {
let [one, two] = editors;
return new Promise(resolve => {
await new Promise(resolve => {
let registration2 = window.onDidChangeTextEditorViewColumn(event => {
actualEvent = event;
registration2.dispose();
resolve();
});
// close editor 1, wait a little for the event to bubble
one.hide();
}).then(() => {
assert.ok(actualEvent);
assert.ok(actualEvent.textEditor === two);
assert.ok(actualEvent.viewColumn === two.viewColumn);
registration1.dispose();
});
assert.ok(actualEvent);
assert.ok(actualEvent.textEditor === two);
assert.ok(actualEvent.viewColumn === two.viewColumn);
registration1.dispose();
});
});
......@@ -340,22 +324,20 @@ suite('window namespace tests', () => {
source.dispose();
});
test('showInputBox - undefined on cancel', function () {
test('showInputBox - undefined on cancel', async function () {
const source = new CancellationTokenSource();
const p = window.showInputBox(undefined, source.token);
source.cancel();
return p.then(value => {
assert.equal(value, undefined);
});
const value = await p;
assert.equal(value, undefined);
});
test('showInputBox - cancel early', function () {
test('showInputBox - cancel early', async function () {
const source = new CancellationTokenSource();
source.cancel();
const p = window.showInputBox(undefined, source.token);
return p.then(value => {
assert.equal(value, undefined);
});
const value = await p;
assert.equal(value, undefined);
});
test('showInputBox - \'\' on Enter', function () {
......@@ -509,7 +491,7 @@ suite('window namespace tests', () => {
return result;
});
test('showQuickPick, native promise - #11754', function () {
test('showQuickPick, native promise - #11754', async function () {
const data = new Promise<string[]>(resolve => {
resolve(['a', 'b', 'c']);
......@@ -518,9 +500,8 @@ suite('window namespace tests', () => {
const source = new CancellationTokenSource();
const result = window.showQuickPick(data, undefined, source.token);
source.cancel();
return result.then(value => {
assert.equal(value, undefined);
});
const value_1 = await result;
assert.equal(value_1, undefined);
});
test('showQuickPick, never resolve promise and cancel - #22453', function () {
......@@ -534,16 +515,17 @@ suite('window namespace tests', () => {
return Promise.all([a, b]);
});
test('showWorkspaceFolderPick', function () {
test('showWorkspaceFolderPick', async function () {
const p = window.showWorkspaceFolderPick(undefined);
return commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem').then(() => {
return p.then(_workspace => {
assert.ok(true);
}, _error => {
assert.ok(false);
});
});
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
try {
await p;
assert.ok(true);
}
catch (_error) {
assert.ok(false);
}
});
test('Default value for showInput Box not accepted when it fails validateInput, reversing #33691', async function () {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册