@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,147 @@
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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
+ import { TestController, TestExecutionState, TestItem, TestRun, TestService } from '../test-service';
19
+
20
+ /**
21
+ * This class manages the state of "internal" nodes in the test tree
22
+ */
23
+ @injectable()
24
+ export class TestExecutionStateManager {
25
+ @inject(TestService)
26
+ protected readonly testService: TestService;
27
+
28
+ private executionStates = new Map<TestRun, TestExecutionStateMap>();
29
+
30
+ @postConstruct()
31
+ init(): void {
32
+ this.testService.getControllers().forEach(controller => this.addController(controller));
33
+ this.testService.onControllersChanged(controllerDelta => {
34
+ controllerDelta.added?.forEach(controller => this.addController(controller));
35
+ });
36
+ }
37
+ addController(controller: TestController): void {
38
+ controller.testRuns.forEach(run => this.addRun(run));
39
+ controller.onRunsChanged(runDelta => {
40
+ runDelta.added?.forEach(run => this.addRun(run));
41
+ runDelta.removed?.forEach(run => {
42
+ this.executionStates.delete(run);
43
+ });
44
+ });
45
+ }
46
+ addRun(run: TestRun): void {
47
+ this.executionStates.set(run, new TestExecutionStateMap);
48
+ run.onDidChangeTestState(updates => {
49
+ updates.forEach(update => {
50
+ this.updateState(run, update.test, update.oldState?.state, update.newState?.state);
51
+ });
52
+ });
53
+ }
54
+
55
+ protected updateState(run: TestRun, item: TestItem, oldState: TestExecutionState | undefined, newState: TestExecutionState | undefined): void {
56
+ const map = this.executionStates.get(run)!;
57
+ map.reportState(item, oldState, newState);
58
+ }
59
+
60
+ getComputedState(run: TestRun, item: TestItem): TestExecutionState | undefined {
61
+ return this.executionStates.get(run)?.getComputedState(item);
62
+ }
63
+ }
64
+
65
+ class TestExecutionStateMap {
66
+ reportState(item: TestItem, oldState: TestExecutionState | undefined, newState: TestExecutionState | undefined): void {
67
+ if (oldState !== newState) {
68
+ if (item.parent) {
69
+ this.reportChildStateChanged(item.parent, oldState, newState);
70
+ }
71
+ }
72
+ }
73
+ reportChildStateChanged(parent: TestItem, oldState: TestExecutionState | undefined, newState: TestExecutionState | undefined): void {
74
+ if (oldState !== newState) {
75
+ const currentParentState = this.getComputedState(parent);
76
+ let counts = this.stateCounts.get(parent);
77
+ if (!counts) {
78
+ counts = [];
79
+ counts[TestExecutionState.Queued] = 0;
80
+ counts[TestExecutionState.Running] = 0;
81
+ counts[TestExecutionState.Passed] = 0;
82
+ counts[TestExecutionState.Failed] = 0;
83
+ counts[TestExecutionState.Skipped] = 0;
84
+ counts[TestExecutionState.Errored] = 0;
85
+ this.stateCounts.set(parent, counts);
86
+ }
87
+ if (oldState) {
88
+ counts[oldState]--;
89
+ }
90
+ if (newState) {
91
+ counts[newState]++;
92
+ }
93
+ const newParentState = this.getComputedState(parent);
94
+ if (parent.parent && currentParentState !== newParentState) {
95
+ this.reportChildStateChanged(parent.parent, currentParentState, newParentState!);
96
+ }
97
+ }
98
+ }
99
+
100
+ private stateCounts: Map<TestItem | TestController, number[]> = new Map();
101
+
102
+ updateState(item: TestItem, oldState: TestExecutionState | undefined, newState: TestExecutionState): void {
103
+ let parent = item.parent;
104
+ while (parent && 'parent' in parent) { // parent is a test item
105
+ let counts = this.stateCounts.get(parent);
106
+ if (!counts) {
107
+ counts = [];
108
+ counts[TestExecutionState.Queued] = 0;
109
+ counts[TestExecutionState.Running] = 0;
110
+ counts[TestExecutionState.Passed] = 0;
111
+ counts[TestExecutionState.Failed] = 0;
112
+ counts[TestExecutionState.Skipped] = 0;
113
+ counts[TestExecutionState.Errored] = 0;
114
+ this.stateCounts.set(parent, counts);
115
+ }
116
+ if (oldState) {
117
+ counts[oldState]--;
118
+ }
119
+ counts[newState]++;
120
+ parent = parent.parent;
121
+ }
122
+ }
123
+
124
+ getComputedState(item: TestItem): TestExecutionState | undefined {
125
+ const counts = this.stateCounts.get(item);
126
+ if (counts) {
127
+ if (counts[TestExecutionState.Errored] > 0) {
128
+ return TestExecutionState.Errored;
129
+ } else if (counts[TestExecutionState.Failed] > 0) {
130
+ return TestExecutionState.Failed;
131
+ } else if (counts[TestExecutionState.Running] > 0) {
132
+ return TestExecutionState.Running;
133
+ } else if (counts[TestExecutionState.Queued] > 0) {
134
+ return TestExecutionState.Queued;
135
+ } else if (counts[TestExecutionState.Passed] > 0) {
136
+ return TestExecutionState.Passed;
137
+ } else if (counts[TestExecutionState.Skipped] > 0) {
138
+ return TestExecutionState.Skipped;
139
+ } else {
140
+ return undefined;
141
+ }
142
+ } else {
143
+ return undefined;
144
+ }
145
+ }
146
+ }
147
+
@@ -0,0 +1,148 @@
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 { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
18
+ import { TestController, TestOutputItem, TestRun, TestService, TestState, TestStateChangedEvent } from '../test-service';
19
+ import { Disposable, Emitter, Event } from '@theia/core';
20
+
21
+ export interface ActiveRunEvent {
22
+ controller: TestController;
23
+ activeRun: TestRun | undefined
24
+ }
25
+
26
+ export interface TestOutputSource {
27
+ readonly output: readonly TestOutputItem[];
28
+ onDidAddTestOutput: Event<TestOutputItem[]>;
29
+ }
30
+
31
+ export interface ActiveTestStateChangedEvent {
32
+ controller: TestController;
33
+ testRun: TestRun;
34
+ statedDelta: TestStateChangedEvent[];
35
+ }
36
+
37
+ interface ActiveTestRunInfo {
38
+ run: TestRun;
39
+ toDispose: Disposable;
40
+ }
41
+
42
+ @injectable()
43
+ export class TestOutputUIModel {
44
+ @inject(TestService) protected testService: TestService;
45
+
46
+ protected readonly activeRuns = new Map<string, ActiveTestRunInfo>();
47
+ protected readonly controllerListeners = new Map<string, Disposable>();
48
+ private _selectedOutputSource: TestOutputSource | undefined;
49
+ private _selectedTestState: TestState | undefined;
50
+
51
+ @postConstruct()
52
+ init(): void {
53
+ this.testService.getControllers().forEach(controller => this.addController(controller));
54
+ this.testService.onControllersChanged(deltas => {
55
+ deltas.added?.forEach(controller => this.addController(controller));
56
+ deltas.removed?.forEach(controller => this.removeController(controller));
57
+ });
58
+ }
59
+
60
+ protected removeController(id: string): void {
61
+ this.controllerListeners.get(id)?.dispose();
62
+ if (this.activeRuns.has(id)) {
63
+ this.activeRuns.delete(id);
64
+ }
65
+ }
66
+
67
+ protected addController(controller: TestController): void {
68
+ this.controllerListeners.set(controller.id, controller.onRunsChanged(delta => {
69
+ if (delta.added) {
70
+ const currentRun = controller.testRuns[controller.testRuns.length - 1];
71
+ if (currentRun) {
72
+ this.setActiveTestRun(currentRun);
73
+ }
74
+ } else {
75
+ delta.removed?.forEach(run => {
76
+ if (run === this.getActiveTestRun(controller)) {
77
+ const currentRun = controller.testRuns[controller.testRuns.length - 1];
78
+ this.doSetActiveRun(controller, currentRun);
79
+ }
80
+ });
81
+ }
82
+ }));
83
+ }
84
+
85
+ getActiveTestRun(controller: TestController): TestRun | undefined {
86
+ return this.activeRuns.get(controller.id)?.run;
87
+ }
88
+
89
+ protected readonly onDidChangeActiveTestRunEmitter = new Emitter<ActiveRunEvent>();
90
+ onDidChangeActiveTestRun: Event<ActiveRunEvent> = this.onDidChangeActiveTestRunEmitter.event;
91
+
92
+ setActiveTestRun(run: TestRun): void {
93
+ this.doSetActiveRun(run.controller, run);
94
+ }
95
+
96
+ doSetActiveRun(controller: TestController, run: TestRun | undefined): void {
97
+ const old = this.activeRuns.get(controller.id);
98
+ if (old !== run) {
99
+ if (old) {
100
+ old.toDispose.dispose();
101
+ }
102
+ if (run) {
103
+ const toDispose = run.onDidChangeTestState(e => {
104
+ this.onDidChangeActiveTestStateEmitter.fire({
105
+ controller,
106
+ testRun: run,
107
+ statedDelta: e
108
+ });
109
+ });
110
+ this.activeRuns.set(controller.id, { run, toDispose });
111
+ } else {
112
+ this.activeRuns.delete(controller.id);
113
+ }
114
+ this.onDidChangeActiveTestRunEmitter.fire({ activeRun: run, controller: controller });
115
+ }
116
+ }
117
+
118
+ private onDidChangeActiveTestStateEmitter: Emitter<ActiveTestStateChangedEvent> = new Emitter();
119
+ onDidChangeActiveTestState: Event<ActiveTestStateChangedEvent> = this.onDidChangeActiveTestStateEmitter.event;
120
+
121
+ get selectedOutputSource(): TestOutputSource | undefined {
122
+ return this._selectedOutputSource;
123
+ }
124
+
125
+ set selectedOutputSource(element: TestOutputSource | undefined) {
126
+ if (element !== this._selectedOutputSource) {
127
+ this._selectedOutputSource = element;
128
+ this.onDidChangeSelectedOutputSourceEmitter.fire(element);
129
+ }
130
+ }
131
+
132
+ protected readonly onDidChangeSelectedOutputSourceEmitter = new Emitter<TestOutputSource | undefined>();
133
+ readonly onDidChangeSelectedOutputSource: Event<TestOutputSource | undefined> = this.onDidChangeSelectedOutputSourceEmitter.event;
134
+
135
+ get selectedTestState(): TestState | undefined {
136
+ return this._selectedTestState;
137
+ }
138
+
139
+ set selectedTestState(element: TestState | undefined) {
140
+ if (element !== this._selectedTestState) {
141
+ this._selectedTestState = element;
142
+ this.onDidChangeSelectedTestStateEmitter.fire(element);
143
+ }
144
+ }
145
+
146
+ protected readonly onDidChangeSelectedTestStateEmitter = new Emitter<TestState | undefined>();
147
+ readonly onDidChangeSelectedTestState: Event<TestState | undefined> = this.onDidChangeSelectedTestStateEmitter.event;
148
+ }
@@ -0,0 +1,34 @@
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 } from '@theia/core/lib/browser';
18
+ import { TestOutputWidget } from './test-output-widget';
19
+ import { injectable } from '@theia/core/shared/inversify';
20
+ import { nls } from '@theia/core';
21
+
22
+ @injectable()
23
+ export class TestOutputViewContribution extends AbstractViewContribution<TestOutputWidget> {
24
+ constructor() {
25
+ super({
26
+ widgetId: TestOutputWidget.ID,
27
+ widgetName: nls.localizeByDefault('Test Output'),
28
+ defaultWidgetOptions: {
29
+ area: 'bottom'
30
+ }
31
+ });
32
+
33
+ }
34
+ }
@@ -0,0 +1,148 @@
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
+ import { RendererType, Terminal } from 'xterm';
17
+ import { FitAddon } from 'xterm-addon-fit';
18
+
19
+ import { BaseWidget, Message, Widget, codicon, isFirefox } from '@theia/core/lib/browser';
20
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
21
+ import { Disposable, DisposableCollection } from '@theia/core';
22
+ import { DEFAULT_TERMINAL_RENDERER_TYPE, TerminalPreferences, TerminalRendererType, isTerminalRendererType } from '@theia/terminal/lib/browser/terminal-preferences';
23
+ import { TerminalThemeService } from '@theia/terminal/lib/browser/terminal-theme-service';
24
+ import { TestOutputSource, TestOutputUIModel } from './test-output-ui-model';
25
+ import debounce = require('p-debounce');
26
+
27
+ @injectable()
28
+ export class TestOutputWidget extends BaseWidget {
29
+ @inject(TerminalPreferences) protected readonly preferences: TerminalPreferences;
30
+ @inject(TerminalThemeService) protected readonly themeService: TerminalThemeService;
31
+ @inject(TestOutputUIModel) protected readonly uiModel: TestOutputUIModel;
32
+
33
+ static ID = 'test-output-view';
34
+
35
+ protected term: Terminal;
36
+ protected disposeOnSetInput = new DisposableCollection();
37
+ protected fitAddon: FitAddon;
38
+
39
+ constructor() {
40
+ super();
41
+
42
+ this.id = TestOutputWidget.ID;
43
+ this.title.label = 'Test Output';
44
+ this.title.caption = 'Test Output';
45
+ this.title.iconClass = codicon('symbol-keyword');
46
+ this.title.closable = true;
47
+ }
48
+
49
+ @postConstruct()
50
+ init(): void {
51
+ this.term = new Terminal({
52
+ disableStdin: true,
53
+ cursorStyle: 'bar',
54
+ fontFamily: this.preferences['terminal.integrated.fontFamily'],
55
+ fontSize: this.preferences['terminal.integrated.fontSize'],
56
+ fontWeight: this.preferences['terminal.integrated.fontWeight'],
57
+ fontWeightBold: this.preferences['terminal.integrated.fontWeightBold'],
58
+ drawBoldTextInBrightColors: this.preferences['terminal.integrated.drawBoldTextInBrightColors'],
59
+ letterSpacing: this.preferences['terminal.integrated.letterSpacing'],
60
+ lineHeight: this.preferences['terminal.integrated.lineHeight'],
61
+ scrollback: this.preferences['terminal.integrated.scrollback'],
62
+ fastScrollSensitivity: this.preferences['terminal.integrated.fastScrollSensitivity'],
63
+ rendererType: this.getTerminalRendererType(this.preferences['terminal.integrated.rendererType']),
64
+ theme: this.themeService.theme
65
+ });
66
+
67
+ this.fitAddon = new FitAddon();
68
+ this.term.loadAddon(this.fitAddon);
69
+ this.setInput(this.uiModel.selectedOutputSource);
70
+ this.uiModel.onDidChangeSelectedOutputSource(source => this.setInput(source));
71
+
72
+ this.toDispose.push(Disposable.create(() =>
73
+ this.term.dispose()
74
+ ));
75
+ }
76
+
77
+ setInput(selectedOutputSource: TestOutputSource | undefined): void {
78
+ this.disposeOnSetInput.dispose();
79
+ this.disposeOnSetInput = new DisposableCollection();
80
+ this.term.clear();
81
+ if (selectedOutputSource) {
82
+ selectedOutputSource.output.forEach(item => this.term.writeln(item.output));
83
+ this.disposeOnSetInput.push(selectedOutputSource.onDidAddTestOutput(items => {
84
+ items.forEach(item => this.term.writeln(item.output));
85
+ }));
86
+ this.term.scrollToBottom();
87
+ }
88
+ }
89
+
90
+ protected override onAfterAttach(msg: Message): void {
91
+ super.onAfterAttach(msg);
92
+ this.term.open(this.node);
93
+
94
+ if (isFirefox) {
95
+ // monkey patching intersection observer handling for secondary window support
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ const renderService: any = (this.term as any)._core._renderService;
98
+ const originalFunc: (entry: IntersectionObserverEntry) => void = renderService._onIntersectionChange.bind(renderService);
99
+ const replacement = function (entry: IntersectionObserverEntry): void {
100
+ if (entry.target.ownerDocument !== document) {
101
+ // in Firefox, the intersection observer always reports the widget as non-intersecting if the dom element
102
+ // is in a different document from when the IntersectionObserver started observing. Since we know
103
+ // that the widget is always "visible" when in a secondary window, so we mark the entry as "intersecting"
104
+ const patchedEvent: IntersectionObserverEntry = {
105
+ ...entry,
106
+ isIntersecting: true,
107
+ };
108
+ originalFunc(patchedEvent);
109
+ } else {
110
+ originalFunc(entry);
111
+ }
112
+ };
113
+
114
+ renderService._onIntersectionChange = replacement;
115
+ }
116
+
117
+ if (isFirefox) {
118
+ // The software scrollbars don't work with xterm.js, so we disable the scrollbar if we are on firefox.
119
+ if (this.term.element) {
120
+ (this.term.element.children.item(0) as HTMLElement).style.overflow = 'hidden';
121
+ }
122
+ }
123
+ }
124
+
125
+ private getTerminalRendererType(terminalRendererType?: string | TerminalRendererType): RendererType {
126
+ if (terminalRendererType && isTerminalRendererType(terminalRendererType)) {
127
+ return terminalRendererType;
128
+ }
129
+ return DEFAULT_TERMINAL_RENDERER_TYPE;
130
+ }
131
+
132
+ protected override onResize(msg: Widget.ResizeMessage): void {
133
+ super.onResize(msg);
134
+ this.resizeTerminal();
135
+ }
136
+
137
+ protected resizeTerminal = debounce(() => this.doResizeTerminal(), 50);
138
+
139
+ protected doResizeTerminal(): void {
140
+ if (this.isDisposed) {
141
+ return;
142
+ }
143
+ const geo = this.fitAddon.proposeDimensions();
144
+ const cols = geo.cols;
145
+ const rows = geo.rows - 1; // subtract one row for margin
146
+ this.term.resize(cols, rows);
147
+ }
148
+ }
@@ -0,0 +1,34 @@
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 } from '@theia/core/lib/browser';
18
+ import { injectable } from '@theia/core/shared/inversify';
19
+ import { TestResultWidget } from './test-result-widget';
20
+ import { nls } from '@theia/core';
21
+
22
+ @injectable()
23
+ export class TestResultViewContribution extends AbstractViewContribution<TestResultWidget> {
24
+ constructor() {
25
+ super({
26
+ widgetId: TestResultWidget.ID,
27
+ widgetName: nls.localizeByDefault('Test Results'),
28
+ defaultWidgetOptions: {
29
+ area: 'bottom'
30
+ }
31
+ });
32
+
33
+ }
34
+ }
@@ -0,0 +1,92 @@
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 { BaseWidget, Message, codicon } from '@theia/core/lib/browser';
18
+ import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
19
+ import { TestOutputUIModel } from './test-output-ui-model';
20
+ import { DisposableCollection, nls } from '@theia/core';
21
+ import { TestFailure, TestMessage } from '../test-service';
22
+ import { MarkdownRenderer } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer';
23
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering';
24
+
25
+ @injectable()
26
+ export class TestResultWidget extends BaseWidget {
27
+
28
+ static readonly ID = 'test-result-widget';
29
+
30
+ @inject(TestOutputUIModel) uiModel: TestOutputUIModel;
31
+ @inject(MarkdownRenderer) markdownRenderer: MarkdownRenderer;
32
+
33
+ protected toDisposeOnRender = new DisposableCollection();
34
+ protected input: TestMessage[] = [];
35
+ protected content: HTMLDivElement;
36
+
37
+ constructor() {
38
+ super();
39
+ this.id = TestResultWidget.ID;
40
+ this.title.label = nls.localizeByDefault('Test Results');
41
+ this.title.caption = nls.localizeByDefault('Test Results');
42
+ this.title.iconClass = codicon('checklist');
43
+ this.title.closable = true;
44
+ this.scrollOptions = {
45
+ minScrollbarLength: 35,
46
+ };
47
+ }
48
+
49
+ @postConstruct()
50
+ init(): void {
51
+ this.uiModel.onDidChangeSelectedTestState(e => {
52
+ if (TestFailure.is(e)) {
53
+ this.setInput(e.messages);
54
+ }
55
+ });
56
+ }
57
+
58
+ protected override onAfterAttach(msg: Message): void {
59
+ super.onAfterAttach(msg);
60
+ this.content = this.node.ownerDocument.createElement('div');
61
+ this.node.append(this.content);
62
+ }
63
+
64
+ setInput(messages: TestMessage[]): void {
65
+ this.input = messages;
66
+ this.update();
67
+ }
68
+
69
+ protected override onUpdateRequest(msg: Message): void {
70
+ this.render();
71
+ super.onUpdateRequest(msg);
72
+ }
73
+
74
+ render(): void {
75
+ this.toDisposeOnRender.dispose();
76
+ this.toDisposeOnRender = new DisposableCollection();
77
+ this.content.innerHTML = '';
78
+ this.input.forEach(message => {
79
+ if (MarkdownString.is(message.message)) {
80
+ const line = this.markdownRenderer.render(message.message);
81
+ this.content.append(line.element);
82
+ this.toDisposeOnRender.push(line);
83
+ } else {
84
+ this.content.append(this.node.ownerDocument.createTextNode(message.message));
85
+ }
86
+ });
87
+ }
88
+
89
+ override dispose(): void {
90
+ this.toDisposeOnRender.dispose();
91
+ }
92
+ }