@theia/test 1.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/lib/browser/constants.d.ts +46 -0
  2. package/lib/browser/constants.d.ts.map +1 -0
  3. package/lib/browser/constants.js +18 -0
  4. package/lib/browser/constants.js.map +1 -0
  5. package/lib/browser/test-service.d.ts +150 -0
  6. package/lib/browser/test-service.d.ts.map +1 -0
  7. package/lib/browser/test-service.js +240 -0
  8. package/lib/browser/test-service.js.map +1 -0
  9. package/lib/browser/view/test-execution-state-manager.d.ts +14 -0
  10. package/lib/browser/view/test-execution-state-manager.d.ts.map +1 -0
  11. package/lib/browser/view/test-execution-state-manager.js +174 -0
  12. package/lib/browser/view/test-execution-state-manager.js.map +1 -0
  13. package/lib/browser/view/test-output-ui-model.d.ts +46 -0
  14. package/lib/browser/view/test-output-ui-model.d.ts.map +1 -0
  15. package/lib/browser/view/test-output-ui-model.js +140 -0
  16. package/lib/browser/view/test-output-ui-model.js.map +1 -0
  17. package/lib/browser/view/test-output-view-contribution.d.ts +6 -0
  18. package/lib/browser/view/test-output-view-contribution.d.ts.map +1 -0
  19. package/lib/browser/view/test-output-view-contribution.js +48 -0
  20. package/lib/browser/view/test-output-view-contribution.js.map +1 -0
  21. package/lib/browser/view/test-output-widget.d.ts +25 -0
  22. package/lib/browser/view/test-output-widget.d.ts.map +1 -0
  23. package/lib/browser/view/test-output-widget.js +159 -0
  24. package/lib/browser/view/test-output-widget.js.map +1 -0
  25. package/lib/browser/view/test-result-view-contribution.d.ts +6 -0
  26. package/lib/browser/view/test-result-view-contribution.d.ts.map +1 -0
  27. package/lib/browser/view/test-result-view-contribution.js +48 -0
  28. package/lib/browser/view/test-result-view-contribution.js.map +1 -0
  29. package/lib/browser/view/test-result-widget.d.ts +21 -0
  30. package/lib/browser/view/test-result-widget.d.ts.map +1 -0
  31. package/lib/browser/view/test-result-widget.js +109 -0
  32. package/lib/browser/view/test-result-widget.js.map +1 -0
  33. package/lib/browser/view/test-run-view-contribution.d.ts +18 -0
  34. package/lib/browser/view/test-run-view-contribution.d.ts.map +1 -0
  35. package/lib/browser/view/test-run-view-contribution.js +101 -0
  36. package/lib/browser/view/test-run-view-contribution.js.map +1 -0
  37. package/lib/browser/view/test-run-widget.d.ts +59 -0
  38. package/lib/browser/view/test-run-widget.d.ts.map +1 -0
  39. package/lib/browser/view/test-run-widget.js +306 -0
  40. package/lib/browser/view/test-run-widget.js.map +1 -0
  41. package/lib/browser/view/test-tree-widget.d.ts +68 -0
  42. package/lib/browser/view/test-tree-widget.d.ts.map +1 -0
  43. package/lib/browser/view/test-tree-widget.js +387 -0
  44. package/lib/browser/view/test-tree-widget.js.map +1 -0
  45. package/lib/browser/view/test-view-contribution.d.ts +46 -0
  46. package/lib/browser/view/test-view-contribution.d.ts.map +1 -0
  47. package/lib/browser/view/test-view-contribution.js +289 -0
  48. package/lib/browser/view/test-view-contribution.js.map +1 -0
  49. package/lib/browser/view/test-view-frontend-module.d.ts +7 -0
  50. package/lib/browser/view/test-view-frontend-module.d.ts.map +1 -0
  51. package/lib/browser/view/test-view-frontend-module.js +120 -0
  52. package/lib/browser/view/test-view-frontend-module.js.map +1 -0
  53. package/lib/common/collections.d.ts +47 -0
  54. package/lib/common/collections.d.ts.map +1 -0
  55. package/lib/common/collections.js +211 -0
  56. package/lib/common/collections.js.map +1 -0
  57. package/lib/common/tree-delta.d.ts +52 -0
  58. package/lib/common/tree-delta.d.ts.map +1 -0
  59. package/lib/common/tree-delta.js +241 -0
  60. package/lib/common/tree-delta.js.map +1 -0
  61. package/lib/common/tree-delta.spec.d.ts +2 -0
  62. package/lib/common/tree-delta.spec.d.ts.map +1 -0
  63. package/lib/common/tree-delta.spec.js +140 -0
  64. package/lib/common/tree-delta.spec.js.map +1 -0
  65. package/package.json +53 -0
  66. package/src/browser/constants.ts +71 -0
  67. package/src/browser/style/index.css +42 -0
  68. package/src/browser/test-service.ts +347 -0
  69. package/src/browser/view/test-execution-state-manager.ts +147 -0
  70. package/src/browser/view/test-output-ui-model.ts +148 -0
  71. package/src/browser/view/test-output-view-contribution.ts +34 -0
  72. package/src/browser/view/test-output-widget.ts +148 -0
  73. package/src/browser/view/test-result-view-contribution.ts +34 -0
  74. package/src/browser/view/test-result-widget.ts +92 -0
  75. package/src/browser/view/test-run-view-contribution.ts +89 -0
  76. package/src/browser/view/test-run-widget.tsx +266 -0
  77. package/src/browser/view/test-tree-widget.tsx +360 -0
  78. package/src/browser/view/test-view-contribution.ts +300 -0
  79. package/src/browser/view/test-view-frontend-module.ts +132 -0
  80. package/src/common/collections.ts +223 -0
  81. package/src/common/tree-delta.spec.ts +166 -0
  82. package/src/common/tree-delta.ts +259 -0
@@ -0,0 +1,360 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
18
+ import {
19
+ TreeWidget, TreeModel, TreeProps, CompositeTreeNode, ExpandableTreeNode, TreeNode, TreeImpl, NodeProps,
20
+ TREE_NODE_SEGMENT_CLASS, TREE_NODE_TAIL_CLASS, SelectableTreeNode
21
+ } from '@theia/core/lib/browser/tree';
22
+ import { ACTION_ITEM, ContextMenuRenderer, KeybindingRegistry, codicon } from '@theia/core/lib/browser';
23
+ import { IconThemeService } from '@theia/core/lib/browser/icon-theme-service';
24
+ import { ThemeService } from '@theia/core/lib/browser/theming';
25
+ import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
26
+ import { TestController, TestExecutionState, TestItem, TestService } from '../test-service';
27
+ import * as React from '@theia/core/shared/react';
28
+ import { DeltaKind, TreeDelta } from '../../common/tree-delta';
29
+ import { ActionMenuNode, CommandRegistry, Disposable, DisposableCollection, Event, MenuModelRegistry, nls } from '@theia/core';
30
+ import { TestExecutionStateManager } from './test-execution-state-manager';
31
+ import { TestOutputUIModel } from './test-output-ui-model';
32
+ import { TEST_VIEW_INLINE_MENU } from './test-view-contribution';
33
+
34
+ const ROOT_ID = 'TestTree';
35
+
36
+ export interface TestRoot extends CompositeTreeNode {
37
+ children: TestControllerNode[];
38
+ }
39
+ export namespace TestRoot {
40
+ export function is(node: unknown): node is TestRoot {
41
+ return CompositeTreeNode.is(node) && node.id === ROOT_ID;
42
+ }
43
+ }
44
+ export interface TestControllerNode extends ExpandableTreeNode {
45
+ controller: TestController;
46
+ }
47
+
48
+ export namespace TestControllerNode {
49
+ export function is(node: unknown): node is TestControllerNode {
50
+ return ExpandableTreeNode.is(node) && 'controller' in node;
51
+ }
52
+ }
53
+
54
+ export interface TestItemNode extends TreeNode {
55
+ controller: TestController;
56
+ testItem: TestItem;
57
+ }
58
+
59
+ export namespace TestItemNode {
60
+ export function is(node: unknown): node is TestItemNode {
61
+ return TreeNode.is(node) && 'testItem' in node;
62
+ }
63
+ }
64
+
65
+ @injectable()
66
+ export class TestTree extends TreeImpl {
67
+ @inject(TestService) protected readonly testService: TestService;
68
+
69
+ private controllerListeners = new Map<string, Disposable>();
70
+
71
+ @postConstruct()
72
+ init(): void {
73
+ this.testService.getControllers().forEach(controller => this.addController(controller));
74
+ this.testService.onControllersChanged(e => {
75
+ e.removed?.forEach(controller => {
76
+ this.controllerListeners.get(controller)?.dispose();
77
+ });
78
+
79
+ e.added?.forEach(controller => this.addController(controller));
80
+
81
+ this.refresh(this.root as CompositeTreeNode);
82
+ });
83
+ }
84
+
85
+ protected addController(controller: TestController): void {
86
+ const listeners = new DisposableCollection();
87
+ this.controllerListeners.set(controller.id, listeners);
88
+ listeners.push(controller.onItemsChanged(delta => {
89
+ this.processDeltas(controller, controller, delta);
90
+ }));
91
+ }
92
+
93
+ protected override async resolveChildren(parent: CompositeTreeNode): Promise<TreeNode[]> {
94
+ if (TestItemNode.is(parent)) {
95
+ parent.testItem.resolveChildren();
96
+ return Promise.resolve(parent.testItem.tests.map(test => this.createTestNode(parent.controller, parent, test)));
97
+ } else if (TestControllerNode.is(parent)) {
98
+ return Promise.resolve(parent.controller.tests.map(test => this.createTestNode(parent.controller, parent, test)));
99
+ } else if (TestRoot.is(parent)) {
100
+ return Promise.resolve(this.testService.getControllers().map(controller => this.createControllerNode(parent, controller)));
101
+ } else {
102
+ return Promise.resolve([]);
103
+ }
104
+ }
105
+
106
+ createControllerNode(parent: CompositeTreeNode, controller: TestController): TestControllerNode {
107
+ const node: TestControllerNode = {
108
+ id: controller.id,
109
+ name: controller.label,
110
+ controller: controller,
111
+ expanded: false,
112
+ children: [],
113
+ parent: parent
114
+ };
115
+
116
+ return node;
117
+ }
118
+
119
+ protected processDeltas(controller: TestController, parent: TestItem | TestController, deltas: TreeDelta<string, TestItem>[]): void {
120
+ deltas.forEach(delta => this.processDelta(controller, parent, delta));
121
+ }
122
+
123
+ protected processDelta(controller: TestController, parent: TestItem | TestController, delta: TreeDelta<string, TestItem>): void {
124
+ if (delta.type === DeltaKind.ADDED || delta.type === DeltaKind.REMOVED) {
125
+ let node;
126
+ if (parent === controller && delta.path.length === 1) {
127
+ node = this.getNode(this.computeId([controller.id]));
128
+ } else {
129
+ const item = this.findInParent(parent, delta.path.slice(0, delta.path.length - 1), 0);
130
+ if (item) {
131
+ node = this.getNode(this.computeId(this.computePath(controller, item as TestItem)));
132
+ }
133
+ }
134
+ if (node) {
135
+ this.refresh(node as CompositeTreeNode); // we only have composite tree nodes in this tree
136
+ } else {
137
+ console.warn('delta for unknown test item');
138
+ }
139
+ } else {
140
+ const item = this.findInParent(parent, delta.path, 0);
141
+ if (item) {
142
+ if (delta.type === DeltaKind.CHANGED) {
143
+ this.fireChanged();
144
+ }
145
+ if (delta.childDeltas) {
146
+ this.processDeltas(controller, item, delta.childDeltas);
147
+ }
148
+ } else {
149
+ console.warn('delta for unknown test item');
150
+ }
151
+ }
152
+ }
153
+
154
+ protected findInParent(root: TestItem | TestController, path: string[], startIndex: number): TestItem | TestController | undefined {
155
+ if (startIndex >= path.length) {
156
+ return root;
157
+ }
158
+ const child = root.tests.find(candidate => candidate.id === path[startIndex]);
159
+ if (!child) {
160
+ return undefined;
161
+ }
162
+ return this.findInParent(child, path, startIndex + 1);
163
+ }
164
+
165
+ protected computePath(controller: TestController, item: TestItem): string[] {
166
+ const result: string[] = [controller.id];
167
+ let current: TestItem | undefined = item;
168
+ while (current) {
169
+ result.unshift(current.id);
170
+ current = current.parent;
171
+ }
172
+ return result;
173
+ }
174
+
175
+ protected computeId(path: string[]): string {
176
+ return path.map(id => id.replace('/', '//')).join('/');
177
+ }
178
+
179
+ createTestNode(controller: TestController, parent: CompositeTreeNode, test: TestItem): TestItemNode {
180
+ const previous = this.getNode(test.id);
181
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
+ const result: any = {
183
+ id: this.computeId(this.computePath(controller, test)),
184
+ name: test.label,
185
+ controller: controller,
186
+ testItem: test,
187
+ expanded: ExpandableTreeNode.is(previous) ? previous.expanded : undefined,
188
+ selected: false,
189
+ children: [] as TestItemNode[],
190
+ parent: parent
191
+ };
192
+ result.children = test.tests.map(t => this.createTestNode(controller, result, t));
193
+ if (result.children.length === 0 && !test.canResolveChildren) {
194
+ delete result.expanded;
195
+ }
196
+ return result;
197
+ }
198
+ }
199
+
200
+ @injectable()
201
+ export class TestTreeWidget extends TreeWidget {
202
+
203
+ static ID = 'test-tree-widget';
204
+
205
+ static TEST_CONTEXT_MENU = ['RESOURCE_CONTEXT_MENU'];
206
+
207
+ @inject(IconThemeService) protected readonly iconThemeService: IconThemeService;
208
+ @inject(ContextKeyService) protected readonly contextKeys: ContextKeyService;
209
+ @inject(ThemeService) protected readonly themeService: ThemeService;
210
+ @inject(TestExecutionStateManager) protected readonly stateManager: TestExecutionStateManager;
211
+ @inject(TestOutputUIModel) protected uiModel: TestOutputUIModel;
212
+ @inject(MenuModelRegistry) protected readonly menus: MenuModelRegistry;
213
+ @inject(CommandRegistry) readonly commands: CommandRegistry;
214
+ @inject(KeybindingRegistry) protected readonly keybindings: KeybindingRegistry;
215
+
216
+ constructor(
217
+ @inject(TreeProps) props: TreeProps,
218
+ @inject(TreeModel) model: TreeModel,
219
+ @inject(ContextMenuRenderer) contextMenuRenderer: ContextMenuRenderer,
220
+ ) {
221
+ super(props, model, contextMenuRenderer);
222
+ this.id = TestTreeWidget.ID;
223
+ this.title.label = nls.localizeByDefault('Test Explorer');
224
+ this.title.caption = nls.localizeByDefault('Test Explorer');
225
+ this.title.iconClass = codicon('beaker');
226
+ this.title.closable = true;
227
+ }
228
+
229
+ @postConstruct()
230
+ protected override init(): void {
231
+ super.init();
232
+ this.addClass('theia-test-view');
233
+ this.model.root = {
234
+ id: ROOT_ID,
235
+ parent: undefined,
236
+ visible: false,
237
+ children: []
238
+ } as TestRoot;
239
+
240
+ this.uiModel.onDidChangeActiveTestRun(e => this.update());
241
+ this.uiModel.onDidChangeActiveTestState(() => this.update());
242
+
243
+ this.model.onSelectionChanged(() => {
244
+ const that = this;
245
+ const node = this.model.selectedNodes[0];
246
+ if (TestItemNode.is(node)) {
247
+ const run = that.uiModel.getActiveTestRun(node.controller);
248
+ if (run) {
249
+ const output = run?.getOutput(node.testItem);
250
+ if (output) {
251
+ this.uiModel.selectedOutputSource = {
252
+ output: output,
253
+ onDidAddTestOutput: Event.map(run.onDidChangeTestOutput, evt => evt.filter(item => item[0] === node.testItem).map(item => item[1]))
254
+ };
255
+ }
256
+ this.uiModel.selectedTestState = run.getTestState(node.testItem);
257
+ }
258
+ }
259
+ });
260
+ }
261
+
262
+ protected override renderTree(model: TreeModel): React.ReactNode {
263
+ if (TestRoot.is(model.root) && model.root.children.length > 0) {
264
+ return super.renderTree(model);
265
+ }
266
+ return <div className='theia-widget-noInfo noMarkers'>{nls.localizeByDefault('No tests have been found in this workspace yet.')}</div>;
267
+ }
268
+
269
+ protected getTestStateClass(state: TestExecutionState | undefined): string {
270
+ switch (state) {
271
+ case TestExecutionState.Queued: return `${codicon('history')} queued`;
272
+ case TestExecutionState.Running: return `${codicon('sync')} codicon-modifier-spin running`;
273
+ case TestExecutionState.Skipped: return `${codicon('debug-step-over')} skipped`;
274
+ case TestExecutionState.Failed: return `${codicon('error')} failed`;
275
+ case TestExecutionState.Errored: return `${codicon('issues')} errored`;
276
+ case TestExecutionState.Passed: return `${codicon('pass')} passed`;
277
+ case TestExecutionState.Running: return `${codicon('sync-spin')} running`;
278
+ default: return codicon('circle');
279
+ }
280
+ }
281
+
282
+ protected override renderIcon(node: TreeNode, props: NodeProps): React.ReactNode {
283
+ if (TestItemNode.is(node)) {
284
+ const currentRun = this.uiModel.getActiveTestRun(node.controller);
285
+ let state;
286
+ if (currentRun) {
287
+ state = currentRun.getTestState(node.testItem)?.state;
288
+ if (!state) {
289
+ state = this.stateManager.getComputedState(currentRun, node.testItem);
290
+ }
291
+ }
292
+ return <div className={this.getTestStateClass(state)}></div >;
293
+ } else {
294
+ return super.renderIcon(node, props);
295
+ }
296
+ }
297
+
298
+ protected override renderTailDecorations(node: TreeNode, props: NodeProps): React.ReactNode {
299
+ if (TestItemNode.is(node)) {
300
+ const testItem = node.testItem;
301
+ return this.contextKeys.with({ view: this.id, controllerId: node.controller.id, testId: testItem.id, testItemHasUri: !!testItem.uri }, () => {
302
+ const menu = this.menus.getMenu(TEST_VIEW_INLINE_MENU);
303
+ const args = [node.testItem];
304
+ const inlineCommands = menu.children.filter((item): item is ActionMenuNode => item instanceof ActionMenuNode);
305
+ const tailDecorations = super.renderTailDecorations(node, props);
306
+ return <React.Fragment>
307
+ {inlineCommands.length > 0 && <div className={TREE_NODE_SEGMENT_CLASS + ' flex'}>
308
+ {inlineCommands.map((item, index) => this.renderInlineCommand(item, index, this.focusService.hasFocus(node), args))}
309
+ </div>}
310
+ {tailDecorations !== undefined && <div className={TREE_NODE_SEGMENT_CLASS + ' flex'}>{tailDecorations}</div>}
311
+ </React.Fragment>;
312
+ });
313
+ } else {
314
+ return super.renderTailDecorations(node, props);
315
+ }
316
+ }
317
+
318
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
319
+ protected renderInlineCommand(actionMenuNode: ActionMenuNode, index: number, tabbable: boolean, args: any[]): React.ReactNode {
320
+ if (!actionMenuNode.icon || !this.commands.isVisible(actionMenuNode.command, ...args) || (actionMenuNode.when && !this.contextKeys.match(actionMenuNode.when))) {
321
+ return false;
322
+ }
323
+ const className = [TREE_NODE_SEGMENT_CLASS, TREE_NODE_TAIL_CLASS, actionMenuNode.icon, ACTION_ITEM, 'theia-test-tree-inline-action'].join(' ');
324
+ const tabIndex = tabbable ? 0 : undefined;
325
+ const titleString = actionMenuNode.label + this.resolveKeybindingForCommand(actionMenuNode.command);
326
+
327
+ return <div key={index} className={className} title={titleString} tabIndex={tabIndex} onClick={e => {
328
+ e.stopPropagation();
329
+ this.commands.executeCommand(actionMenuNode.command, ...args);
330
+ }} />;
331
+ }
332
+
333
+ protected resolveKeybindingForCommand(command: string | undefined): string {
334
+ let result = '';
335
+ if (command) {
336
+ const bindings = this.keybindings.getKeybindingsForCommand(command);
337
+ let found = false;
338
+ if (bindings && bindings.length > 0) {
339
+ bindings.forEach(binding => {
340
+ if (!found && this.keybindings.isEnabledInScope(binding, this.node)) {
341
+ found = true;
342
+ result = ` (${this.keybindings.acceleratorFor(binding, '+')})`;
343
+ }
344
+ });
345
+ }
346
+ }
347
+ return result;
348
+ }
349
+
350
+ protected override toContextMenuArgs(node: SelectableTreeNode): (TestItem)[] {
351
+ if (TestItemNode.is(node)) {
352
+ return [node.testItem];
353
+ }
354
+ return [];
355
+ }
356
+
357
+ override storeState(): object {
358
+ return {}; // don't store any state for now
359
+ }
360
+ }
@@ -0,0 +1,300 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 STMicroelectronics and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { AbstractViewContribution, FrontendApplicationContribution, ViewContainerTitleOptions, Widget, codicon } from '@theia/core/lib/browser';
18
+ import { Command, CommandRegistry, MenuModelRegistry, nls } from '@theia/core';
19
+ import { inject, injectable } from '@theia/core/shared/inversify';
20
+ import { TestItem, TestRunProfileKind, TestService } from '../test-service';
21
+ import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
22
+ import { TestTreeWidget } from './test-tree-widget';
23
+ import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
24
+ import { TestCommandId } from '../constants';
25
+ import { NavigationLocationService } from '@theia/editor/lib/browser/navigation/navigation-location-service';
26
+ import { NavigationLocation } from '@theia/editor/lib/browser/navigation/navigation-location';
27
+ import { FileService } from '@theia/filesystem/lib/browser/file-service';
28
+ import { FileNavigatorCommands } from '@theia/navigator/lib/browser/file-navigator-commands';
29
+
30
+ export namespace TestViewCommands {
31
+ /**
32
+ * Command which refreshes all test.
33
+ */
34
+ export const REFRESH: Command = Command.toDefaultLocalizedCommand({
35
+ id: TestCommandId.RefreshTestsAction,
36
+ label: 'Refresh Tests',
37
+ category: 'Test',
38
+ iconClass: codicon('refresh')
39
+ });
40
+
41
+ /**
42
+ * Command which cancels the refresh
43
+ */
44
+ export const CANCEL_REFRESH: Command = Command.toDefaultLocalizedCommand({
45
+ id: TestCommandId.CancelTestRefreshAction,
46
+ label: 'Cancel Test Refresh',
47
+ category: 'Test',
48
+ iconClass: codicon('stop')
49
+ });
50
+
51
+ export const RUN_ALL_TESTS: Command = Command.toDefaultLocalizedCommand({
52
+ id: TestCommandId.RunAllAction,
53
+ label: 'Run All Tests',
54
+ category: 'Test',
55
+ iconClass: codicon('run-all')
56
+ });
57
+
58
+ export const DEBUG_ALL_TESTS: Command = Command.toDefaultLocalizedCommand({
59
+ id: TestCommandId.DebugAllAction,
60
+ label: 'Debug Tests',
61
+ category: 'Test',
62
+ iconClass: codicon('debug-all')
63
+ });
64
+
65
+ export const RUN_TEST: Command = Command.toDefaultLocalizedCommand({
66
+ id: TestCommandId.RunAction,
67
+ label: 'Run Test',
68
+ category: 'Test',
69
+ iconClass: codicon('run')
70
+ });
71
+
72
+ export const RUN_TEST_WITH_PROFILE: Command = Command.toDefaultLocalizedCommand({
73
+ id: TestCommandId.RunUsingProfileAction,
74
+ category: 'Test',
75
+ label: 'Execute using Profile...'
76
+ });
77
+
78
+ export const DEBUG_TEST: Command = Command.toDefaultLocalizedCommand({
79
+ id: TestCommandId.DebugAction,
80
+ label: 'Debug Test',
81
+ category: 'Test',
82
+ iconClass: codicon('debug-alt')
83
+ });
84
+
85
+ export const CANCEL_ALL_RUNS: Command = Command.toLocalizedCommand({
86
+ id: 'testing.cancelAllRuns',
87
+ label: 'Cancel All Test Runs',
88
+ category: 'Test',
89
+ iconClass: codicon('debug-stop')
90
+ }, 'theia/test/cancelAllTestRuns', nls.getDefaultKey('Test'));
91
+
92
+ export const CANCEL_RUN: Command = Command.toDefaultLocalizedCommand({
93
+ id: TestCommandId.CancelTestRunAction,
94
+ label: 'Cancel Test Run',
95
+ category: 'Test',
96
+ iconClass: codicon('debug-stop')
97
+ });
98
+
99
+ export const GOTO_TEST: Command = Command.toDefaultLocalizedCommand({
100
+ id: TestCommandId.GoToTest,
101
+ label: 'Go to Test',
102
+ category: 'Test',
103
+ iconClass: codicon('go-to-file')
104
+ });
105
+
106
+ export const CONFIGURE_PROFILES: Command = Command.toDefaultLocalizedCommand({
107
+ id: TestCommandId.ConfigureTestProfilesAction,
108
+ label: 'Configure Test Profiles',
109
+ category: 'Test'
110
+ });
111
+
112
+ export const CLEAR_ALL_RESULTS: Command = Command.toDefaultLocalizedCommand({
113
+ id: TestCommandId.ClearTestResultsAction,
114
+ label: 'Clear All Results',
115
+ category: 'Test',
116
+ iconClass: codicon('trash')
117
+ });
118
+ }
119
+
120
+ export const TEST_VIEW_CONTEXT_MENU = ['test-view-context-menu'];
121
+ export const TEST_VIEW_INLINE_MENU = [...TEST_VIEW_CONTEXT_MENU, 'inline'];
122
+
123
+ export const TEST_VIEW_CONTAINER_ID = 'test-view-container';
124
+ export const TEST_VIEW_CONTAINER_TITLE_OPTIONS: ViewContainerTitleOptions = {
125
+ label: nls.localizeByDefault('Testing'),
126
+ iconClass: codicon('beaker'),
127
+ closeable: true
128
+ };
129
+
130
+ @injectable()
131
+ export class TestViewContribution extends AbstractViewContribution<TestTreeWidget> implements
132
+ FrontendApplicationContribution, TabBarToolbarContribution {
133
+
134
+ @inject(TestService) protected readonly testService: TestService;
135
+ @inject(ContextKeyService) protected readonly contextKeys: ContextKeyService;
136
+ @inject(NavigationLocationService) navigationService: NavigationLocationService;
137
+ @inject(FileService) fileSystem: FileService;
138
+
139
+ constructor() {
140
+ super({
141
+ viewContainerId: TEST_VIEW_CONTAINER_ID,
142
+ widgetId: TestTreeWidget.ID,
143
+ widgetName: nls.localizeByDefault('Test Explorer'),
144
+ defaultWidgetOptions: {
145
+ area: 'left',
146
+ rank: 600,
147
+ }
148
+ });
149
+ }
150
+
151
+ async initializeLayout(): Promise<void> {
152
+ await this.openView({ activate: false });
153
+ }
154
+
155
+ override registerCommands(commands: CommandRegistry): void {
156
+ super.registerCommands(commands);
157
+ commands.registerCommand(TestViewCommands.REFRESH, {
158
+ isEnabled: w => this.withWidget(w, () => !this.testService.isRefreshing),
159
+ isVisible: w => this.withWidget(w, () => !this.testService.isRefreshing),
160
+ execute: () => this.testService.refresh()
161
+ });
162
+
163
+ commands.registerCommand(TestViewCommands.CANCEL_REFRESH, {
164
+ isEnabled: w => this.withWidget(w, () => this.testService.isRefreshing),
165
+ isVisible: w => this.withWidget(w, () => this.testService.isRefreshing),
166
+ execute: () => this.testService.cancelRefresh()
167
+ });
168
+
169
+ commands.registerCommand(TestViewCommands.RUN_ALL_TESTS, {
170
+ isEnabled: w => this.withWidget(w, () => true),
171
+ isVisible: w => this.withWidget(w, () => true),
172
+ execute: () => this.testService.runAllTests(TestRunProfileKind.Run)
173
+ });
174
+
175
+ commands.registerCommand(TestViewCommands.DEBUG_ALL_TESTS, {
176
+ isEnabled: w => this.withWidget(w, () => true),
177
+ isVisible: w => this.withWidget(w, () => true),
178
+ execute: () => this.testService.runAllTests(TestRunProfileKind.Debug)
179
+ });
180
+
181
+ commands.registerCommand(TestViewCommands.RUN_TEST, {
182
+ isEnabled: t => TestItem.is(t),
183
+ isVisible: t => TestItem.is(t),
184
+ execute: t => {
185
+ this.testService.runTests(TestRunProfileKind.Run, [t]);
186
+ }
187
+ });
188
+
189
+ commands.registerCommand(TestViewCommands.DEBUG_TEST, {
190
+ isEnabled: t => TestItem.is(t),
191
+ isVisible: t => TestItem.is(t),
192
+ execute: t => {
193
+ this.testService.runTests(TestRunProfileKind.Debug, [t]);
194
+ }
195
+ });
196
+
197
+ commands.registerCommand(TestViewCommands.RUN_TEST_WITH_PROFILE, {
198
+ isEnabled: t => TestItem.is(t),
199
+ isVisible: t => TestItem.is(t),
200
+ execute: t => {
201
+ this.testService.runTestsWithProfile([t]);
202
+ }
203
+ });
204
+
205
+ commands.registerCommand(TestViewCommands.CANCEL_ALL_RUNS, {
206
+ isEnabled: w => this.withWidget(w, () => true),
207
+ isVisible: w => this.withWidget(w, () => true),
208
+ execute: () => this.cancelAllRuns()
209
+ });
210
+
211
+ commands.registerCommand(TestViewCommands.GOTO_TEST, {
212
+ isEnabled: t => TestItem.is(t) && !!t.uri,
213
+ isVisible: t => TestItem.is(t) && !!t.uri,
214
+ execute: t => {
215
+ if (TestItem.is(t)) {
216
+ this.fileSystem.resolve(t.uri!).then(stat => {
217
+ if (stat.isFile) {
218
+ this.navigationService.reveal(NavigationLocation.create(t.uri!, t.range ? t.range.start : { line: 0, character: 0 }));
219
+ } else {
220
+ commands.executeCommand(FileNavigatorCommands.REVEAL_IN_NAVIGATOR.id, t.uri!);
221
+ }
222
+ });
223
+ }
224
+ }
225
+ });
226
+
227
+ commands.registerCommand(TestViewCommands.CONFIGURE_PROFILES, {
228
+ execute: () => {
229
+ this.testService.configureProfile();
230
+ }
231
+ });
232
+ }
233
+
234
+ protected cancelAllRuns(): void {
235
+ this.testService.getControllers().forEach(controller => controller.testRuns.forEach(run => run.cancel()));
236
+ }
237
+
238
+ override registerMenus(menus: MenuModelRegistry): void {
239
+ super.registerMenus(menus);
240
+ menus.registerMenuAction(TEST_VIEW_INLINE_MENU, {
241
+ commandId: TestViewCommands.RUN_TEST.id,
242
+ order: 'a'
243
+ });
244
+ menus.registerMenuAction(TEST_VIEW_INLINE_MENU, {
245
+ commandId: TestViewCommands.DEBUG_TEST.id,
246
+ order: 'aa'
247
+ });
248
+ menus.registerMenuAction(TEST_VIEW_INLINE_MENU, {
249
+ commandId: TestViewCommands.GOTO_TEST.id,
250
+ order: 'aaa'
251
+ });
252
+
253
+ menus.registerMenuAction(TEST_VIEW_CONTEXT_MENU, {
254
+ commandId: TestViewCommands.RUN_TEST_WITH_PROFILE.id,
255
+ order: 'aaaa'
256
+ });
257
+ }
258
+
259
+ registerToolbarItems(toolbar: TabBarToolbarRegistry): void {
260
+ toolbar.registerItem({
261
+ id: TestViewCommands.REFRESH.id,
262
+ command: TestViewCommands.REFRESH.id,
263
+ priority: 0,
264
+ onDidChange: this.testService.onDidChangeIsRefreshing
265
+ });
266
+
267
+ toolbar.registerItem({
268
+ id: TestViewCommands.CANCEL_REFRESH.id,
269
+ command: TestViewCommands.CANCEL_REFRESH.id,
270
+ priority: 0,
271
+ onDidChange: this.testService.onDidChangeIsRefreshing
272
+ });
273
+
274
+ toolbar.registerItem({
275
+ id: TestViewCommands.RUN_ALL_TESTS.id,
276
+ command: TestViewCommands.RUN_ALL_TESTS.id,
277
+ priority: 1
278
+ });
279
+
280
+ toolbar.registerItem({
281
+ id: TestViewCommands.DEBUG_ALL_TESTS.id,
282
+ command: TestViewCommands.DEBUG_ALL_TESTS.id,
283
+ priority: 2
284
+ });
285
+
286
+ toolbar.registerItem({
287
+ id: TestViewCommands.CANCEL_ALL_RUNS.id,
288
+ command: TestViewCommands.CANCEL_ALL_RUNS.id,
289
+ priority: 3
290
+ });
291
+
292
+ }
293
+
294
+ protected withWidget<T>(widget: Widget | undefined = this.tryGetWidget(), cb: (widget: TestTreeWidget) => T): T | false {
295
+ if (widget instanceof TestTreeWidget && widget.id === TestTreeWidget.ID) {
296
+ return cb(widget);
297
+ }
298
+ return false;
299
+ }
300
+ }