Skip to content

Commit 9c8640e

Browse files
committed
feat: improve static sleep during openResources method
Signed-off-by: Dominik Jelinek <[email protected]>
1 parent c1ceab4 commit 9c8640e

File tree

14 files changed

+35
-37
lines changed

14 files changed

+35
-37
lines changed

packages/extester/src/browser.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ export class VSBrowser {
145145
/**
146146
* Waits until parts of the workbench are loaded
147147
*/
148-
async waitForWorkbench(timeout = 30000): Promise<void> {
148+
async waitForWorkbench(timeout: number = 30_000): Promise<void> {
149149
// Workaround/patch for https://github.com/redhat-developer/vscode-extension-tester/issues/466
150150
try {
151151
await this._driver.wait(until.elementLocated(By.className('monaco-workbench')), timeout, `Workbench was not loaded properly after ${timeout} ms.`);
152152
} catch (err) {
153153
if ((err as Error).name === 'WebDriverError') {
154-
await new Promise((res) => setTimeout(res, 3000));
154+
await this._driver.sleep(3_000);
155155
} else {
156156
throw err;
157157
}
@@ -199,14 +199,16 @@ export class VSBrowser {
199199
* @param paths path(s) of folder(s)/files(s) to open as varargs
200200
* @returns Promise resolving when all selected resources are opened and the workbench reloads
201201
*/
202-
async openResources(...paths: string[]): Promise<void> {
203-
if (paths.length === 0) {
202+
async openResources(resource: { path: string | string[]; timeout?: number; delay?: number }): Promise<void> {
203+
if (resource.path.length === 0) {
204204
return;
205205
}
206206

207207
const code = new CodeUtil(this.storagePath, this.releaseType, this.extensionsFolder);
208-
code.open(...paths);
209-
await new Promise((res) => setTimeout(res, 3000));
210-
await this.waitForWorkbench();
208+
code.open(resource.path);
209+
if (resource.delay) {
210+
await this._driver.sleep(resource.delay);
211+
}
212+
await this.waitForWorkbench(resource.timeout);
211213
}
212214
}

packages/extester/src/suite/runner.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ export class VSRunner {
9292
const start = Date.now();
9393
const binPath = process.platform === 'darwin' ? await self.createShortcut(code.getCodeFolder(), self.tmpLink) : self.chromeBin;
9494
await browser.start(binPath);
95-
await browser.openResources(...resources);
96-
await browser.waitForWorkbench();
97-
await new Promise((res) => {
98-
setTimeout(res, 3000);
99-
});
95+
await browser.openResources({ path: resources, delay: 1_500 });
96+
await browser.driver.sleep(3_000);
10097
console.log(`Browser ready in ${Date.now() - start} ms`);
10198
console.log('Launching tests...');
10299
});

packages/extester/src/util/codeUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ export class CodeUtil {
201201
* Open files/folders in running vscode
202202
* @param paths vararg paths to files or folders to open
203203
*/
204-
open(...paths: string[]): void {
205-
const segments = paths.map((f) => `"${f}"`).join(' ');
204+
open(paths: string | string[]): void {
205+
const segments = typeof paths === 'string' ? paths : paths.map((f) => `"${f}"`).join(' ');
206206
const command = `${this.getCliInitCommand()} -r ${segments} --user-data-dir="${path.join(this.downloadFolder, 'settings')}"`;
207207
childProcess.execSync(command);
208208
}

tests/test-project/src/test/bottomBar/problemsView.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('ProblemsView', function () {
2626

2727
before(async function () {
2828
this.timeout(25000);
29-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts'));
29+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts'), delay: 3_000 });
3030

3131
bar = new BottomBarPanel();
3232
await bar.toggle(true);

tests/test-project/src/test/bottomBar/views.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Output View/Text Views', function () {
2626

2727
before(async function () {
2828
this.timeout(25000);
29-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources'));
29+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources'), delay: 3_000 });
3030
await VSBrowser.instance.waitForWorkbench();
3131
});
3232

tests/test-project/src/test/debug/debug.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ describe('Debugging', function () {
4848
before(async function () {
4949
this.timeout(30000);
5050
const browser = VSBrowser.instance;
51-
await browser.openResources(folder);
51+
await browser.openResources({ path: folder });
5252
await browser.driver.sleep(5000);
53-
await browser.openResources(path.join(folder, 'test.js'));
53+
await browser.openResources({ path: path.join(folder, 'test.js') });
5454
await browser.driver.sleep(5000);
5555
view = (await (await new ActivityBar().getViewControl('Run'))?.openView()) as DebugView;
5656

tests/test-project/src/test/editor/customEditor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('CustomEditor', () => {
2525
const CUSTOM_TITLE: string = 'example.cscratch';
2626

2727
before(async () => {
28-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', CUSTOM_TITLE));
28+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', CUSTOM_TITLE) });
2929
editor = new CustomEditor();
3030
});
3131

tests/test-project/src/test/editor/diffEditor.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ describe('DiffEditor', async () => {
2424

2525
before(async function () {
2626
this.timeout(250000);
27-
await VSBrowser.instance.openResources(
28-
path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-a.txt'),
29-
path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-b.txt'),
30-
);
27+
await VSBrowser.instance.openResources({
28+
path: [
29+
path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-a.txt'),
30+
path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file-b.txt'),
31+
],
32+
});
3133
await new EditorView().openEditor('test-file-b.txt');
3234
await new Workbench().executeCommand('File: Compare Active File With...');
3335
let quickOpen: QuickOpenBox | InputBox;

tests/test-project/src/test/editor/extensionEditor.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import {
2929
WebDriver,
3030
} from 'vscode-extension-tester';
3131
import * as pjson from '../../../package.json';
32+
import * as path from 'path';
3233

3334
describe('Extension Editor', function () {
35+
this.timeout(99999999);
3436
let driver: WebDriver;
3537
let viewControl: ViewControl;
3638
let extensionsView: SideBarView;
@@ -43,19 +45,14 @@ describe('Extension Editor', function () {
4345

4446
before(async function () {
4547
driver = VSBrowser.instance.driver;
48+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') });
4649
viewControl = (await new ActivityBar().getViewControl('Extensions')) as ViewControl;
4750
extensionsView = await viewControl.openView();
4851
await driver.wait(async function () {
4952
return (await extensionsView.getContent().getSections()).length > 0;
5053
});
5154

52-
const view = await viewControl.openView();
53-
54-
await driver.wait(async function () {
55-
return (await view.getContent().getSections()).length > 0;
56-
});
57-
section = (await view.getContent().getSection('Installed')) as ExtensionsViewSection;
58-
55+
section = (await extensionsView.getContent().getSection('Installed')) as ExtensionsViewSection;
5956
await driver.wait(async function () {
6057
item = (await section.findItem(`@installed ${pjson.displayName}`)) as ExtensionsViewItem;
6158
return item !== undefined;

tests/test-project/src/test/editor/textEditor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('ContentAssist', async function () {
3838

3939
before(async () => {
4040
this.timeout(30000);
41-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts'));
41+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-file.ts') });
4242
await VSBrowser.instance.waitForWorkbench();
4343
await new Promise((res) => setTimeout(res, 2000));
4444
const ew = new EditorView();
@@ -191,7 +191,7 @@ describe('TextEditor', function () {
191191
let ew: EditorView;
192192

193193
beforeEach(async function () {
194-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', param.file));
194+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', param.file) });
195195
ew = new EditorView();
196196
await ew.getDriver().wait(
197197
async function () {

tests/test-project/src/test/menu/contextMenu.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import * as path from 'path';
2525

2626
before(async () => {
2727
this.timeout(30000);
28-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder'));
28+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') });
2929
await VSBrowser.instance.driver.sleep(5000);
3030
});
3131

tests/test-project/src/test/menu/titleBar.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import { ActivityBar, TitleBar, ContextMenu, TitleBarItem, EditorView, VSBrowser
2424

2525
before(async function () {
2626
this.timeout(30000);
27-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder'));
27+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') });
2828
await VSBrowser.instance.driver.sleep(5000);
2929
bar = new TitleBar();
3030

31-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder', 'foo'));
31+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder', 'foo') });
3232

3333
// workspace cleanup before tests
3434
await new EditorView().closeAllEditors();

tests/test-project/src/test/xsideBar/scmView.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as fs from 'fs-extra';
2626
before(async function () {
2727
this.timeout(15000);
2828
fs.writeFileSync(path.resolve('.', 'testfile'), 'content');
29-
await VSBrowser.instance.openResources(path.resolve('..', '..'));
29+
await VSBrowser.instance.openResources({ path: path.resolve('..', '..'), delay: 3_000 });
3030
await VSBrowser.instance.waitForWorkbench();
3131
view = (await ((await new ActivityBar().getViewControl('Source Control')) as ViewControl).openView()) as ScmView;
3232
await new Promise((res) => {

tests/test-project/src/test/xsideBar/sideBarView.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('SideBarView', () => {
8282

8383
before(async function () {
8484
this.timeout(15000);
85-
await VSBrowser.instance.openResources(path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder'));
85+
await VSBrowser.instance.openResources({ path: path.resolve(__dirname, '..', '..', '..', 'resources', 'test-folder') });
8686
view = await ((await new ActivityBar().getViewControl('Explorer')) as ViewControl).openView();
8787
await new Promise((res) => {
8888
setTimeout(res, 1000);

0 commit comments

Comments
 (0)