Skip to content

Commit

Permalink
test: Add tests for dangling refs to fsWatcher.spec.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
svsool committed Aug 6, 2020
1 parent 859016e commit 1e6eed2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/features/fsWatcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,42 @@ describe('fsWatcher feature', () => {
});
});

it('should add new dangling refs to cache on file create', async () => {
const noteName = rndName();

expect(utils.getWorkspaceCache().danglingRefs).toEqual([]);
expect(utils.getWorkspaceCache().danglingRefsByFsPath).toEqual({});

await createFile(`${noteName}.md`, '[[dangling-ref]] [[dangling-ref2]]', false);

await waitForExpect(() => {
expect(utils.getWorkspaceCache().danglingRefs).toEqual(['dangling-ref', 'dangling-ref2']);
expect(Object.values(utils.getWorkspaceCache().danglingRefsByFsPath)).toEqual([
['dangling-ref', 'dangling-ref2'],
]);
});
});

it('should remove dangling refs from cache on file remove', async () => {
const noteName = rndName();

await createFile(`${noteName}.md`, '[[dangling-ref]] [[dangling-ref2]]', false);

await waitForExpect(() => {
expect(utils.getWorkspaceCache().danglingRefs).toEqual(['dangling-ref', 'dangling-ref2']);
expect(Object.values(utils.getWorkspaceCache().danglingRefsByFsPath)).toEqual([
['dangling-ref', 'dangling-ref2'],
]);
});

await removeFile(`${noteName}.md`);

await waitForExpect(() => {
expect(utils.getWorkspaceCache().danglingRefs).toEqual([]);
expect(utils.getWorkspaceCache().danglingRefsByFsPath).toEqual({});
});
});

it.skip('should sync workspace cache on file remove (For some reason onDidDelete is not called timely in test env)', async () => {
const noteName = rndName();

Expand Down

0 comments on commit 1e6eed2

Please sign in to comment.