Skip to content

feat: improve static sleep during openResources method #1549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
16 changes: 9 additions & 7 deletions packages/extester/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ export class VSBrowser {
/**
* Waits until parts of the workbench are loaded
*/
async waitForWorkbench(timeout = 30000): Promise<void> {
async waitForWorkbench(timeout: number = 30_000): Promise<void> {
// 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;
}
Expand Down Expand Up @@ -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<void> {
if (paths.length === 0) {
async openResources(resource: { path: string | string[]; timeout?: number; delay?: number }): Promise<void> {
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);
}
}
7 changes: 2 additions & 5 deletions packages/extester/src/suite/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
});
Expand Down
4 changes: 2 additions & 2 deletions packages/extester/src/util/codeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test-project/src/test/bottomBar/problemsView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/test-project/src/test/bottomBar/views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
4 changes: 2 additions & 2 deletions tests/test-project/src/test/debug/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion tests/test-project/src/test/editor/customEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
10 changes: 6 additions & 4 deletions tests/test-project/src/test/editor/diffEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions tests/test-project/src/test/editor/extensionEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/test-project/src/test/editor/textEditor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 () {
Expand Down
2 changes: 1 addition & 1 deletion tests/test-project/src/test/menu/contextMenu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
4 changes: 2 additions & 2 deletions tests/test-project/src/test/menu/titleBar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/test-project/src/test/xsideBar/scmView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test-project/src/test/xsideBar/sideBarView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading