mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:28:52 +01:00
Use await/async in tests
This commit is contained in:
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user