mirror of
https://github.com/Microsoft/vscode
synced 2024-08-28 13:29:44 +00:00
Method to clear memento static map (#126092)
This commit is contained in:
parent
66ecd8f6a8
commit
e1161be268
|
@ -59,6 +59,19 @@ export class Memento {
|
|||
globalMemento.save();
|
||||
}
|
||||
}
|
||||
|
||||
static clear(scope: StorageScope): void {
|
||||
|
||||
// Workspace
|
||||
if (scope === StorageScope.WORKSPACE) {
|
||||
Memento.workspaceMementos.clear();
|
||||
}
|
||||
|
||||
// Global
|
||||
if (scope === StorageScope.GLOBAL) {
|
||||
Memento.globalMementos.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ScopedMemento {
|
||||
|
|
|
@ -14,6 +14,8 @@ suite('Memento', () => {
|
|||
|
||||
setup(() => {
|
||||
storage = new TestStorageService();
|
||||
Memento.clear(StorageScope.GLOBAL);
|
||||
Memento.clear(StorageScope.WORKSPACE);
|
||||
});
|
||||
|
||||
test('Loading and Saving Memento with Scopes', () => {
|
||||
|
@ -176,4 +178,30 @@ suite('Memento', () => {
|
|||
memento = myMemento2.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE);
|
||||
assert.deepStrictEqual(memento, { foo: 'Hello World', bar: 'Hello World' });
|
||||
});
|
||||
|
||||
test('Clear Memento', () => {
|
||||
let myMemento = new Memento('memento.test', storage);
|
||||
|
||||
// Global
|
||||
let globalMemento = myMemento.getMemento(StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
globalMemento.foo = 'Hello World';
|
||||
|
||||
// Workspace
|
||||
let workspaceMemento = myMemento.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE);
|
||||
workspaceMemento.bar = 'Hello World';
|
||||
|
||||
myMemento.saveMemento();
|
||||
|
||||
// Clear
|
||||
storage = new TestStorageService();
|
||||
Memento.clear(StorageScope.GLOBAL);
|
||||
Memento.clear(StorageScope.WORKSPACE);
|
||||
|
||||
myMemento = new Memento('memento.test', storage);
|
||||
globalMemento = myMemento.getMemento(StorageScope.GLOBAL, StorageTarget.MACHINE);
|
||||
workspaceMemento = myMemento.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE);
|
||||
|
||||
assert.deepStrictEqual(globalMemento, {});
|
||||
assert.deepStrictEqual(workspaceMemento, {});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue