Skip to content

Commit

Permalink
Onboard to ensureNoDisposablesAreLeakedInTestSuite in quickAccess t…
Browse files Browse the repository at this point in the history
…ests

ref #200091
  • Loading branch information
TylerLeonhardt committed Dec 6, 2023
1 parent 42b9e86 commit 7a104d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@
"src/vs/workbench/services/userActivity/test/browser/domActivityTracker.test.ts",
"src/vs/workbench/services/workspaces/test/browser/workspaces.test.ts",
"src/vs/workbench/services/workspaces/test/common/workspaceTrust.test.ts",
"src/vs/workbench/test/browser/quickAccess.test.ts",
"src/vs/workbench/test/browser/webview.test.ts"
]
}
Expand Down
39 changes: 24 additions & 15 deletions src/vs/workbench/test/browser/quickAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { TestServiceAccessor, workbenchInstantiationService } from 'vs/workbench
import { DisposableStore, toDisposable, IDisposable } from 'vs/base/common/lifecycle';
import { timeout } from 'vs/base/common/async';
import { PickerQuickAccessProvider, FastAndSlowPicks } from 'vs/platform/quickinput/browser/pickerQuickAccess';
import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils';

suite('QuickAccess', () => {

let disposables: DisposableStore;
const disposables = ensureNoDisposablesAreLeakedInTestSuite();

let instantiationService: IInstantiationService;
let accessor: TestServiceAccessor;

Expand All @@ -38,50 +40,62 @@ suite('QuickAccess', () => {

class TestProviderDefault implements IQuickAccessProvider {

constructor(@IQuickInputService private readonly quickInputService: IQuickInputService, disposables: DisposableStore) { }
constructor(@IQuickInputService private readonly quickInputService: IQuickInputService) { }

provide(picker: IQuickPick<IQuickPickItem>, token: CancellationToken): IDisposable {
assert.ok(picker);
providerDefaultCalled = true;
token.onCancellationRequested(() => providerDefaultCanceled = true);

const store = new DisposableStore();
store.add(token.onCancellationRequested(() => providerDefaultCanceled = true));

// bring up provider #3
setTimeout(() => this.quickInputService.quickAccess.show(providerDescriptor3.prefix));

return toDisposable(() => providerDefaultDisposed = true);
store.add(toDisposable(() => providerDefaultDisposed = true));
return store;
}
}

class TestProvider1 implements IQuickAccessProvider {
provide(picker: IQuickPick<IQuickPickItem>, token: CancellationToken): IDisposable {
assert.ok(picker);
provider1Called = true;
token.onCancellationRequested(() => provider1Canceled = true);

return toDisposable(() => provider1Disposed = true);
const store = new DisposableStore();
store.add(token.onCancellationRequested(() => provider1Canceled = true));

store.add(toDisposable(() => provider1Disposed = true));
return store;
}
}

class TestProvider2 implements IQuickAccessProvider {
provide(picker: IQuickPick<IQuickPickItem>, token: CancellationToken): IDisposable {
assert.ok(picker);
provider2Called = true;
token.onCancellationRequested(() => provider2Canceled = true);

return toDisposable(() => provider2Disposed = true);
const store = new DisposableStore();
store.add(token.onCancellationRequested(() => provider2Canceled = true));

store.add(toDisposable(() => provider2Disposed = true));
return store;
}
}

class TestProvider3 implements IQuickAccessProvider {
provide(picker: IQuickPick<IQuickPickItem>, token: CancellationToken): IDisposable {
assert.ok(picker);
provider3Called = true;
token.onCancellationRequested(() => provider3Canceled = true);

const store = new DisposableStore();
store.add(token.onCancellationRequested(() => provider3Canceled = true));

// hide without picking
setTimeout(() => picker.hide());

return toDisposable(() => provider3Disposed = true);
store.add(toDisposable(() => provider3Disposed = true));
return store;
}
}

Expand All @@ -91,15 +105,10 @@ suite('QuickAccess', () => {
const providerDescriptor3 = { ctor: TestProvider3, prefix: 'changed', helpEntries: [] };

setup(() => {
disposables = new DisposableStore();
instantiationService = workbenchInstantiationService(undefined, disposables);
accessor = instantiationService.createInstance(TestServiceAccessor);
});

teardown(() => {
disposables.dispose();
});

test('registry', () => {
const registry = (Registry.as<IQuickAccessRegistry>(Extensions.Quickaccess));
const restore = (registry as QuickAccessRegistry).clear();
Expand Down

0 comments on commit 7a104d4

Please sign in to comment.