mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 00:59:03 +01:00
Merge branch 'master' into tyriar/90539
This commit is contained in:
@@ -8,7 +8,7 @@ import * as assert from 'assert';
|
||||
import { join } from 'path';
|
||||
import { commands, workspace, window, Uri, Range, Position, ViewColumn } from 'vscode';
|
||||
|
||||
suite('commands namespace tests', () => {
|
||||
suite('vscode API - commands', () => {
|
||||
|
||||
test('getCommands', function (done) {
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
suite('Configuration tests', () => {
|
||||
suite('vscode API - configuration', () => {
|
||||
|
||||
test('configurations, language defaults', function () {
|
||||
const defaultLanguageSettings = vscode.workspace.getConfiguration().get('[abcLang]');
|
||||
|
||||
@@ -8,7 +8,7 @@ import { debug, workspace, Disposable, commands, window } from 'vscode';
|
||||
import { disposeAll } from '../utils';
|
||||
import { basename } from 'path';
|
||||
|
||||
suite('Debug', function () {
|
||||
suite('vscode API - debug', function () {
|
||||
|
||||
test('breakpoints', async function () {
|
||||
assert.equal(debug.breakpoints.length, 0);
|
||||
@@ -37,16 +37,24 @@ suite('Debug', function () {
|
||||
disposeAll(toDispose);
|
||||
});
|
||||
|
||||
// @isidor flakey test
|
||||
test.skip('start debugging', async function () {
|
||||
assert.equal(debug.activeDebugSession, undefined);
|
||||
let stoppedEvents = 0;
|
||||
let variablesReceived: () => void;
|
||||
let initializedReceived: () => void;
|
||||
let configurationDoneReceived: () => void;
|
||||
const toDispose: Disposable[] = [];
|
||||
if (debug.activeDebugSession) {
|
||||
// We are re-running due to flakyness, make sure to clear out state
|
||||
let sessionTerminatedRetry: () => void;
|
||||
toDispose.push(debug.onDidTerminateDebugSession(() => {
|
||||
sessionTerminatedRetry();
|
||||
}));
|
||||
const sessionTerminatedPromise = new Promise<void>(resolve => sessionTerminatedRetry = resolve);
|
||||
await commands.executeCommand('workbench.action.debug.stop');
|
||||
await sessionTerminatedPromise;
|
||||
}
|
||||
|
||||
const firstVariablesRetrieved = new Promise<void>(resolve => variablesReceived = resolve);
|
||||
const toDispose: Disposable[] = [];
|
||||
toDispose.push(debug.registerDebugAdapterTrackerFactory('*', {
|
||||
createDebugAdapterTracker: () => ({
|
||||
onDidSendMessage: m => {
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as assert from 'assert';
|
||||
import { workspace, window, Position, Range, commands, TextEditor, TextDocument, TextEditorCursorStyle, TextEditorLineNumbersStyle, SnippetString, Selection, Uri } from 'vscode';
|
||||
import { createRandomFile, deleteFile, closeAllEditors } from '../utils';
|
||||
|
||||
suite('editor tests', () => {
|
||||
suite('vscode API - editors', () => {
|
||||
|
||||
teardown(closeAllEditors);
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as assert from 'assert';
|
||||
import { env, extensions, ExtensionKind, UIKind, Uri } from 'vscode';
|
||||
|
||||
suite('env-namespace', () => {
|
||||
suite('vscode API - env', () => {
|
||||
|
||||
test('env is set', function () {
|
||||
assert.equal(typeof env.language, 'string');
|
||||
|
||||
@@ -8,7 +8,7 @@ import { join } from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import { createRandomFile, testFs } from '../utils';
|
||||
|
||||
suite('languages namespace tests', () => {
|
||||
suite('vscode API - languages', () => {
|
||||
|
||||
const isWindows = process.platform === 'win32';
|
||||
|
||||
|
||||
@@ -18,190 +18,188 @@ interface QuickPickExpected {
|
||||
};
|
||||
}
|
||||
|
||||
suite('window namespace tests', function () {
|
||||
suite('vscode API - quick input', function () {
|
||||
|
||||
suite('QuickInput tests', function () {
|
||||
teardown(closeAllEditors);
|
||||
teardown(closeAllEditors);
|
||||
|
||||
test('createQuickPick, select second', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
test('createQuickPick, select second', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => { };
|
||||
_done(err);
|
||||
};
|
||||
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins'], ['zwei']],
|
||||
selectionItems: [['zwei']],
|
||||
acceptedItems: {
|
||||
active: [['zwei']],
|
||||
selection: [['zwei']],
|
||||
dispose: [true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins'], ['zwei']],
|
||||
selectionItems: [['zwei']],
|
||||
acceptedItems: {
|
||||
active: [['zwei']],
|
||||
selection: [['zwei']],
|
||||
dispose: [true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
test('createQuickPick, focus second', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
test('createQuickPick, focus second', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => { };
|
||||
_done(err);
|
||||
};
|
||||
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['zwei']],
|
||||
selectionItems: [['zwei']],
|
||||
acceptedItems: {
|
||||
active: [['zwei']],
|
||||
selection: [['zwei']],
|
||||
dispose: [true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.activeItems = [quickPick.items[1]];
|
||||
quickPick.show();
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['zwei']],
|
||||
selectionItems: [['zwei']],
|
||||
acceptedItems: {
|
||||
active: [['zwei']],
|
||||
selection: [['zwei']],
|
||||
dispose: [true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.activeItems = [quickPick.items[1]];
|
||||
quickPick.show();
|
||||
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
test('createQuickPick, select first and second', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
test('createQuickPick, select first and second', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => { };
|
||||
_done(err);
|
||||
};
|
||||
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins'], ['zwei']],
|
||||
selectionItems: [['eins'], ['eins', 'zwei']],
|
||||
acceptedItems: {
|
||||
active: [['zwei']],
|
||||
selection: [['eins', 'zwei']],
|
||||
dispose: [true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.canSelectMany = true;
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins'], ['zwei']],
|
||||
selectionItems: [['eins'], ['eins', 'zwei']],
|
||||
acceptedItems: {
|
||||
active: [['zwei']],
|
||||
selection: [['eins', 'zwei']],
|
||||
dispose: [true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.canSelectMany = true;
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
await commands.executeCommand('workbench.action.quickPickManyToggle');
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
await commands.executeCommand('workbench.action.quickPickManyToggle');
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
await commands.executeCommand('workbench.action.quickPickManyToggle');
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
await commands.executeCommand('workbench.action.quickPickManyToggle');
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
test('createQuickPick, selection events', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
test('createQuickPick, selection events', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => { };
|
||||
_done(err);
|
||||
};
|
||||
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'accept', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins']],
|
||||
selectionItems: [['zwei'], ['drei']],
|
||||
acceptedItems: {
|
||||
active: [['eins'], ['eins']],
|
||||
selection: [['zwei'], ['drei']],
|
||||
dispose: [false, true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'accept', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins']],
|
||||
selectionItems: [['zwei'], ['drei']],
|
||||
acceptedItems: {
|
||||
active: [['eins'], ['eins']],
|
||||
selection: [['zwei'], ['drei']],
|
||||
dispose: [false, true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei', 'drei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
|
||||
quickPick.selectedItems = [quickPick.items[1]];
|
||||
setTimeout(() => {
|
||||
quickPick.selectedItems = [quickPick.items[2]];
|
||||
}, 0);
|
||||
});
|
||||
quickPick.selectedItems = [quickPick.items[1]];
|
||||
setTimeout(() => {
|
||||
quickPick.selectedItems = [quickPick.items[2]];
|
||||
}, 0);
|
||||
});
|
||||
|
||||
test('createQuickPick, continue after first accept', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
test('createQuickPick, continue after first accept', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => { };
|
||||
_done(err);
|
||||
};
|
||||
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'accept', 'active', 'selection', 'active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins'], [], ['drei']],
|
||||
selectionItems: [['eins'], [], ['drei']],
|
||||
acceptedItems: {
|
||||
active: [['eins'], ['drei']],
|
||||
selection: [['eins'], ['drei']],
|
||||
dispose: [false, true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
const quickPick = createQuickPick({
|
||||
events: ['active', 'selection', 'accept', 'active', 'selection', 'active', 'selection', 'accept', 'hide'],
|
||||
activeItems: [['eins'], [], ['drei']],
|
||||
selectionItems: [['eins'], [], ['drei']],
|
||||
acceptedItems: {
|
||||
active: [['eins'], ['drei']],
|
||||
selection: [['eins'], ['drei']],
|
||||
dispose: [false, true]
|
||||
},
|
||||
}, (err?: any) => done(err));
|
||||
quickPick.items = ['eins', 'zwei'].map(label => ({ label }));
|
||||
quickPick.show();
|
||||
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
(async () => {
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
await timeout(async () => {
|
||||
quickPick.items = ['drei', 'vier'].map(label => ({ label }));
|
||||
await timeout(async () => {
|
||||
quickPick.items = ['drei', 'vier'].map(label => ({ label }));
|
||||
await timeout(async () => {
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
}, 0);
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
}, 0);
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
}, 0);
|
||||
})()
|
||||
.catch(err => done(err));
|
||||
});
|
||||
|
||||
test('createQuickPick, dispose in onDidHide', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => { };
|
||||
_done(err);
|
||||
};
|
||||
|
||||
let hidden = false;
|
||||
const quickPick = window.createQuickPick();
|
||||
quickPick.onDidHide(() => {
|
||||
if (hidden) {
|
||||
done(new Error('Already hidden'));
|
||||
} else {
|
||||
hidden = true;
|
||||
quickPick.dispose();
|
||||
setTimeout(done, 0);
|
||||
}
|
||||
});
|
||||
quickPick.show();
|
||||
quickPick.hide();
|
||||
});
|
||||
|
||||
test('createQuickPick, dispose in onDidHide', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
test('createQuickPick, hide and dispose', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => { };
|
||||
_done(err);
|
||||
};
|
||||
|
||||
let hidden = false;
|
||||
const quickPick = window.createQuickPick();
|
||||
quickPick.onDidHide(() => {
|
||||
if (hidden) {
|
||||
done(new Error('Already hidden'));
|
||||
} else {
|
||||
hidden = true;
|
||||
quickPick.dispose();
|
||||
setTimeout(done, 0);
|
||||
}
|
||||
});
|
||||
quickPick.show();
|
||||
quickPick.hide();
|
||||
});
|
||||
|
||||
test('createQuickPick, hide and dispose', function (_done) {
|
||||
let done = (err?: any) => {
|
||||
done = () => {};
|
||||
_done(err);
|
||||
};
|
||||
|
||||
let hidden = false;
|
||||
const quickPick = window.createQuickPick();
|
||||
quickPick.onDidHide(() => {
|
||||
if (hidden) {
|
||||
done(new Error('Already hidden'));
|
||||
} else {
|
||||
hidden = true;
|
||||
setTimeout(done, 0);
|
||||
}
|
||||
});
|
||||
quickPick.show();
|
||||
quickPick.hide();
|
||||
quickPick.dispose();
|
||||
let hidden = false;
|
||||
const quickPick = window.createQuickPick();
|
||||
quickPick.onDidHide(() => {
|
||||
if (hidden) {
|
||||
done(new Error('Already hidden'));
|
||||
} else {
|
||||
hidden = true;
|
||||
setTimeout(done, 0);
|
||||
}
|
||||
});
|
||||
quickPick.show();
|
||||
quickPick.hide();
|
||||
quickPick.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -276,4 +274,4 @@ function createQuickPick(expected: QuickPickExpected, done: (err?: any) => void,
|
||||
|
||||
async function timeout<T>(run: () => Promise<T> | T, ms: number): Promise<T> {
|
||||
return new Promise<T>(resolve => setTimeout(() => resolve(run()), ms));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable } from 'vscode';
|
||||
import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable, UIKind, env, EnvironmentVariableMutatorType, EnvironmentVariableMutator } from 'vscode';
|
||||
import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
|
||||
|
||||
suite('window namespace tests', () => {
|
||||
// TODO@Daniel flaky tests (https://github.com/microsoft/vscode/issues/92826)
|
||||
((env.uiKind === UIKind.Web) ? suite.skip : suite)('vscode API - terminal', () => {
|
||||
suiteSetup(async () => {
|
||||
// Disable conpty in integration tests because of https://github.com/microsoft/vscode/issues/76548
|
||||
await workspace.getConfiguration('terminal.integrated').update('windowsEnableConpty', false, ConfigurationTarget.Global);
|
||||
@@ -19,6 +20,7 @@ suite('window namespace tests', () => {
|
||||
disposables.length = 0;
|
||||
});
|
||||
|
||||
|
||||
test('sendText immediately after createTerminal should not throw', (done) => {
|
||||
disposables.push(window.onDidOpenTerminal(term => {
|
||||
try {
|
||||
@@ -409,8 +411,7 @@ suite('window namespace tests', () => {
|
||||
// const terminal = window.createTerminal({ name: 'foo', pty });
|
||||
// });
|
||||
|
||||
// https://github.com/microsoft/vscode/issues/90437
|
||||
test.skip('should respect dimension overrides', (done) => {
|
||||
test('should respect dimension overrides', (done) => {
|
||||
disposables.push(window.onDidOpenTerminal(term => {
|
||||
try {
|
||||
equal(terminal, term);
|
||||
@@ -423,15 +424,18 @@ suite('window namespace tests', () => {
|
||||
// HACK: Ignore the event if dimension(s) are zero (#83778)
|
||||
return;
|
||||
}
|
||||
try {
|
||||
equal(e.dimensions.columns, 10);
|
||||
equal(e.dimensions.rows, 5);
|
||||
equal(e.terminal, terminal);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
// The default pty dimensions have a chance to appear here since override
|
||||
// dimensions happens after the terminal is created. If so just ignore and
|
||||
// wait for the right dimensions
|
||||
if (e.dimensions.columns === 10 || e.dimensions.rows === 5) {
|
||||
try {
|
||||
equal(e.terminal, terminal);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
disposables.push(window.onDidCloseTerminal(() => done()));
|
||||
terminal.dispose();
|
||||
}
|
||||
disposables.push(window.onDidCloseTerminal(() => done()));
|
||||
terminal.dispose();
|
||||
}));
|
||||
}));
|
||||
const writeEmitter = new EventEmitter<string>();
|
||||
@@ -469,7 +473,7 @@ suite('window namespace tests', () => {
|
||||
const pty: Pseudoterminal = {
|
||||
onDidWrite: writeEmitter.event,
|
||||
onDidClose: closeEmitter.event,
|
||||
open: () => closeEmitter.fire(),
|
||||
open: () => closeEmitter.fire(undefined),
|
||||
close: () => { }
|
||||
};
|
||||
const terminal = window.createTerminal({ name: 'foo', pty });
|
||||
@@ -562,5 +566,201 @@ suite('window namespace tests', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
suite('getEnvironmentVariableCollection', () => {
|
||||
test('should have collection variables apply to terminals immediately after setting', (done) => {
|
||||
// Text to match on before passing the test
|
||||
const expectedText = [
|
||||
'~a2~',
|
||||
'b1~b2~',
|
||||
'~c2~c1'
|
||||
];
|
||||
disposables.push(window.onDidWriteTerminalData(e => {
|
||||
try {
|
||||
equal(terminal, e.terminal);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
// Multiple expected could show up in the same data event
|
||||
while (expectedText.length > 0 && e.data.indexOf(expectedText[0]) >= 0) {
|
||||
expectedText.shift();
|
||||
// Check if all string are found, if so finish the test
|
||||
if (expectedText.length === 0) {
|
||||
disposables.push(window.onDidCloseTerminal(() => done()));
|
||||
terminal.dispose();
|
||||
}
|
||||
}
|
||||
}));
|
||||
const collection = window.getEnvironmentVariableCollection();
|
||||
disposables.push(collection);
|
||||
collection.replace('A', '~a2~');
|
||||
collection.append('B', '~b2~');
|
||||
collection.prepend('C', '~c2~');
|
||||
const terminal = window.createTerminal({
|
||||
env: {
|
||||
A: 'a1',
|
||||
B: 'b1',
|
||||
C: 'c1'
|
||||
}
|
||||
});
|
||||
// Run both PowerShell and sh commands, errors don't matter we're just looking for
|
||||
// the correct output
|
||||
terminal.sendText('$env:A');
|
||||
terminal.sendText('echo $A');
|
||||
terminal.sendText('$env:B');
|
||||
terminal.sendText('echo $B');
|
||||
terminal.sendText('$env:C');
|
||||
terminal.sendText('echo $C');
|
||||
});
|
||||
|
||||
test('should have collection variables apply to environment variables that don\'t exist', (done) => {
|
||||
// Text to match on before passing the test
|
||||
const expectedText = [
|
||||
'~a2~',
|
||||
'~b2~',
|
||||
'~c2~'
|
||||
];
|
||||
disposables.push(window.onDidWriteTerminalData(e => {
|
||||
try {
|
||||
equal(terminal, e.terminal);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
// Multiple expected could show up in the same data event
|
||||
while (expectedText.length > 0 && e.data.indexOf(expectedText[0]) >= 0) {
|
||||
expectedText.shift();
|
||||
// Check if all string are found, if so finish the test
|
||||
if (expectedText.length === 0) {
|
||||
disposables.push(window.onDidCloseTerminal(() => done()));
|
||||
terminal.dispose();
|
||||
}
|
||||
}
|
||||
}));
|
||||
const collection = window.getEnvironmentVariableCollection();
|
||||
disposables.push(collection);
|
||||
collection.replace('A', '~a2~');
|
||||
collection.append('B', '~b2~');
|
||||
collection.prepend('C', '~c2~');
|
||||
const terminal = window.createTerminal({
|
||||
env: {
|
||||
A: null,
|
||||
B: null,
|
||||
C: null
|
||||
}
|
||||
});
|
||||
// Run both PowerShell and sh commands, errors don't matter we're just looking for
|
||||
// the correct output
|
||||
terminal.sendText('$env:A');
|
||||
terminal.sendText('echo $A');
|
||||
terminal.sendText('$env:B');
|
||||
terminal.sendText('echo $B');
|
||||
terminal.sendText('$env:C');
|
||||
terminal.sendText('echo $C');
|
||||
});
|
||||
|
||||
test('should respect clearing entries', (done) => {
|
||||
// Text to match on before passing the test
|
||||
const expectedText = [
|
||||
'~a1~',
|
||||
'~b1~'
|
||||
];
|
||||
disposables.push(window.onDidWriteTerminalData(e => {
|
||||
try {
|
||||
equal(terminal, e.terminal);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
// Multiple expected could show up in the same data event
|
||||
while (expectedText.length > 0 && e.data.indexOf(expectedText[0]) >= 0) {
|
||||
expectedText.shift();
|
||||
// Check if all string are found, if so finish the test
|
||||
if (expectedText.length === 0) {
|
||||
disposables.push(window.onDidCloseTerminal(() => done()));
|
||||
terminal.dispose();
|
||||
}
|
||||
}
|
||||
}));
|
||||
const collection = window.getEnvironmentVariableCollection();
|
||||
disposables.push(collection);
|
||||
collection.replace('A', '~a2~');
|
||||
collection.replace('B', '~a2~');
|
||||
collection.clear();
|
||||
const terminal = window.createTerminal({
|
||||
env: {
|
||||
A: '~a1~',
|
||||
B: '~b1~'
|
||||
}
|
||||
});
|
||||
// Run both PowerShell and sh commands, errors don't matter we're just looking for
|
||||
// the correct output
|
||||
terminal.sendText('$env:A');
|
||||
terminal.sendText('echo $A');
|
||||
terminal.sendText('$env:B');
|
||||
terminal.sendText('echo $B');
|
||||
});
|
||||
|
||||
test('should respect deleting entries', (done) => {
|
||||
// Text to match on before passing the test
|
||||
const expectedText = [
|
||||
'~a1~',
|
||||
'~b2~'
|
||||
];
|
||||
disposables.push(window.onDidWriteTerminalData(e => {
|
||||
try {
|
||||
equal(terminal, e.terminal);
|
||||
} catch (e) {
|
||||
done(e);
|
||||
}
|
||||
// Multiple expected could show up in the same data event
|
||||
while (expectedText.length > 0 && e.data.indexOf(expectedText[0]) >= 0) {
|
||||
expectedText.shift();
|
||||
// Check if all string are found, if so finish the test
|
||||
if (expectedText.length === 0) {
|
||||
disposables.push(window.onDidCloseTerminal(() => done()));
|
||||
terminal.dispose();
|
||||
}
|
||||
}
|
||||
}));
|
||||
const collection = window.getEnvironmentVariableCollection();
|
||||
disposables.push(collection);
|
||||
collection.replace('A', '~a2~');
|
||||
collection.replace('B', '~b2~');
|
||||
collection.delete('A');
|
||||
const terminal = window.createTerminal({
|
||||
env: {
|
||||
A: '~a1~',
|
||||
B: '~b2~'
|
||||
}
|
||||
});
|
||||
// Run both PowerShell and sh commands, errors don't matter we're just looking for
|
||||
// the correct output
|
||||
terminal.sendText('$env:A');
|
||||
terminal.sendText('echo $A');
|
||||
terminal.sendText('$env:B');
|
||||
terminal.sendText('echo $B');
|
||||
});
|
||||
|
||||
test('get and forEach should work', () => {
|
||||
const collection = window.getEnvironmentVariableCollection();
|
||||
disposables.push(collection);
|
||||
collection.replace('A', '~a2~');
|
||||
collection.append('B', '~b2~');
|
||||
collection.prepend('C', '~c2~');
|
||||
|
||||
// Verify get
|
||||
deepEqual(collection.get('A'), { value: '~a2~', type: EnvironmentVariableMutatorType.Replace });
|
||||
deepEqual(collection.get('B'), { value: '~b2~', type: EnvironmentVariableMutatorType.Append });
|
||||
deepEqual(collection.get('C'), { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend });
|
||||
|
||||
// Verify forEach
|
||||
const entries: [string, EnvironmentVariableMutator][] = [];
|
||||
collection.forEach((v, m) => entries.push([v, m]));
|
||||
deepEqual(entries, [
|
||||
['A', { value: '~a2~', type: EnvironmentVariableMutatorType.Replace }],
|
||||
['B', { value: '~b2~', type: EnvironmentVariableMutatorType.Append }],
|
||||
['C', { value: '~c2~', type: EnvironmentVariableMutatorType.Prepend }]
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,12 +7,9 @@ import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
|
||||
suite('types', () => {
|
||||
suite('vscode API - types', () => {
|
||||
|
||||
test('static properties, es5 compat class', function () {
|
||||
|
||||
|
||||
assert.ok(vscode.ThemeIcon.File instanceof vscode.ThemeIcon);
|
||||
assert.ok(vscode.ThemeIcon.Folder instanceof vscode.ThemeIcon);
|
||||
assert.ok(vscode.CodeActionKind.Empty instanceof vscode.CodeActionKind);
|
||||
|
||||
@@ -3,17 +3,18 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import 'mocha';
|
||||
import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
import 'mocha';
|
||||
import * as os from 'os';
|
||||
import { join } from 'path';
|
||||
import { closeAllEditors, disposeAll, conditionalTest } from '../utils';
|
||||
import * as vscode from 'vscode';
|
||||
import { closeAllEditors, conditionalTest, delay, disposeAll } from '../utils';
|
||||
|
||||
const webviewId = 'myWebview';
|
||||
|
||||
const testDocument = join(vscode.workspace.rootPath || '', './bower.json');
|
||||
|
||||
suite('Webview tests', () => {
|
||||
suite('vscode API - webview', () => {
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
|
||||
function _register<T extends vscode.Disposable>(disposable: T) {
|
||||
@@ -332,8 +333,30 @@ suite('Webview tests', () => {
|
||||
webview.webview.postMessage({ value: 1 });
|
||||
await firstResponse;
|
||||
assert.strictEqual(webview.viewColumn, vscode.ViewColumn.One);
|
||||
|
||||
});
|
||||
|
||||
if (os.platform() === 'darwin') {
|
||||
conditionalTest('webview can copy text from webview', async () => {
|
||||
const expectedText = `webview text from: ${Date.now()}!`;
|
||||
|
||||
const webview = _register(vscode.window.createWebviewPanel(webviewId, 'title', { viewColumn: vscode.ViewColumn.One }, { enableScripts: true, retainContextWhenHidden: true }));
|
||||
const ready = getMesssage(webview);
|
||||
|
||||
|
||||
webview.webview.html = createHtmlDocumentWithBody(/*html*/`
|
||||
<b>${expectedText}</b>
|
||||
<script>
|
||||
const vscode = acquireVsCodeApi();
|
||||
document.execCommand('selectAll');
|
||||
vscode.postMessage({ type: 'ready' });
|
||||
</script>`);
|
||||
await ready;
|
||||
|
||||
await vscode.commands.executeCommand('editor.action.webvieweditor.copy');
|
||||
await delay(200); // Make sure copy has time to reach webview
|
||||
assert.strictEqual(await vscode.env.clipboard.readText(), expectedText);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function createHtmlDocumentWithBody(body: string): string {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { workspace, window, commands, ViewColumn, TextEditorViewColumnChangeEven
|
||||
import { join } from 'path';
|
||||
import { closeAllEditors, pathEquals, createRandomFile } from '../utils';
|
||||
|
||||
suite('window namespace tests', () => {
|
||||
suite('vscode API - window', () => {
|
||||
|
||||
teardown(closeAllEditors);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
import { createRandomFile, withLogDisabled } from '../utils';
|
||||
|
||||
suite('workspace-event', () => {
|
||||
suite('vscode API - workspace events', () => {
|
||||
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
|
||||
@@ -201,9 +201,29 @@ suite('workspace-event', () => {
|
||||
assert.equal(onDidRename?.files[0].newUri.toString(), newUri.toString());
|
||||
});
|
||||
|
||||
test('onWillRename - make changes', async function () {
|
||||
test('onWillRename - make changes (saved file)', function () {
|
||||
return testOnWillRename(false);
|
||||
});
|
||||
|
||||
test('onWillRename - make changes (dirty file)', function () {
|
||||
return testOnWillRename(true);
|
||||
});
|
||||
|
||||
async function testOnWillRename(withDirtyFile: boolean): Promise<void> {
|
||||
|
||||
const oldUri = await createRandomFile('BAR');
|
||||
|
||||
if (withDirtyFile) {
|
||||
const edit = new vscode.WorkspaceEdit();
|
||||
edit.insert(oldUri, new vscode.Position(0, 0), 'BAR');
|
||||
|
||||
const success = await vscode.workspace.applyEdit(edit);
|
||||
assert.ok(success);
|
||||
|
||||
const oldDocument = await vscode.workspace.openTextDocument(oldUri);
|
||||
assert.ok(oldDocument.isDirty);
|
||||
}
|
||||
|
||||
const newUri = oldUri.with({ path: oldUri.path + '-NEW' });
|
||||
|
||||
const anotherFile = await createRandomFile('BAR');
|
||||
@@ -229,7 +249,13 @@ suite('workspace-event', () => {
|
||||
assert.equal(onWillRename?.files[0].oldUri.toString(), oldUri.toString());
|
||||
assert.equal(onWillRename?.files[0].newUri.toString(), newUri.toString());
|
||||
|
||||
assert.equal((await vscode.workspace.openTextDocument(newUri)).getText(), 'FOOBAR');
|
||||
assert.equal((await vscode.workspace.openTextDocument(anotherFile)).getText(), 'FARBOO');
|
||||
});
|
||||
const newDocument = await vscode.workspace.openTextDocument(newUri);
|
||||
const anotherDocument = await vscode.workspace.openTextDocument(anotherFile);
|
||||
|
||||
assert.equal(newDocument.getText(), withDirtyFile ? 'FOOBARBAR' : 'FOOBAR');
|
||||
assert.equal(anotherDocument.getText(), 'FARBOO');
|
||||
|
||||
assert.ok(newDocument.isDirty);
|
||||
assert.ok(anotherDocument.isDirty);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
import { posix } from 'path';
|
||||
|
||||
suite('workspace-fs', () => {
|
||||
suite('vscode API - workspace-fs', () => {
|
||||
|
||||
let root: vscode.Uri;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import * as assert from 'assert';
|
||||
import { window, tasks, Disposable, TaskDefinition, Task, EventEmitter, CustomExecution, Pseudoterminal, TaskScope, commands, Task2 } from 'vscode';
|
||||
|
||||
suite('workspace-namespace', () => {
|
||||
suite('vscode API - tasks', () => {
|
||||
|
||||
suite('Tasks', () => {
|
||||
let disposables: Disposable[] = [];
|
||||
|
||||
@@ -9,7 +9,7 @@ import { createRandomFile, deleteFile, closeAllEditors, pathEquals, rndName, dis
|
||||
import { join, posix, basename } from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
suite('workspace-namespace', () => {
|
||||
suite('vscode API - workspace', () => {
|
||||
|
||||
teardown(closeAllEditors);
|
||||
|
||||
@@ -215,13 +215,6 @@ suite('workspace-namespace', () => {
|
||||
});
|
||||
|
||||
test('eol, change via onWillSave', async function () {
|
||||
if (vscode.env.uiKind === vscode.UIKind.Web) {
|
||||
// TODO@Jo Test seems to fail when running in web due to
|
||||
// onWillSaveTextDocument not getting called
|
||||
this.skip();
|
||||
return;
|
||||
}
|
||||
|
||||
let called = false;
|
||||
let sub = vscode.workspace.onWillSaveTextDocument(e => {
|
||||
called = true;
|
||||
|
||||
Reference in New Issue
Block a user