From 9a4eba89f6e68c1f8f76543c9eaee740adb05b3c Mon Sep 17 00:00:00 2001 From: Dominik Jelinek Date: Wed, 2 Oct 2024 16:09:31 +0200 Subject: [PATCH] feat: improve static sleep during openResources method Signed-off-by: Dominik Jelinek --- packages/extester/src/browser.ts | 16 +++++++++------- packages/extester/src/suite/runner.ts | 7 ++----- packages/extester/src/util/codeUtil.ts | 4 ++-- .../src/test/bottomBar/problemsView.test.ts | 2 +- .../src/test/bottomBar/views.test.ts | 2 +- tests/test-project/src/test/debug/debug.test.ts | 4 ++-- .../src/test/editor/customEditor.test.ts | 2 +- .../src/test/editor/diffEditor.test.ts | 10 ++++++---- .../src/test/editor/extensionEditor.test.ts | 11 ++++------- .../src/test/editor/textEditor.test.ts | 4 ++-- .../src/test/menu/contextMenu.test.ts | 2 +- .../test-project/src/test/menu/titleBar.test.ts | 4 ++-- .../src/test/xsideBar/scmView.test.ts | 2 +- .../src/test/xsideBar/sideBarView.test.ts | 2 +- 14 files changed, 35 insertions(+), 37 deletions(-) diff --git a/packages/extester/src/browser.ts b/packages/extester/src/browser.ts index 8700827cb..28034f312 100644 --- a/packages/extester/src/browser.ts +++ b/packages/extester/src/browser.ts @@ -145,13 +145,13 @@ export class VSBrowser { /** * Waits until parts of the workbench are loaded */ - async waitForWorkbench(timeout = 30000): Promise { + async waitForWorkbench(timeout: number = 30_000): Promise { // Workaround/patch for https://github.com/redhat-developer/vscode-extension-tester/issues/466 try { await this._driver.wait(until.elementLocated(By.className('monaco-workbench')), timeout, `Workbench was not loaded properly after ${timeout} ms.`); } catch (err) { if ((err as Error).name === 'WebDriverError') { - await new Promise((res) => setTimeout(res, 3000)); + await this._driver.sleep(3_000); } else { throw err; } @@ -199,14 +199,16 @@ export class VSBrowser { * @param paths path(s) of folder(s)/files(s) to open as varargs * @returns Promise resolving when all selected resources are opened and the workbench reloads */ - async openResources(...paths: string[]): Promise { - if (paths.length === 0) { + async openResources(resource: { path: string | string[]; timeout?: number; delay?: number }): Promise { + if (resource.path.length === 0) { return; } const code = new CodeUtil(this.storagePath, this.releaseType, this.extensionsFolder); - code.open(...paths); - await new Promise((res) => setTimeout(res, 3000)); - await this.waitForWorkbench(); + code.open(resource.path); + if (resource.delay) { + await this._driver.sleep(resource.delay); + } + await this.waitForWorkbench(resource.timeout); } } diff --git a/packages/extester/src/suite/runner.ts b/packages/extester/src/suite/runner.ts index 7e5a9921b..f36cfc36e 100644 --- a/packages/extester/src/suite/runner.ts +++ b/packages/extester/src/suite/runner.ts @@ -92,11 +92,8 @@ export class VSRunner { const start = Date.now(); const binPath = process.platform === 'darwin' ? await self.createShortcut(code.getCodeFolder(), self.tmpLink) : self.chromeBin; await browser.start(binPath); - await browser.openResources(...resources); - await browser.waitForWorkbench(); - await new Promise((res) => { - setTimeout(res, 3000); - }); + await browser.openResources({ path: resources, delay: 1_500 }); + await browser.driver.sleep(3_000); console.log(`Browser ready in ${Date.now() - start} ms`); console.log('Launching tests...'); }); diff --git a/packages/extester/src/util/codeUtil.ts b/packages/extester/src/util/codeUtil.ts index 149bc4d06..e322dd681 100644 --- a/packages/extester/src/util/codeUtil.ts +++ b/packages/extester/src/util/codeUtil.ts @@ -201,8 +201,8 @@ export class CodeUtil { * Open files/folders in running vscode * @param paths vararg paths to files or folders to open */ - open(...paths: string[]): void { - const segments = paths.map((f) => `"${f}"`).join(' '); + open(paths: string | string[]): void { + const segments = typeof paths === 'string' ? paths : paths.map((f) => `"${f}"`).join(' '); const command = `${this.getCliInitCommand()} -r ${segments} --user-data-dir="${path.join(this.downloadFolder, 'settings')}"`; childProcess.execSync(command); } diff --git a/tests/test-project/src/test/bottomBar/problemsView.test.ts b/tests/test-project/src/test/bottomBar/problemsView.test.ts index 779280de1..d429b8839 100644 --- a/tests/test-project/src/test/bottomBar/problemsView.test.ts +++ b/tests/test-project/src/test/bottomBar/problemsView.test.ts @@ -26,7 +26,7 @@ describe('ProblemsView', function () { before(async function () { this.timeout(25000); - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts')); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts'), delay: 3_000 }); bar = new BottomBarPanel(); await bar.toggle(true); diff --git a/tests/test-project/src/test/bottomBar/views.test.ts b/tests/test-project/src/test/bottomBar/views.test.ts index e74cfc876..3de383f03 100644 --- a/tests/test-project/src/test/bottomBar/views.test.ts +++ b/tests/test-project/src/test/bottomBar/views.test.ts @@ -26,7 +26,7 @@ describe('Output View/Text Views', function () { before(async function () { this.timeout(25000); - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources')); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources'), delay: 3_000 }); await VSBrowser.instance.waitForWorkbench(); }); diff --git a/tests/test-project/src/test/debug/debug.test.ts b/tests/test-project/src/test/debug/debug.test.ts index 945affd4b..0f9a66226 100644 --- a/tests/test-project/src/test/debug/debug.test.ts +++ b/tests/test-project/src/test/debug/debug.test.ts @@ -48,9 +48,9 @@ describe('Debugging', function () { before(async function () { this.timeout(30000); const browser = VSBrowser.instance; - await browser.openResources(folder); + await browser.openResources({ path: folder }); await browser.driver.sleep(5000); - await browser.openResources(path.join(folder, 'test.js')); + await browser.openResources({ path: path.join(folder, 'test.js') }); await browser.driver.sleep(5000); view = (await (await new ActivityBar().getViewControl('Run'))?.openView()) as DebugView; diff --git a/tests/test-project/src/test/editor/customEditor.test.ts b/tests/test-project/src/test/editor/customEditor.test.ts index f95fceba7..4edbd1e06 100644 --- a/tests/test-project/src/test/editor/customEditor.test.ts +++ b/tests/test-project/src/test/editor/customEditor.test.ts @@ -25,7 +25,7 @@ describe('CustomEditor', () => { const CUSTOM_TITLE: string = 'example.cscratch'; before(async () => { - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', CUSTOM_TITLE)); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', CUSTOM_TITLE) }); editor = new CustomEditor(); }); diff --git a/tests/test-project/src/test/editor/diffEditor.test.ts b/tests/test-project/src/test/editor/diffEditor.test.ts index 4a1e08771..5de83dd77 100644 --- a/tests/test-project/src/test/editor/diffEditor.test.ts +++ b/tests/test-project/src/test/editor/diffEditor.test.ts @@ -24,10 +24,12 @@ describe('DiffEditor', async () => { before(async function () { this.timeout(250000); - await VSBrowser.instance.openResources( - path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-a.txt'), - path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-b.txt'), - ); + await VSBrowser.instance.openResources({ + path: [ + path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-a.txt'), + path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-b.txt'), + ], + }); await new EditorView().openEditor('test-file-b.txt'); await new Workbench().executeCommand('File: Compare Active File With...'); let quickOpen: QuickOpenBox | InputBox; diff --git a/tests/test-project/src/test/editor/extensionEditor.test.ts b/tests/test-project/src/test/editor/extensionEditor.test.ts index 11dfc69e5..3f5432797 100644 --- a/tests/test-project/src/test/editor/extensionEditor.test.ts +++ b/tests/test-project/src/test/editor/extensionEditor.test.ts @@ -29,8 +29,10 @@ import { WebDriver, } from 'vscode-extension-tester'; import * as pjson from '../../../package.json'; +import * as path from 'path'; describe('Extension Editor', function () { + this.timeout(99999999); let driver: WebDriver; let viewControl: ViewControl; let extensionsView: SideBarView; @@ -43,19 +45,14 @@ describe('Extension Editor', function () { before(async function () { driver = VSBrowser.instance.driver; + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') }); viewControl = (await new ActivityBar().getViewControl('Extensions')) as ViewControl; extensionsView = await viewControl.openView(); await driver.wait(async function () { return (await extensionsView.getContent().getSections()).length > 0; }); - const view = await viewControl.openView(); - - await driver.wait(async function () { - return (await view.getContent().getSections()).length > 0; - }); - section = (await view.getContent().getSection('Installed')) as ExtensionsViewSection; - + section = (await extensionsView.getContent().getSection('Installed')) as ExtensionsViewSection; await driver.wait(async function () { item = (await section.findItem(`@installed ${pjson.displayName}`)) as ExtensionsViewItem; return item !== undefined; diff --git a/tests/test-project/src/test/editor/textEditor.test.ts b/tests/test-project/src/test/editor/textEditor.test.ts index 91312a82c..6049cefa5 100644 --- a/tests/test-project/src/test/editor/textEditor.test.ts +++ b/tests/test-project/src/test/editor/textEditor.test.ts @@ -38,7 +38,7 @@ describe('ContentAssist', async function () { before(async () => { this.timeout(30000); - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts')); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts') }); await VSBrowser.instance.waitForWorkbench(); await new Promise((res) => setTimeout(res, 2000)); const ew = new EditorView(); @@ -191,7 +191,7 @@ describe('TextEditor', function () { let ew: EditorView; beforeEach(async function () { - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', param.file)); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', param.file) }); ew = new EditorView(); await ew.getDriver().wait( async function () { diff --git a/tests/test-project/src/test/menu/contextMenu.test.ts b/tests/test-project/src/test/menu/contextMenu.test.ts index 6f93fe0f7..b633bf2b4 100644 --- a/tests/test-project/src/test/menu/contextMenu.test.ts +++ b/tests/test-project/src/test/menu/contextMenu.test.ts @@ -25,7 +25,7 @@ import * as path from 'path'; before(async () => { this.timeout(30000); - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder')); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') }); await VSBrowser.instance.driver.sleep(5000); }); diff --git a/tests/test-project/src/test/menu/titleBar.test.ts b/tests/test-project/src/test/menu/titleBar.test.ts index 0b77befb2..8bf3d7403 100644 --- a/tests/test-project/src/test/menu/titleBar.test.ts +++ b/tests/test-project/src/test/menu/titleBar.test.ts @@ -24,11 +24,11 @@ import { ActivityBar, TitleBar, ContextMenu, TitleBarItem, EditorView, VSBrowser before(async function () { this.timeout(30000); - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder')); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') }); await VSBrowser.instance.driver.sleep(5000); bar = new TitleBar(); - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder', 'foo')); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder', 'foo') }); // workspace cleanup before tests await new EditorView().closeAllEditors(); diff --git a/tests/test-project/src/test/xsideBar/scmView.test.ts b/tests/test-project/src/test/xsideBar/scmView.test.ts index 8ab14d540..bf3984f4b 100644 --- a/tests/test-project/src/test/xsideBar/scmView.test.ts +++ b/tests/test-project/src/test/xsideBar/scmView.test.ts @@ -26,7 +26,7 @@ import * as fs from 'fs-extra'; before(async function () { this.timeout(15000); fs.writeFileSync(path.resolve('.', 'testfile'), 'content'); - await VSBrowser.instance.openResources(path.resolve('..', '..')); + await VSBrowser.instance.openResources({ path: path.resolve('..', '..'), delay: 3_000 }); await VSBrowser.instance.waitForWorkbench(); view = (await ((await new ActivityBar().getViewControl('Source Control')) as ViewControl).openView()) as ScmView; await new Promise((res) => { diff --git a/tests/test-project/src/test/xsideBar/sideBarView.test.ts b/tests/test-project/src/test/xsideBar/sideBarView.test.ts index b58b48da5..b480ec5eb 100644 --- a/tests/test-project/src/test/xsideBar/sideBarView.test.ts +++ b/tests/test-project/src/test/xsideBar/sideBarView.test.ts @@ -82,7 +82,7 @@ describe('SideBarView', () => { before(async function () { this.timeout(15000); - await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder')); + await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') }); view = await ((await new ActivityBar().getViewControl('Explorer')) as ViewControl).openView(); await new Promise((res) => { setTimeout(res, 1000);