@theia/test 1.53.0-next.55 → 1.53.0-next.64

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.
@@ -1,360 +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
- }
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
+ }