Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions tst/e2e/DocumentHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ describe('DocumentHandler', () => {
await extension.reset();
});

beforeEach(async () => {
await extension.reset();
});

afterAll(async () => {
await extension.close();
});
Expand All @@ -35,7 +31,7 @@ describe('DocumentHandler', () => {
const document = extension.components.documentManager.get(uri);
expect(document).toBeDefined();
expect(document?.contents()).toBe(content);
});
}, 2_500);
});

it('should handle document change and update DocumentManager', async () => {
Expand Down Expand Up @@ -65,7 +61,7 @@ describe('DocumentHandler', () => {
await WaitFor.waitFor(() => {
const document = extension.components.documentManager.get(uri);
expect(document?.contents()).toBe(`Hello${newContent}`);
});
}, 2_500);

const replaceContent = 'SomeRandomContent';
await extension.changeDocument({
Expand All @@ -76,7 +72,7 @@ describe('DocumentHandler', () => {
await WaitFor.waitFor(() => {
const document = extension.components.documentManager.get(uri);
expect(document?.contents()).toBe(replaceContent);
});
}, 2_500);
});

it('should handle document close and remove from DocumentManager', async () => {
Expand All @@ -93,14 +89,14 @@ describe('DocumentHandler', () => {

await WaitFor.waitFor(() => {
expect(extension.components.documentManager.get(uri)).toBeDefined();
});
}, 2_500);

await extension.closeDocument({
textDocument: { uri },
});

await WaitFor.waitFor(() => {
expect(extension.components.documentManager.get(uri)).toBeUndefined();
});
}, 2_500);
});
});
8 changes: 2 additions & 6 deletions tst/utils/TestExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ export class TestExtension implements Closeable {

async reset() {
await this.ready();
(this.serverConnection.components.documents.documents as any)._syncedDocuments.clear();

this.core.settingsManager.reset();
this.core.syntaxTreeManager.deleteAllTrees();
this.core.documentManager.clear();
Expand Down Expand Up @@ -241,12 +243,10 @@ export class TestExtension implements Closeable {

async openDocument(params: DidOpenTextDocumentParams) {
await this.notify(DidOpenTextDocumentNotification.method, params);
await wait(10);
}

async changeDocument(params: DidChangeTextDocumentParams) {
await this.notify(DidChangeTextDocumentNotification.method, params);
await wait(10);
}

async closeDocument(params: DidCloseTextDocumentParams) {
Expand Down Expand Up @@ -338,7 +338,3 @@ export class TestExtension implements Closeable {
return uri;
}
}

async function wait(ms: number) {
await new Promise((resolve) => setTimeout(resolve, ms));
}
Loading