Skip to content

Commit a77ec12

Browse files
authored
test(vscode): fix failure to close editors on beforeEach hook. (#5975)
## Problem - See #5325 - the following `waitUntil` is timing out: https://github.com/aws/aws-toolkit-vscode/blob/43299f368308b6720ba22bbd910c6714bc47bdcb/packages/core/src/test/testUtil.ts#L495-L518 - All occurrences of error (AFAIK) fail to list any editors open. This implies `waitUntil` is timing out even though all editors (that aren't ignored by pattern) are closed. ## Solution A potential explanation is that the `executeCommand` is taking a long time to close the editors ignored by the patterns, and causing a timeout in `waitUntil`. In this case, we don't want to error. - refactor to also check if activeEditors is cleared. If there aren't any, we shouldn't be throwing an error. - Also, decrease timeout to avoid wasting time here during tests (if we can't close ignored editors, don't waste time trying). This code is run between every test so 5 second timeout per test is huge. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 43299f3 commit a77ec12

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

packages/core/src/test/testUtil.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,30 +490,30 @@ export async function closeAllEditors(): Promise<void> {
490490
/amazonwebservices\.[a-z\-]+-vscode\./,
491491
/nullExtensionDescription./, // Sometimes exists instead of the prior line, see https://github.com/aws/aws-toolkit-vscode/issues/4658
492492
]
493-
const editors: vscode.TextEditor[] = []
493+
const editorsToClose: vscode.TextEditor[] = []
494494

495495
const noVisibleEditor: boolean | undefined = await waitUntil(
496496
async () => {
497497
// Race: documents could appear after the call to closeAllEditors(), so retry.
498498
await vscode.commands.executeCommand(closeAllCmd)
499-
editors.length = 0
500-
editors.push(
499+
editorsToClose.length = 0
500+
editorsToClose.push(
501501
...vscode.window.visibleTextEditors.filter(
502502
(editor) => !ignorePatterns.some((p) => p.test(editor.document.fileName))
503503
)
504504
)
505505

506-
return editors.length === 0
506+
return editorsToClose.length === 0
507507
},
508508
{
509-
timeout: 5000, // Arbitrary values. Should succeed except when VS Code is lagging heavily.
509+
timeout: 1000, // Arbitrary values. Should succeed except when VS Code is lagging heavily.
510510
interval: 250,
511511
truthy: true,
512512
}
513513
)
514514

515-
if (!noVisibleEditor) {
516-
const editorNames = editors.map((editor) => `\t${editor.document.fileName}`)
515+
if (!noVisibleEditor && editorsToClose.length > 0) {
516+
const editorNames = editorsToClose.map((editor) => `\t${editor.document.fileName}`)
517517
throw new Error(`Editors were still open after closeAllEditors():\n${editorNames.join('\n')}`)
518518
}
519519
}

0 commit comments

Comments
 (0)