Skip to content

Commit 11fd274

Browse files
author
Benjamin Pasero
committed
tests - add test for out of workspace watchers
1 parent c6d4c7e commit 11fd274

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/vs/workbench/services/editor/test/browser/editorService.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,4 +896,26 @@ suite('EditorService', () => {
896896
Event.once(editorService.onDidActiveEditorChange)(c);
897897
});
898898
}
899+
900+
test('file watcher gets installed for out of workspace files', async function () {
901+
const [part, service, testInstantiationService, accessor] = createEditorService();
902+
903+
const input1 = testInstantiationService.createInstance(TestEditorInput, URI.parse('file://resource1-openside'));
904+
const input2 = testInstantiationService.createInstance(TestEditorInput, URI.parse('file://resource2-openside'));
905+
906+
await part.whenRestored;
907+
908+
await service.openEditor(input1, { pinned: true });
909+
assert.equal(accessor.fileService.watches.length, 1);
910+
assert.equal(accessor.fileService.watches[0].toString(), input1.resource.toString());
911+
912+
const editor = await service.openEditor(input2, { pinned: true });
913+
assert.equal(accessor.fileService.watches.length, 1);
914+
assert.equal(accessor.fileService.watches[0].toString(), input2.resource.toString());
915+
916+
await editor?.group?.closeAllEditors();
917+
assert.equal(accessor.fileService.watches.length, 0);
918+
919+
part.dispose();
920+
});
899921
});

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,14 @@ export class TestFileService implements IFileService {
739739
}
740740

741741
del(_resource: URI, _options?: { useTrash?: boolean, recursive?: boolean }): Promise<void> { return Promise.resolve(); }
742-
watch(_resource: URI): IDisposable { return Disposable.None; }
742+
743+
readonly watches: URI[] = [];
744+
watch(_resource: URI): IDisposable {
745+
this.watches.push(_resource);
746+
747+
return toDisposable(() => this.watches.splice(this.watches.indexOf(_resource), 1));
748+
}
749+
743750
getWriteEncoding(_resource: URI): IResourceEncoding { return { encoding: 'utf8', hasBOM: false }; }
744751
dispose(): void { }
745752
}

0 commit comments

Comments
 (0)