Move EnvironmentVariableCollection API into ExtensionContext (#96061)

* Move env var collection to ext context

* Remove dispose, fix persistent passing

* Fire collection change on persistence change

* Fix tests by forcing activation and getting ctx

* chore: bump js-debug

Co-authored-by: Connor Peet <connor@peet.io>
This commit is contained in:
Daniel Imms
2020-04-24 16:45:30 -07:00
committed by GitHub
parent 00ec9390a4
commit 7f5bada046
8 changed files with 73 additions and 79 deletions

View File

@@ -3,20 +3,27 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable, UIKind, env, EnvironmentVariableMutatorType, EnvironmentVariableMutator } from 'vscode';
import { window, Pseudoterminal, EventEmitter, TerminalDimensions, workspace, ConfigurationTarget, Disposable, UIKind, env, EnvironmentVariableMutatorType, EnvironmentVariableMutator, extensions, ExtensionContext } from 'vscode';
import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
// Disable terminal tests:
// - Web https://github.com/microsoft/vscode/issues/92826
// - Remote https://github.com/microsoft/vscode/issues/96057
((env.uiKind === UIKind.Web || typeof env.remoteName !== 'undefined') ? suite.skip : suite)('vscode API - terminal', () => {
let extensionContext: ExtensionContext;
suiteSetup(async () => {
// Trigger extension activation and grab the context as some tests depend on it
await extensions.getExtension('vscode.vscode-api-tests')?.activate();
extensionContext = (global as any).testExtensionContext;
const config = workspace.getConfiguration('terminal.integrated');
// Disable conpty in integration tests because of https://github.com/microsoft/vscode/issues/76548
await config.update('windowsEnableConpty', false, ConfigurationTarget.Global);
// Disable exit alerts as tests may trigger then and we're not testing the notifications
await config.update('showExitAlert', false, ConfigurationTarget.Global);
});
suite('Terminal', () => {
let disposables: Disposable[] = [];
@@ -25,7 +32,6 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
disposables.length = 0;
});
test('sendText immediately after createTerminal should not throw', (done) => {
disposables.push(window.onDidOpenTerminal(term => {
try {
@@ -607,7 +613,7 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
});
});
suite('getEnvironmentVariableCollection', () => {
suite('environmentVariableCollection', () => {
test('should have collection variables apply to terminals immediately after setting', (done) => {
// Text to match on before passing the test
const expectedText = [
@@ -632,8 +638,8 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
}
}
}));
const collection = window.getEnvironmentVariableCollection();
disposables.push(collection);
const collection = extensionContext.environmentVariableCollection;
disposables.push({ dispose: () => collection.clear() });
collection.replace('A', '~a2~');
collection.append('B', '~b2~');
collection.prepend('C', '~c2~');
@@ -678,8 +684,8 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
}
}
}));
const collection = window.getEnvironmentVariableCollection();
disposables.push(collection);
const collection = extensionContext.environmentVariableCollection;
disposables.push({ dispose: () => collection.clear() });
collection.replace('A', '~a2~');
collection.append('B', '~b2~');
collection.prepend('C', '~c2~');
@@ -723,8 +729,8 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
}
}
}));
const collection = window.getEnvironmentVariableCollection();
disposables.push(collection);
const collection = extensionContext.environmentVariableCollection;
disposables.push({ dispose: () => collection.clear() });
collection.replace('A', '~a2~');
collection.replace('B', '~a2~');
collection.clear();
@@ -765,8 +771,8 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
}
}
}));
const collection = window.getEnvironmentVariableCollection();
disposables.push(collection);
const collection = extensionContext.environmentVariableCollection;
disposables.push({ dispose: () => collection.clear() });
collection.replace('A', '~a2~');
collection.replace('B', '~b2~');
collection.delete('A');
@@ -785,8 +791,8 @@ import { doesNotThrow, equal, ok, deepEqual, throws } from 'assert';
});
test('get and forEach should work', () => {
const collection = window.getEnvironmentVariableCollection();
disposables.push(collection);
const collection = extensionContext.environmentVariableCollection;
disposables.push({ dispose: () => collection.clear() });
collection.replace('A', '~a2~');
collection.append('B', '~b2~');
collection.prepend('C', '~c2~');