Skip to content
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

[tests] increase timeout to allow plugin views to be prepared #8151

Merged
merged 2 commits into from
Jul 20, 2020
Merged
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
1 change: 1 addition & 0 deletions dev-packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"puppeteer": "^2.0.0",
"puppeteer-to-istanbul": "^1.2.2",
"tar": "^4.0.0",
"temp": "^0.9.1",
"unzip-stream": "^0.3.0",
"yargs": "^11.1.0"
},
Expand Down
4 changes: 4 additions & 0 deletions dev-packages/cli/src/theia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import * as temp from 'temp';
import * as yargs from 'yargs';
import { ApplicationPackageManager, rebuild } from '@theia/application-manager';
import { ApplicationProps } from '@theia/application-package';
Expand Down Expand Up @@ -216,6 +217,9 @@ function rebuildCommand(command: string, target: ApplicationProps.Target): yargs
testCoverage: boolean
}) => {
try {
if (!process.env.THEIA_CONFIG_DIR) {
process.env.THEIA_CONFIG_DIR = temp.track().mkdirSync('theia-test-config-dir');
}
await runTest({
start: async () => new Promise((resolve, reject) => {
const serverArgs = commandArgs('test').filter(a => a.indexOf('--test-') !== 0);
Expand Down
4 changes: 2 additions & 2 deletions examples/api-tests/src/menus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// @ts-check
describe('Menus', function () {
this.timeout(7500);

const { assert } = chai;

Expand Down Expand Up @@ -51,8 +52,7 @@ describe('Menus', function () {

before(async function () {
await pluginService.didStart;
// register views for the explorer view container
await pluginService.activatePlugin('vscode.npm');
await pluginService.activateByViewContainer('explorer');
});

const toTearDown = new DisposableCollection();
Expand Down
15 changes: 11 additions & 4 deletions examples/api-tests/src/views.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

// @ts-check
describe('Views', function () {
this.timeout(7500);

const { assert } = chai;

Expand All @@ -24,6 +25,7 @@ describe('Views', function () {
const { ScmContribution } = require('@theia/scm/lib/browser/scm-contribution');
const { OutlineViewContribution } = require('@theia/outline-view/lib/browser/outline-view-contribution');
const { ProblemContribution } = require('@theia/markers/lib/browser/problem/problem-contribution');
const { HostedPluginSupport } = require('@theia/plugin-ext/lib/hosted/browser/hosted-plugin');

/** @type {import('inversify').Container} */
const container = window['theia'].container;
Expand All @@ -32,13 +34,18 @@ describe('Views', function () {
const scmContribution = container.get(ScmContribution);
const outlineContribution = container.get(OutlineViewContribution);
const problemContribution = container.get(ProblemContribution);
const pluginService = container.get(HostedPluginSupport);

before(() => {
shell.leftPanelHandler.collapse();
});
before(() => Promise.all([
shell.leftPanelHandler.collapse(),
(async function () {
await pluginService.didStart;
await pluginService.activateByViewContainer('explorer');
})()
]));

for (const contribution of [navigatorContribution, scmContribution, outlineContribution, problemContribution]) {
it(`should toggle ${contribution.viewLabel}`, async () => {
it(`should toggle ${contribution.viewLabel}`, async function () {
let view = await contribution.closeView();
if (view) {
assert.notEqual(shell.getAreaFor(view), contribution.defaultViewOptions.area);
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/browser/shell/tab-bar-toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ export class TabBarToolbarRegistry implements FrontendApplicationContribution {
* By default returns with all items where the command is enabled and `item.isVisible` is `true`.
*/
visibleItems(widget: Widget): Array<TabBarToolbarItem | ReactTabBarToolbarItem> {
if (widget.isDisposed) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fo instance in the side bar, the title is still visible, but associated widget is disposed since it is collapsed, with bad timing it can throw in own contributions

return [];
}
const result = [];
for (const item of this.items.values()) {
const visible = TabBarToolbarItem.is(item)
Expand Down
18 changes: 14 additions & 4 deletions packages/core/src/browser/view-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ export class ViewContainer extends BaseWidget implements StatefulWidget, Applica
}

get containerLayout(): ViewContainerLayout {
return this.panel.layout as ViewContainerLayout;
const layout = this.panel.layout;
if (layout instanceof ViewContainerLayout) {
return layout;
}
throw new Error('view container is disposed');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a widget is disposed then layout is null

}

protected get orientation(): SplitLayout.Orientation {
Expand Down Expand Up @@ -1159,7 +1163,7 @@ export class ViewContainerLayout extends SplitLayout {
}

if (!enableAnimation || this.options.animationDuration <= 0) {
MessageLoop.postMessage(this.parent!, Widget.Msg.FitRequest);
MessageLoop.postMessage(this.parent, Widget.Msg.FitRequest);
return;
}
let startTime: number | undefined = undefined;
Expand All @@ -1178,6 +1182,10 @@ export class ViewContainerLayout extends SplitLayout {

// The update function is called on every animation frame until the predefined duration has elapsed.
const updateFunc = (time: number) => {
if (!this.parent) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a widget gets closed during the animation it will throw in MessageLoop.sendMessage

part.animatedSize = undefined;
return;
}
if (startTime === undefined) {
startTime = time;
}
Expand All @@ -1199,11 +1207,13 @@ export class ViewContainerLayout extends SplitLayout {
// Request another frame to reset the part to variable size
requestAnimationFrame(() => {
part.animatedSize = undefined;
MessageLoop.sendMessage(this.parent!, Widget.Msg.FitRequest);
if (this.parent) {
MessageLoop.sendMessage(this.parent, Widget.Msg.FitRequest);
}
});
}
}
MessageLoop.sendMessage(this.parent!, Widget.Msg.FitRequest);
MessageLoop.sendMessage(this.parent, Widget.Msg.FitRequest);
};
requestAnimationFrame(updateFunc);
}
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/node/env-variables/env-variables-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import { FileUri } from '../file-uri';
export class EnvVariablesServerImpl implements EnvVariablesServer {

protected readonly envs: { [key: string]: EnvVariable } = {};
protected readonly configDirUri = FileUri.create(join(homedir(), '.theia')).toString();
protected readonly configDirUri: Promise<string>;

constructor() {
this.configDirUri = this.createConfigDirUri();
this.configDirUri.then(configDirUri => console.log(`Configuration directory URI: '${configDirUri}'`));
const prEnv = process.env;
Object.keys(prEnv).forEach((key: string) => {
let keyName = key;
Expand All @@ -38,6 +40,10 @@ export class EnvVariablesServerImpl implements EnvVariablesServer {
});
}

protected async createConfigDirUri(): Promise<string> {
return FileUri.create(process.env.THEIA_CONFIG_DIR || join(homedir(), '.theia')).toString();
}

async getExecPath(): Promise<string> {
return process.execPath;
}
Expand All @@ -53,7 +59,7 @@ export class EnvVariablesServerImpl implements EnvVariablesServer {
return this.envs[key];
}

async getConfigDirUri(): Promise<string> {
getConfigDirUri(): Promise<string> {
return this.configDirUri;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ export class HostedPluginSupport {
await Promise.all(activation);
}

async activateByViewContainer(viewContainerId: string): Promise<void> {
await Promise.all(this.viewRegistry.getContainerViews(viewContainerId).map(viewId => this.activateByView(viewId)));
}

async activateByView(viewId: string): Promise<void> {
await this.activateByEvent(`onView:${viewId}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
return toDispose;
}

getContainerViews(viewContainerId: string): string[] {
return this.containerViews.get(viewContainerId) || [];
}

registerView(viewContainerId: string, view: View): Disposable {
if (this.views.has(view.id)) {
console.warn('view with such id already registered: ', JSON.stringify(view));
Expand All @@ -256,7 +260,7 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
this.views.set(view.id, [viewContainerId, view]);
toDispose.push(Disposable.create(() => this.views.delete(view.id)));

const containerViews = this.containerViews.get(viewContainerId) || [];
const containerViews = this.getContainerViews(viewContainerId);
containerViews.push(view.id);
this.containerViews.set(viewContainerId, containerViews);
toDispose.push(Disposable.create(() => {
Expand Down Expand Up @@ -374,7 +378,7 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
const [, options] = data;
containerWidget.setTitleOptions(options);
}
for (const viewId of this.containerViews.get(viewContainerId) || []) {
for (const viewId of this.getContainerViews(viewContainerId)) {
const identifier = this.toPluginViewWidgetIdentifier(viewId);
const widget = await this.widgetManager.getOrCreateWidget<PluginViewWidget>(PLUGIN_VIEW_FACTORY_ID, identifier);
if (containerWidget.getTrackableWidgets().indexOf(widget) === -1) {
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12113,6 +12113,13 @@ temp@^0.8.1, temp@^0.8.3:
dependencies:
rimraf "~2.6.2"

temp@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.9.1.tgz#2d666114fafa26966cd4065996d7ceedd4dd4697"
integrity sha512-WMuOgiua1xb5R56lE0eH6ivpVmg/lq2OHm4+LtT/xtEtPQ+sz6N3bBM6WZ5FvO1lO4IKIOb43qnhoc4qxP5OeA==
dependencies:
rimraf "~2.6.2"

tempfile@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/tempfile/-/tempfile-1.1.1.tgz#5bcc4eaecc4ab2c707d8bc11d99ccc9a2cb287f2"
Expand Down