@theia/task 1.77.0-next.7 → 1.77.0-next.77

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 (43) hide show
  1. package/lib/browser/process/process-task-resolver.d.ts +5 -1
  2. package/lib/browser/process/process-task-resolver.d.ts.map +1 -1
  3. package/lib/browser/process/process-task-resolver.js +35 -23
  4. package/lib/browser/process/process-task-resolver.js.map +1 -1
  5. package/lib/browser/process/process-task-resolver.spec.d.ts +2 -0
  6. package/lib/browser/process/process-task-resolver.spec.d.ts.map +1 -0
  7. package/lib/browser/process/process-task-resolver.spec.js +218 -0
  8. package/lib/browser/process/process-task-resolver.spec.js.map +1 -0
  9. package/lib/browser/quick-open-task.js +1 -1
  10. package/lib/browser/quick-open-task.js.map +1 -1
  11. package/lib/browser/task-configuration-manager.js +1 -1
  12. package/lib/browser/task-configuration-manager.js.map +1 -1
  13. package/lib/browser/task-schema-updater.d.ts +1 -1
  14. package/lib/browser/task-schema-updater.d.ts.map +1 -1
  15. package/lib/browser/task-schema-updater.js +3 -3
  16. package/lib/browser/task-schema-updater.js.map +1 -1
  17. package/lib/browser/task-service.d.ts.map +1 -1
  18. package/lib/browser/task-service.js +4 -1
  19. package/lib/browser/task-service.js.map +1 -1
  20. package/lib/browser/task-service.spec.d.ts +2 -0
  21. package/lib/browser/task-service.spec.d.ts.map +1 -0
  22. package/lib/browser/task-service.spec.js +94 -0
  23. package/lib/browser/task-service.spec.js.map +1 -0
  24. package/lib/browser/task-terminal-widget-manager.js +1 -1
  25. package/lib/browser/task-terminal-widget-manager.js.map +1 -1
  26. package/lib/browser/tasks-monaco-contribution.js +2 -1
  27. package/lib/browser/tasks-monaco-contribution.js.map +1 -1
  28. package/lib/node/process/process-task-runner.js +1 -1
  29. package/lib/node/process/process-task-runner.js.map +1 -1
  30. package/lib/node/task-abstract-line-matcher.js +2 -1
  31. package/lib/node/task-abstract-line-matcher.js.map +1 -1
  32. package/lib/node/task-server.slow-spec.d.ts.map +1 -1
  33. package/lib/node/task-server.slow-spec.js +0 -1
  34. package/lib/node/task-server.slow-spec.js.map +1 -1
  35. package/lib/node/test/task-test-container.js +6 -5
  36. package/lib/node/test/task-test-container.js.map +1 -1
  37. package/package.json +12 -12
  38. package/src/browser/process/process-task-resolver.spec.ts +247 -0
  39. package/src/browser/process/process-task-resolver.ts +41 -24
  40. package/src/browser/task-schema-updater.ts +1 -1
  41. package/src/browser/task-service.spec.ts +102 -0
  42. package/src/browser/task-service.ts +6 -3
  43. package/src/node/task-server.slow-spec.ts +0 -1
@@ -0,0 +1,102 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 Md. Mehedi Hasan.
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 { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
18
+ let disableJSDOM = enableJSDOM();
19
+
20
+ import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
21
+ FrontendApplicationConfigProvider.set({});
22
+
23
+ import * as sinon from 'sinon';
24
+ // TaskService imports xterm, which probes the canvas API during module loading.
25
+ // These tests do not render a terminal, and JSDOM has no canvas backend.
26
+ const canvasContext = sinon.stub(HTMLCanvasElement.prototype, 'getContext');
27
+
28
+ import { expect } from 'chai';
29
+ import { cancelled } from '@theia/core/lib/common/cancellation';
30
+ import { MockLogger } from '@theia/core/lib/common/test/mock-logger';
31
+ import { RunTaskOption, TaskConfiguration, TaskInfo, TaskScope } from '../common';
32
+ import { TaskResolverRegistry } from './task-contribution';
33
+ import { TaskDefinitionRegistry } from './task-definition-registry';
34
+ import { TaskService } from './task-service';
35
+
36
+ canvasContext.restore();
37
+ disableJSDOM();
38
+
39
+ class TestTaskService extends TaskService {
40
+ override readonly logger = new MockLogger();
41
+ override readonly taskResolverRegistry = new TaskResolverRegistry();
42
+ override readonly taskDefinitionRegistry = new TaskDefinitionRegistry();
43
+ override readonly removeProblemMarkers = sinon.stub<[RunTaskOption?], Promise<void>>().resolves();
44
+ override readonly runResolvedTask = sinon.stub<[TaskConfiguration, RunTaskOption?], Promise<TaskInfo | undefined>>().resolves();
45
+
46
+ resolveAndRun(task: TaskConfiguration): Promise<TaskInfo | undefined> {
47
+ return this.doRunTask(task);
48
+ }
49
+ }
50
+
51
+ describe('TaskService task resolution', () => {
52
+ let service: TestTaskService;
53
+ let logError: sinon.SinonStub;
54
+ const task: TaskConfiguration = { type: 'shell', label: 'input task', _scope: TaskScope.Workspace };
55
+
56
+ before(() => {
57
+ disableJSDOM = enableJSDOM();
58
+ });
59
+
60
+ after(() => {
61
+ disableJSDOM();
62
+ });
63
+
64
+ beforeEach(() => {
65
+ service = new TestTaskService();
66
+ logError = sinon.stub(service.logger, 'error').resolves();
67
+ });
68
+
69
+ for (const stage of ['task', 'execution'] as const) {
70
+ it(`does not launch a task or log an error when the ${stage} resolver is cancelled`, async () => {
71
+ const resolver = { resolveTask: sinon.stub().rejects(cancelled()) };
72
+ if (stage === 'task') {
73
+ service.taskResolverRegistry.registerTaskResolver('shell', resolver);
74
+ } else {
75
+ service.taskResolverRegistry.registerExecutionResolver('shell', resolver);
76
+ }
77
+
78
+ expect(await service.resolveAndRun(task)).to.equal(undefined);
79
+ sinon.assert.calledOnce(resolver.resolveTask);
80
+ sinon.assert.notCalled(service.removeProblemMarkers);
81
+ sinon.assert.notCalled(service.runResolvedTask);
82
+ sinon.assert.notCalled(logError);
83
+
84
+ resolver.resolveTask.resolves(task);
85
+ await service.resolveAndRun(task);
86
+ sinon.assert.calledOnce(service.removeProblemMarkers);
87
+ sinon.assert.calledOnceWithExactly(service.runResolvedTask, task, undefined);
88
+ sinon.assert.notCalled(logError);
89
+ });
90
+ }
91
+
92
+ it('still logs unexpected resolver errors without launching the task', async () => {
93
+ const error = new Error('Unable to resolve task');
94
+ service.taskResolverRegistry.registerExecutionResolver('shell', {
95
+ resolveTask: sinon.stub().rejects(error)
96
+ });
97
+
98
+ expect(await service.resolveAndRun(task)).to.equal(undefined);
99
+ sinon.assert.notCalled(service.runResolvedTask);
100
+ sinon.assert.calledOnceWithExactly(logError, `Error resolving task '${task.label}': ${error}`);
101
+ });
102
+ });
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { ApplicationShell, FrontendApplication, QuickPickValue, WidgetManager, WidgetOpenMode } from '@theia/core/lib/browser';
18
18
  import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
19
- import { CommandService, ILogger, nls } from '@theia/core/lib/common';
19
+ import { CommandService, ILogger, isCancelled, nls } from '@theia/core/lib/common';
20
20
  import { MessageService } from '@theia/core/lib/common/message-service';
21
21
  import { Deferred } from '@theia/core/lib/common/promise-util';
22
22
  import { QuickPickItemOrSeparator, QuickPickService } from '@theia/core/lib/common/quick-pick-service';
@@ -383,7 +383,7 @@ export class TaskService implements TaskConfigurationClient {
383
383
  async getConfiguredTasks(token: number): Promise<TaskConfiguration[]> {
384
384
  const invalidTaskConfig = this.taskConfigurations.getInvalidTaskConfigurations()[0];
385
385
  if (invalidTaskConfig) {
386
- const widget = <ProblemWidget>await this.widgetManager.getOrCreateWidget(PROBLEMS_WIDGET_ID);
386
+ const widget = await this.widgetManager.getOrCreateWidget(PROBLEMS_WIDGET_ID) as ProblemWidget;
387
387
  const isProblemsWidgetVisible = widget && widget.isVisible;
388
388
  const currentEditorUri = this.editorManager.currentEditor && this.editorManager.currentEditor.editor.getResourceUri();
389
389
  let isInvalidTaskConfigFileOpen = false;
@@ -862,6 +862,9 @@ export class TaskService implements TaskConfigurationClient {
862
862
  await this.removeProblemMarkers(option);
863
863
  return this.runResolvedTask(taskToRun, option);
864
864
  } catch (error) {
865
+ if (isCancelled(error)) {
866
+ return undefined;
867
+ }
865
868
  const errMessage = `Error resolving task '${task.label}': ${error}`;
866
869
  this.logger.error(errMessage);
867
870
  }
@@ -1083,7 +1086,7 @@ export class TaskService implements TaskConfigurationClient {
1083
1086
  const selectedText: string = this.editorManager.currentEditor.editor.document.getText(selectedRange).trimRight() + '\n';
1084
1087
  let terminal = this.terminalService.lastUsedTerminal;
1085
1088
  if (!terminal || terminal.kind !== 'user' || (await terminal.hasChildProcesses())) {
1086
- terminal = <TerminalWidget>await this.terminalService.newTerminal(<TerminalWidgetFactoryOptions>{ created: nextTerminalCreationToken() });
1089
+ terminal = await this.terminalService.newTerminal(<TerminalWidgetFactoryOptions>{ created: nextTerminalCreationToken() }) as TerminalWidget;
1087
1090
  await terminal.start();
1088
1091
  this.terminalService.open(terminal);
1089
1092
  }
@@ -14,7 +14,6 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- // tslint:disable-next-line:no-implicit-dependencies
18
17
  import 'reflect-metadata';
19
18
  import { createTaskTestContainer } from './test/task-test-container';
20
19
  import { BackendApplication } from '@theia/core/lib/node/backend-application';