Skip to content

Commit

Permalink
Adjust diagnostics wait time in tests dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Sep 30, 2022
1 parent db9a4dd commit 7dbbd1a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 5 additions & 5 deletions client/tests/e2e/suite/extension.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ suite("Extension Test Suite", () => {
const docUri = getDocUri(path.join("test_tool_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, []);
});

test("Valid macro file returns empty diagnostics", async () => {
const docUri = getDocUri(path.join("macros_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, []);
});

test("Invalid tool should return diagnostics for required attributes 'id' and 'name'", async () => {
const docUri = getDocUri(path.join("test_invalid_tool_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, [
{
message: "Element 'tool': The attribute 'id' is required but missing.",
Expand All @@ -58,7 +58,7 @@ suite("Extension Test Suite", () => {
const docUri = getDocUri(path.join("test_syntax_error_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, [
{
message: "Couldn't find end of Start Tag tool line 1, line 2, column 1",
Expand All @@ -72,7 +72,7 @@ suite("Extension Test Suite", () => {
const docUri = getDocUri(path.join("test_syntax_error_macro_01.xml"));
await activateAndOpenInEditor(docUri);

await waitForDiagnostics();
await waitForDiagnostics(docUri);
await assertDiagnostics(docUri, [
{
message: "Premature end of data in tag macros line 1, line 2, column 1",
Expand Down
11 changes: 9 additions & 2 deletions client/tests/e2e/suite/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ export async function sleep(ms: number): Promise<void> {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export async function waitForDiagnostics(): Promise<void> {
return sleep(500);
export async function waitForDiagnostics(docUri: vscode.Uri, timeoutInMilliseconds: number = 2000): Promise<void> {
const waitMilliseconds = 100;
let waitTimeout = timeoutInMilliseconds;
let diagnostics = vscode.languages.getDiagnostics(docUri);
while (waitTimeout > 0 && !diagnostics.length) {
await sleep(waitMilliseconds);
waitTimeout -= waitMilliseconds;
diagnostics = vscode.languages.getDiagnostics(docUri);
}
}

export const getDocPath = (filePath: string): string => {
Expand Down

0 comments on commit 7dbbd1a

Please sign in to comment.