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

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,156 +1,156 @@
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, TestFailure, TestOutputItem, TestRun, TestService, TestState, TestStateChangedEvent } from '../test-service';
19
- import { Disposable, Emitter, Event } from '@theia/core';
20
- import { TestContextKeyService } from './test-context-key-service';
21
-
22
- export interface ActiveRunEvent {
23
- controller: TestController;
24
- activeRun: TestRun | undefined
25
- }
26
-
27
- export interface TestOutputSource {
28
- readonly output: readonly TestOutputItem[];
29
- onDidAddTestOutput: Event<TestOutputItem[]>;
30
- }
31
-
32
- export interface ActiveTestStateChangedEvent {
33
- controller: TestController;
34
- testRun: TestRun;
35
- statedDelta: TestStateChangedEvent[];
36
- }
37
-
38
- interface ActiveTestRunInfo {
39
- run: TestRun;
40
- toDispose: Disposable;
41
- }
42
-
43
- @injectable()
44
- export class TestOutputUIModel {
45
- @inject(TestContextKeyService) protected readonly testContextKeys: TestContextKeyService;
46
- @inject(TestService) protected testService: TestService;
47
-
48
- protected readonly activeRuns = new Map<string, ActiveTestRunInfo>();
49
- protected readonly controllerListeners = new Map<string, Disposable>();
50
- private _selectedOutputSource: TestOutputSource | undefined;
51
- private _selectedTestState: TestState | undefined;
52
-
53
- @postConstruct()
54
- init(): void {
55
- this.testService.getControllers().forEach(controller => this.addController(controller));
56
- this.testService.onControllersChanged(deltas => {
57
- deltas.added?.forEach(controller => this.addController(controller));
58
- deltas.removed?.forEach(controller => this.removeController(controller));
59
- });
60
- }
61
-
62
- protected removeController(id: string): void {
63
- this.controllerListeners.get(id)?.dispose();
64
- if (this.activeRuns.has(id)) {
65
- this.activeRuns.delete(id);
66
- }
67
- }
68
-
69
- protected addController(controller: TestController): void {
70
- this.controllerListeners.set(controller.id, controller.onRunsChanged(delta => {
71
- if (delta.added) {
72
- const currentRun = controller.testRuns[controller.testRuns.length - 1];
73
- if (currentRun) {
74
- this.setActiveTestRun(currentRun);
75
- }
76
- } else {
77
- delta.removed?.forEach(run => {
78
- if (run === this.getActiveTestRun(controller)) {
79
- const currentRun = controller.testRuns[controller.testRuns.length - 1];
80
- this.doSetActiveRun(controller, currentRun);
81
- }
82
- });
83
- }
84
- }));
85
- }
86
-
87
- getActiveTestRun(controller: TestController): TestRun | undefined {
88
- return this.activeRuns.get(controller.id)?.run;
89
- }
90
-
91
- protected readonly onDidChangeActiveTestRunEmitter = new Emitter<ActiveRunEvent>();
92
- onDidChangeActiveTestRun: Event<ActiveRunEvent> = this.onDidChangeActiveTestRunEmitter.event;
93
-
94
- setActiveTestRun(run: TestRun): void {
95
- this.doSetActiveRun(run.controller, run);
96
- }
97
-
98
- doSetActiveRun(controller: TestController, run: TestRun | undefined): void {
99
- const old = this.activeRuns.get(controller.id);
100
- if (old !== run) {
101
- if (old) {
102
- old.toDispose.dispose();
103
- }
104
- if (run) {
105
- const toDispose = run.onDidChangeTestState(e => {
106
- this.onDidChangeActiveTestStateEmitter.fire({
107
- controller,
108
- testRun: run,
109
- statedDelta: e
110
- });
111
- });
112
- this.activeRuns.set(controller.id, { run, toDispose });
113
- } else {
114
- this.activeRuns.delete(controller.id);
115
- }
116
- this.onDidChangeActiveTestRunEmitter.fire({ activeRun: run, controller: controller });
117
- }
118
- }
119
-
120
- private onDidChangeActiveTestStateEmitter: Emitter<ActiveTestStateChangedEvent> = new Emitter();
121
- onDidChangeActiveTestState: Event<ActiveTestStateChangedEvent> = this.onDidChangeActiveTestStateEmitter.event;
122
-
123
- get selectedOutputSource(): TestOutputSource | undefined {
124
- return this._selectedOutputSource;
125
- }
126
-
127
- set selectedOutputSource(element: TestOutputSource | undefined) {
128
- if (element !== this._selectedOutputSource) {
129
- this._selectedOutputSource = element;
130
- this.onDidChangeSelectedOutputSourceEmitter.fire(element);
131
- }
132
- }
133
-
134
- protected readonly onDidChangeSelectedOutputSourceEmitter = new Emitter<TestOutputSource | undefined>();
135
- readonly onDidChangeSelectedOutputSource: Event<TestOutputSource | undefined> = this.onDidChangeSelectedOutputSourceEmitter.event;
136
-
137
- get selectedTestState(): TestState | undefined {
138
- return this._selectedTestState;
139
- }
140
-
141
- set selectedTestState(element: TestState | undefined) {
142
- if (element !== this._selectedTestState) {
143
- this._selectedTestState = element;
144
- if (this._selectedTestState && TestFailure.is(this._selectedTestState.state)) {
145
- const message = this._selectedTestState.state.messages[0];
146
- this.testContextKeys.contextValue.set(message.contextValue);
147
- } else {
148
- this.testContextKeys.contextValue.reset();
149
- }
150
- this.onDidChangeSelectedTestStateEmitter.fire(element);
151
- }
152
- }
153
-
154
- protected readonly onDidChangeSelectedTestStateEmitter = new Emitter<TestState | undefined>();
155
- readonly onDidChangeSelectedTestState: Event<TestState | undefined> = this.onDidChangeSelectedTestStateEmitter.event;
156
- }
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, TestFailure, TestOutputItem, TestRun, TestService, TestState, TestStateChangedEvent } from '../test-service';
19
+ import { Disposable, Emitter, Event } from '@theia/core';
20
+ import { TestContextKeyService } from './test-context-key-service';
21
+
22
+ export interface ActiveRunEvent {
23
+ controller: TestController;
24
+ activeRun: TestRun | undefined
25
+ }
26
+
27
+ export interface TestOutputSource {
28
+ readonly output: readonly TestOutputItem[];
29
+ onDidAddTestOutput: Event<TestOutputItem[]>;
30
+ }
31
+
32
+ export interface ActiveTestStateChangedEvent {
33
+ controller: TestController;
34
+ testRun: TestRun;
35
+ statedDelta: TestStateChangedEvent[];
36
+ }
37
+
38
+ interface ActiveTestRunInfo {
39
+ run: TestRun;
40
+ toDispose: Disposable;
41
+ }
42
+
43
+ @injectable()
44
+ export class TestOutputUIModel {
45
+ @inject(TestContextKeyService) protected readonly testContextKeys: TestContextKeyService;
46
+ @inject(TestService) protected testService: TestService;
47
+
48
+ protected readonly activeRuns = new Map<string, ActiveTestRunInfo>();
49
+ protected readonly controllerListeners = new Map<string, Disposable>();
50
+ private _selectedOutputSource: TestOutputSource | undefined;
51
+ private _selectedTestState: TestState | undefined;
52
+
53
+ @postConstruct()
54
+ init(): void {
55
+ this.testService.getControllers().forEach(controller => this.addController(controller));
56
+ this.testService.onControllersChanged(deltas => {
57
+ deltas.added?.forEach(controller => this.addController(controller));
58
+ deltas.removed?.forEach(controller => this.removeController(controller));
59
+ });
60
+ }
61
+
62
+ protected removeController(id: string): void {
63
+ this.controllerListeners.get(id)?.dispose();
64
+ if (this.activeRuns.has(id)) {
65
+ this.activeRuns.delete(id);
66
+ }
67
+ }
68
+
69
+ protected addController(controller: TestController): void {
70
+ this.controllerListeners.set(controller.id, controller.onRunsChanged(delta => {
71
+ if (delta.added) {
72
+ const currentRun = controller.testRuns[controller.testRuns.length - 1];
73
+ if (currentRun) {
74
+ this.setActiveTestRun(currentRun);
75
+ }
76
+ } else {
77
+ delta.removed?.forEach(run => {
78
+ if (run === this.getActiveTestRun(controller)) {
79
+ const currentRun = controller.testRuns[controller.testRuns.length - 1];
80
+ this.doSetActiveRun(controller, currentRun);
81
+ }
82
+ });
83
+ }
84
+ }));
85
+ }
86
+
87
+ getActiveTestRun(controller: TestController): TestRun | undefined {
88
+ return this.activeRuns.get(controller.id)?.run;
89
+ }
90
+
91
+ protected readonly onDidChangeActiveTestRunEmitter = new Emitter<ActiveRunEvent>();
92
+ onDidChangeActiveTestRun: Event<ActiveRunEvent> = this.onDidChangeActiveTestRunEmitter.event;
93
+
94
+ setActiveTestRun(run: TestRun): void {
95
+ this.doSetActiveRun(run.controller, run);
96
+ }
97
+
98
+ doSetActiveRun(controller: TestController, run: TestRun | undefined): void {
99
+ const old = this.activeRuns.get(controller.id);
100
+ if (old !== run) {
101
+ if (old) {
102
+ old.toDispose.dispose();
103
+ }
104
+ if (run) {
105
+ const toDispose = run.onDidChangeTestState(e => {
106
+ this.onDidChangeActiveTestStateEmitter.fire({
107
+ controller,
108
+ testRun: run,
109
+ statedDelta: e
110
+ });
111
+ });
112
+ this.activeRuns.set(controller.id, { run, toDispose });
113
+ } else {
114
+ this.activeRuns.delete(controller.id);
115
+ }
116
+ this.onDidChangeActiveTestRunEmitter.fire({ activeRun: run, controller: controller });
117
+ }
118
+ }
119
+
120
+ private onDidChangeActiveTestStateEmitter: Emitter<ActiveTestStateChangedEvent> = new Emitter();
121
+ onDidChangeActiveTestState: Event<ActiveTestStateChangedEvent> = this.onDidChangeActiveTestStateEmitter.event;
122
+
123
+ get selectedOutputSource(): TestOutputSource | undefined {
124
+ return this._selectedOutputSource;
125
+ }
126
+
127
+ set selectedOutputSource(element: TestOutputSource | undefined) {
128
+ if (element !== this._selectedOutputSource) {
129
+ this._selectedOutputSource = element;
130
+ this.onDidChangeSelectedOutputSourceEmitter.fire(element);
131
+ }
132
+ }
133
+
134
+ protected readonly onDidChangeSelectedOutputSourceEmitter = new Emitter<TestOutputSource | undefined>();
135
+ readonly onDidChangeSelectedOutputSource: Event<TestOutputSource | undefined> = this.onDidChangeSelectedOutputSourceEmitter.event;
136
+
137
+ get selectedTestState(): TestState | undefined {
138
+ return this._selectedTestState;
139
+ }
140
+
141
+ set selectedTestState(element: TestState | undefined) {
142
+ if (element !== this._selectedTestState) {
143
+ this._selectedTestState = element;
144
+ if (this._selectedTestState && TestFailure.is(this._selectedTestState.state)) {
145
+ const message = this._selectedTestState.state.messages[0];
146
+ this.testContextKeys.contextValue.set(message.contextValue);
147
+ } else {
148
+ this.testContextKeys.contextValue.reset();
149
+ }
150
+ this.onDidChangeSelectedTestStateEmitter.fire(element);
151
+ }
152
+ }
153
+
154
+ protected readonly onDidChangeSelectedTestStateEmitter = new Emitter<TestState | undefined>();
155
+ readonly onDidChangeSelectedTestState: Event<TestState | undefined> = this.onDidChangeSelectedTestStateEmitter.event;
156
+ }
@@ -1,34 +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
- }
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
+ }