@theia/terminal 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.
Files changed (43) hide show
  1. package/README.md +30 -30
  2. package/lib/browser/terminal-widget-impl.js +4 -4
  3. package/package.json +9 -9
  4. package/src/browser/base/terminal-service.ts +60 -60
  5. package/src/browser/base/terminal-widget.ts +268 -268
  6. package/src/browser/index.ts +17 -17
  7. package/src/browser/search/terminal-search-container.ts +28 -28
  8. package/src/browser/search/terminal-search-widget.tsx +161 -161
  9. package/src/browser/shell-terminal-profile.ts +45 -45
  10. package/src/browser/style/terminal-search.css +99 -99
  11. package/src/browser/style/terminal.css +32 -32
  12. package/src/browser/terminal-contribution.ts +19 -19
  13. package/src/browser/terminal-copy-on-selection-handler.ts +92 -92
  14. package/src/browser/terminal-file-link-provider.ts +289 -289
  15. package/src/browser/terminal-frontend-contribution.ts +1134 -1134
  16. package/src/browser/terminal-frontend-module.ts +138 -138
  17. package/src/browser/terminal-link-helpers.ts +187 -187
  18. package/src/browser/terminal-link-provider.ts +203 -203
  19. package/src/browser/terminal-preferences.ts +428 -428
  20. package/src/browser/terminal-profile-service.ts +180 -180
  21. package/src/browser/terminal-quick-open-service.ts +132 -132
  22. package/src/browser/terminal-theme-service.ts +213 -213
  23. package/src/browser/terminal-url-link-provider.ts +66 -66
  24. package/src/browser/terminal-widget-impl.ts +996 -996
  25. package/src/common/base-terminal-protocol.ts +125 -125
  26. package/src/common/shell-terminal-protocol.ts +103 -103
  27. package/src/common/terminal-common-module.ts +30 -30
  28. package/src/common/terminal-protocol.ts +32 -32
  29. package/src/common/terminal-watcher.ts +69 -69
  30. package/src/node/base-terminal-server.ts +173 -173
  31. package/src/node/buffering-stream.spec.ts +46 -46
  32. package/src/node/buffering-stream.ts +95 -95
  33. package/src/node/index.ts +17 -17
  34. package/src/node/shell-process.ts +102 -102
  35. package/src/node/shell-terminal-server.spec.ts +40 -40
  36. package/src/node/shell-terminal-server.ts +223 -223
  37. package/src/node/terminal-backend-contribution.slow-spec.ts +63 -63
  38. package/src/node/terminal-backend-contribution.ts +60 -60
  39. package/src/node/terminal-backend-module.ts +82 -82
  40. package/src/node/terminal-server.spec.ts +47 -47
  41. package/src/node/terminal-server.ts +52 -52
  42. package/src/node/test/terminal-test-container.ts +39 -39
  43. package/src/package.spec.ts +28 -28
@@ -1,223 +1,223 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 Ericsson 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, named } from '@theia/core/shared/inversify';
18
- import { ILogger } from '@theia/core/lib/common/logger';
19
- import { EnvironmentUtils } from '@theia/core/lib/node/environment-utils';
20
- import { BaseTerminalServer } from './base-terminal-server';
21
- import { ShellProcessFactory, getRootPath } from './shell-process';
22
- import { ProcessManager, TerminalProcess } from '@theia/process/lib/node';
23
- import { isWindows } from '@theia/core/lib/common/os';
24
- import * as cp from 'child_process';
25
- import {
26
- EnvironmentVariableCollectionWithPersistence, EnvironmentVariableMutatorType, NO_ROOT_URI, SerializableEnvironmentVariableCollection,
27
- IShellTerminalServer, IShellTerminalServerOptions
28
- }
29
- from '../common/shell-terminal-protocol';
30
- import { URI } from '@theia/core';
31
- import { MultiKeyMap } from '@theia/core/lib/common/collections';
32
- import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string';
33
-
34
- interface SerializedExtensionEnvironmentVariableCollection {
35
- extensionIdentifier: string,
36
- rootUri: string,
37
- collection: SerializableEnvironmentVariableCollection,
38
- }
39
-
40
- @injectable()
41
- export class ShellTerminalServer extends BaseTerminalServer implements IShellTerminalServer {
42
- @inject(EnvironmentUtils) protected environmentUtils: EnvironmentUtils;
43
-
44
- readonly collections: MultiKeyMap<string, EnvironmentVariableCollectionWithPersistence> = new MultiKeyMap(2);
45
-
46
- constructor(
47
- @inject(ShellProcessFactory) protected readonly shellFactory: ShellProcessFactory,
48
- @inject(ProcessManager) processManager: ProcessManager,
49
- @inject(ILogger) @named('terminal') logger: ILogger) {
50
- super(processManager, logger);
51
- }
52
-
53
- async create(options: IShellTerminalServerOptions): Promise<number> {
54
- try {
55
- if (options.strictEnv !== true) {
56
- options.env = this.environmentUtils.mergeProcessEnv(options.env);
57
- this.applyToProcessEnvironment(URI.fromFilePath(getRootPath(options.rootURI)), options.env);
58
- }
59
- const term = this.shellFactory(options);
60
- this.postCreate(term);
61
- return term.id;
62
- } catch (error) {
63
- this.logger.error('Error while creating terminal', error);
64
- return -1;
65
- }
66
- }
67
-
68
- // copied and modified from https://github.com/microsoft/vscode/blob/4636be2b71c87bfb0bfe3c94278b447a5efcc1f1/src/vs/workbench/contrib/debug/node/terminals.ts#L32-L75
69
- private spawnAsPromised(command: string, args: string[]): Promise<string> {
70
- return new Promise((resolve, reject) => {
71
- let stdout = '';
72
- const child = cp.spawn(command, args, {
73
- shell: true
74
- });
75
- if (child.pid) {
76
- child.stdout.on('data', (data: Buffer) => {
77
- stdout += data.toString();
78
- });
79
- }
80
- child.on('error', err => {
81
- reject(err);
82
- });
83
- child.on('close', code => {
84
- resolve(stdout);
85
- });
86
- });
87
- }
88
-
89
- public hasChildProcesses(processId: number | undefined): Promise<boolean> {
90
- if (processId) {
91
- // if shell has at least one child process, assume that shell is busy
92
- if (isWindows) {
93
- return this.spawnAsPromised('wmic', ['process', 'get', 'ParentProcessId']).then(stdout => {
94
- const pids = stdout.split('\r\n');
95
- return pids.some(p => parseInt(p) === processId);
96
- }, error => true);
97
- } else {
98
- return this.spawnAsPromised('/usr/bin/pgrep', ['-lP', String(processId)]).then(stdout => {
99
- const r = stdout.trim();
100
- if (r.length === 0 || r.indexOf(' tmux') >= 0) { // ignore 'tmux';
101
- return false;
102
- } else {
103
- return true;
104
- }
105
- }, error => true);
106
- }
107
- }
108
- // fall back to safe side
109
- return Promise.resolve(true);
110
- }
111
-
112
- applyToProcessEnvironment(cwdUri: URI, env: { [key: string]: string | null }): void {
113
- let lowerToActualVariableNames: {
114
- [lowerKey: string]: string | undefined
115
- } | undefined;
116
- if (isWindows) {
117
- lowerToActualVariableNames = {};
118
- Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e);
119
- }
120
- this.collections.forEach((mutators, [extensionIdentifier, rootUri]) => {
121
- if (rootUri === NO_ROOT_URI || this.matchesRootUri(cwdUri, rootUri)) {
122
- mutators.variableMutators.forEach((mutator, variable) => {
123
- const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable;
124
- switch (mutator.type) {
125
- case EnvironmentVariableMutatorType.Append:
126
- env[actualVariable] = (env[actualVariable] || '') + mutator.value;
127
- break;
128
- case EnvironmentVariableMutatorType.Prepend:
129
- env[actualVariable] = mutator.value + (env[actualVariable] || '');
130
- break;
131
- case EnvironmentVariableMutatorType.Replace:
132
- env[actualVariable] = mutator.value;
133
- break;
134
- }
135
- });
136
- }
137
- });
138
- }
139
-
140
- matchesRootUri(cwdUri: URI, rootUri: string): boolean {
141
- return new URI(rootUri).isEqualOrParent(cwdUri);
142
- }
143
-
144
- /*---------------------------------------------------------------------------------------------
145
- * Copyright (c) Microsoft Corporation. All rights reserved.
146
- * Licensed under the MIT License. See License.txt in the project root for license information.
147
- *--------------------------------------------------------------------------------------------*/
148
- // some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts
149
-
150
- setCollection(extensionIdentifier: string, baseUri: string, persistent: boolean,
151
- collection: SerializableEnvironmentVariableCollection): void {
152
- this.doSetCollection(extensionIdentifier, baseUri, persistent, collection);
153
- this.updateCollections();
154
- }
155
-
156
- private doSetCollection(extensionIdentifier: string, baseUri: string, persistent: boolean,
157
- collection: SerializableEnvironmentVariableCollection): void {
158
- this.collections.set([extensionIdentifier, baseUri], {
159
- persistent: persistent,
160
- description: collection.description,
161
- variableMutators: new Map(collection.mutators)
162
- });
163
- }
164
-
165
- restorePersisted(jsonValue: string): void {
166
- const collectionsJson: SerializedExtensionEnvironmentVariableCollection[] = JSON.parse(jsonValue);
167
- collectionsJson.forEach(c => this.doSetCollection(c.extensionIdentifier, c.rootUri ?? NO_ROOT_URI, true, c.collection));
168
-
169
- }
170
-
171
- deleteCollection(extensionIdentifier: string): void {
172
- this.collections.delete([extensionIdentifier]);
173
- this.updateCollections();
174
- }
175
-
176
- private updateCollections(): void {
177
- this.persistCollections();
178
- }
179
-
180
- protected persistCollections(): void {
181
- const collectionsJson: SerializedExtensionEnvironmentVariableCollection[] = [];
182
- this.collections.forEach((collection, [extensionIdentifier, rootUri]) => {
183
- if (collection.persistent) {
184
- collectionsJson.push({
185
- extensionIdentifier,
186
- rootUri,
187
- collection: {
188
- description: collection.description,
189
- mutators: [...this.collections.get([extensionIdentifier, rootUri])!.variableMutators.entries()]
190
- },
191
- });
192
- }
193
- });
194
- if (this.client) {
195
- const stringifiedJson = JSON.stringify(collectionsJson);
196
- this.client.storeTerminalEnvVariables(stringifiedJson);
197
- }
198
- }
199
-
200
- async getEnvVarCollectionDescriptionsByExtension(id: number): Promise<Map<string, (string | MarkdownString | undefined)[]>> {
201
- const terminal = this.processManager.get(id);
202
- if (!(terminal instanceof TerminalProcess)) {
203
- throw new Error(`terminal "${id}" does not exist`);
204
- }
205
- const result = new Map<string, (string | MarkdownString | undefined)[]>();
206
- this.collections.forEach((value, key) => {
207
- const prev = result.get(key[0]) || [];
208
- prev.push(value.description);
209
- result.set(key[0], prev);
210
- });
211
- return result;
212
- }
213
-
214
- async getEnvVarCollections(): Promise<[string, string, boolean, SerializableEnvironmentVariableCollection][]> {
215
- const result: [string, string, boolean, SerializableEnvironmentVariableCollection][] = [];
216
-
217
- this.collections.forEach((value, [extensionIdentifier, rootUri]) => {
218
- result.push([extensionIdentifier, rootUri, value.persistent, { description: value.description, mutators: [...value.variableMutators.entries()] }]);
219
- });
220
-
221
- return result;
222
- }
223
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 Ericsson 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, named } from '@theia/core/shared/inversify';
18
+ import { ILogger } from '@theia/core/lib/common/logger';
19
+ import { EnvironmentUtils } from '@theia/core/lib/node/environment-utils';
20
+ import { BaseTerminalServer } from './base-terminal-server';
21
+ import { ShellProcessFactory, getRootPath } from './shell-process';
22
+ import { ProcessManager, TerminalProcess } from '@theia/process/lib/node';
23
+ import { isWindows } from '@theia/core/lib/common/os';
24
+ import * as cp from 'child_process';
25
+ import {
26
+ EnvironmentVariableCollectionWithPersistence, EnvironmentVariableMutatorType, NO_ROOT_URI, SerializableEnvironmentVariableCollection,
27
+ IShellTerminalServer, IShellTerminalServerOptions
28
+ }
29
+ from '../common/shell-terminal-protocol';
30
+ import { URI } from '@theia/core';
31
+ import { MultiKeyMap } from '@theia/core/lib/common/collections';
32
+ import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string';
33
+
34
+ interface SerializedExtensionEnvironmentVariableCollection {
35
+ extensionIdentifier: string,
36
+ rootUri: string,
37
+ collection: SerializableEnvironmentVariableCollection,
38
+ }
39
+
40
+ @injectable()
41
+ export class ShellTerminalServer extends BaseTerminalServer implements IShellTerminalServer {
42
+ @inject(EnvironmentUtils) protected environmentUtils: EnvironmentUtils;
43
+
44
+ readonly collections: MultiKeyMap<string, EnvironmentVariableCollectionWithPersistence> = new MultiKeyMap(2);
45
+
46
+ constructor(
47
+ @inject(ShellProcessFactory) protected readonly shellFactory: ShellProcessFactory,
48
+ @inject(ProcessManager) processManager: ProcessManager,
49
+ @inject(ILogger) @named('terminal') logger: ILogger) {
50
+ super(processManager, logger);
51
+ }
52
+
53
+ async create(options: IShellTerminalServerOptions): Promise<number> {
54
+ try {
55
+ if (options.strictEnv !== true) {
56
+ options.env = this.environmentUtils.mergeProcessEnv(options.env);
57
+ this.applyToProcessEnvironment(URI.fromFilePath(getRootPath(options.rootURI)), options.env);
58
+ }
59
+ const term = this.shellFactory(options);
60
+ this.postCreate(term);
61
+ return term.id;
62
+ } catch (error) {
63
+ this.logger.error('Error while creating terminal', error);
64
+ return -1;
65
+ }
66
+ }
67
+
68
+ // copied and modified from https://github.com/microsoft/vscode/blob/4636be2b71c87bfb0bfe3c94278b447a5efcc1f1/src/vs/workbench/contrib/debug/node/terminals.ts#L32-L75
69
+ private spawnAsPromised(command: string, args: string[]): Promise<string> {
70
+ return new Promise((resolve, reject) => {
71
+ let stdout = '';
72
+ const child = cp.spawn(command, args, {
73
+ shell: true
74
+ });
75
+ if (child.pid) {
76
+ child.stdout.on('data', (data: Buffer) => {
77
+ stdout += data.toString();
78
+ });
79
+ }
80
+ child.on('error', err => {
81
+ reject(err);
82
+ });
83
+ child.on('close', code => {
84
+ resolve(stdout);
85
+ });
86
+ });
87
+ }
88
+
89
+ public hasChildProcesses(processId: number | undefined): Promise<boolean> {
90
+ if (processId) {
91
+ // if shell has at least one child process, assume that shell is busy
92
+ if (isWindows) {
93
+ return this.spawnAsPromised('wmic', ['process', 'get', 'ParentProcessId']).then(stdout => {
94
+ const pids = stdout.split('\r\n');
95
+ return pids.some(p => parseInt(p) === processId);
96
+ }, error => true);
97
+ } else {
98
+ return this.spawnAsPromised('/usr/bin/pgrep', ['-lP', String(processId)]).then(stdout => {
99
+ const r = stdout.trim();
100
+ if (r.length === 0 || r.indexOf(' tmux') >= 0) { // ignore 'tmux';
101
+ return false;
102
+ } else {
103
+ return true;
104
+ }
105
+ }, error => true);
106
+ }
107
+ }
108
+ // fall back to safe side
109
+ return Promise.resolve(true);
110
+ }
111
+
112
+ applyToProcessEnvironment(cwdUri: URI, env: { [key: string]: string | null }): void {
113
+ let lowerToActualVariableNames: {
114
+ [lowerKey: string]: string | undefined
115
+ } | undefined;
116
+ if (isWindows) {
117
+ lowerToActualVariableNames = {};
118
+ Object.keys(env).forEach(e => lowerToActualVariableNames![e.toLowerCase()] = e);
119
+ }
120
+ this.collections.forEach((mutators, [extensionIdentifier, rootUri]) => {
121
+ if (rootUri === NO_ROOT_URI || this.matchesRootUri(cwdUri, rootUri)) {
122
+ mutators.variableMutators.forEach((mutator, variable) => {
123
+ const actualVariable = isWindows ? lowerToActualVariableNames![variable.toLowerCase()] || variable : variable;
124
+ switch (mutator.type) {
125
+ case EnvironmentVariableMutatorType.Append:
126
+ env[actualVariable] = (env[actualVariable] || '') + mutator.value;
127
+ break;
128
+ case EnvironmentVariableMutatorType.Prepend:
129
+ env[actualVariable] = mutator.value + (env[actualVariable] || '');
130
+ break;
131
+ case EnvironmentVariableMutatorType.Replace:
132
+ env[actualVariable] = mutator.value;
133
+ break;
134
+ }
135
+ });
136
+ }
137
+ });
138
+ }
139
+
140
+ matchesRootUri(cwdUri: URI, rootUri: string): boolean {
141
+ return new URI(rootUri).isEqualOrParent(cwdUri);
142
+ }
143
+
144
+ /*---------------------------------------------------------------------------------------------
145
+ * Copyright (c) Microsoft Corporation. All rights reserved.
146
+ * Licensed under the MIT License. See License.txt in the project root for license information.
147
+ *--------------------------------------------------------------------------------------------*/
148
+ // some code copied and modified from https://github.com/microsoft/vscode/blob/1.49.0/src/vs/workbench/contrib/terminal/common/environmentVariableService.ts
149
+
150
+ setCollection(extensionIdentifier: string, baseUri: string, persistent: boolean,
151
+ collection: SerializableEnvironmentVariableCollection): void {
152
+ this.doSetCollection(extensionIdentifier, baseUri, persistent, collection);
153
+ this.updateCollections();
154
+ }
155
+
156
+ private doSetCollection(extensionIdentifier: string, baseUri: string, persistent: boolean,
157
+ collection: SerializableEnvironmentVariableCollection): void {
158
+ this.collections.set([extensionIdentifier, baseUri], {
159
+ persistent: persistent,
160
+ description: collection.description,
161
+ variableMutators: new Map(collection.mutators)
162
+ });
163
+ }
164
+
165
+ restorePersisted(jsonValue: string): void {
166
+ const collectionsJson: SerializedExtensionEnvironmentVariableCollection[] = JSON.parse(jsonValue);
167
+ collectionsJson.forEach(c => this.doSetCollection(c.extensionIdentifier, c.rootUri ?? NO_ROOT_URI, true, c.collection));
168
+
169
+ }
170
+
171
+ deleteCollection(extensionIdentifier: string): void {
172
+ this.collections.delete([extensionIdentifier]);
173
+ this.updateCollections();
174
+ }
175
+
176
+ private updateCollections(): void {
177
+ this.persistCollections();
178
+ }
179
+
180
+ protected persistCollections(): void {
181
+ const collectionsJson: SerializedExtensionEnvironmentVariableCollection[] = [];
182
+ this.collections.forEach((collection, [extensionIdentifier, rootUri]) => {
183
+ if (collection.persistent) {
184
+ collectionsJson.push({
185
+ extensionIdentifier,
186
+ rootUri,
187
+ collection: {
188
+ description: collection.description,
189
+ mutators: [...this.collections.get([extensionIdentifier, rootUri])!.variableMutators.entries()]
190
+ },
191
+ });
192
+ }
193
+ });
194
+ if (this.client) {
195
+ const stringifiedJson = JSON.stringify(collectionsJson);
196
+ this.client.storeTerminalEnvVariables(stringifiedJson);
197
+ }
198
+ }
199
+
200
+ async getEnvVarCollectionDescriptionsByExtension(id: number): Promise<Map<string, (string | MarkdownString | undefined)[]>> {
201
+ const terminal = this.processManager.get(id);
202
+ if (!(terminal instanceof TerminalProcess)) {
203
+ throw new Error(`terminal "${id}" does not exist`);
204
+ }
205
+ const result = new Map<string, (string | MarkdownString | undefined)[]>();
206
+ this.collections.forEach((value, key) => {
207
+ const prev = result.get(key[0]) || [];
208
+ prev.push(value.description);
209
+ result.set(key[0], prev);
210
+ });
211
+ return result;
212
+ }
213
+
214
+ async getEnvVarCollections(): Promise<[string, string, boolean, SerializableEnvironmentVariableCollection][]> {
215
+ const result: [string, string, boolean, SerializableEnvironmentVariableCollection][] = [];
216
+
217
+ this.collections.forEach((value, [extensionIdentifier, rootUri]) => {
218
+ result.push([extensionIdentifier, rootUri, value.persistent, { description: value.description, mutators: [...value.variableMutators.entries()] }]);
219
+ });
220
+
221
+ return result;
222
+ }
223
+ }
@@ -1,63 +1,63 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2018 Ericsson 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 { createTerminalTestContainer } from './test/terminal-test-container';
18
- import { BackendApplication } from '@theia/core/lib/node/backend-application';
19
- import { IShellTerminalServer } from '../common/shell-terminal-protocol';
20
- import * as http from 'http';
21
- import * as https from 'https';
22
- import { terminalsPath } from '../common/terminal-protocol';
23
- import { TestWebSocketChannelSetup } from '@theia/core/lib/node/messaging/test/test-web-socket-channel';
24
-
25
- describe('Terminal Backend Contribution', function (): void {
26
-
27
- this.timeout(10000);
28
- let server: http.Server | https.Server;
29
- let shellTerminalServer: IShellTerminalServer;
30
-
31
- beforeEach(async () => {
32
- const container = createTerminalTestContainer();
33
- const application = container.get(BackendApplication);
34
- shellTerminalServer = container.get(IShellTerminalServer);
35
- server = await application.start(3000, 'localhost');
36
- });
37
-
38
- afterEach(() => {
39
- const s = server;
40
- server = undefined!;
41
- shellTerminalServer = undefined!;
42
- s.close();
43
- });
44
-
45
- it('is data received from the terminal ws server', async () => {
46
- const terminalId = await shellTerminalServer.create({});
47
- await new Promise<void>((resolve, reject) => {
48
- const path = `${terminalsPath}/${terminalId}`;
49
- const { connectionProvider } = new TestWebSocketChannelSetup({ server, path });
50
-
51
- connectionProvider.listen(path, (path2, channel) => {
52
- channel.onError(reject);
53
- channel.onClose(event => reject(new Error(`channel is closed with '${event.code}' code and '${event.reason}' reason}`)));
54
- if (path2 === path) {
55
- resolve();
56
- channel.close();
57
- }
58
- }, false);
59
-
60
- });
61
- });
62
-
63
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2018 Ericsson 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 { createTerminalTestContainer } from './test/terminal-test-container';
18
+ import { BackendApplication } from '@theia/core/lib/node/backend-application';
19
+ import { IShellTerminalServer } from '../common/shell-terminal-protocol';
20
+ import * as http from 'http';
21
+ import * as https from 'https';
22
+ import { terminalsPath } from '../common/terminal-protocol';
23
+ import { TestWebSocketChannelSetup } from '@theia/core/lib/node/messaging/test/test-web-socket-channel';
24
+
25
+ describe('Terminal Backend Contribution', function (): void {
26
+
27
+ this.timeout(10000);
28
+ let server: http.Server | https.Server;
29
+ let shellTerminalServer: IShellTerminalServer;
30
+
31
+ beforeEach(async () => {
32
+ const container = createTerminalTestContainer();
33
+ const application = container.get(BackendApplication);
34
+ shellTerminalServer = container.get(IShellTerminalServer);
35
+ server = await application.start(3000, 'localhost');
36
+ });
37
+
38
+ afterEach(() => {
39
+ const s = server;
40
+ server = undefined!;
41
+ shellTerminalServer = undefined!;
42
+ s.close();
43
+ });
44
+
45
+ it('is data received from the terminal ws server', async () => {
46
+ const terminalId = await shellTerminalServer.create({});
47
+ await new Promise<void>((resolve, reject) => {
48
+ const path = `${terminalsPath}/${terminalId}`;
49
+ const { connectionProvider } = new TestWebSocketChannelSetup({ server, path });
50
+
51
+ connectionProvider.listen(path, (path2, channel) => {
52
+ channel.onError(reject);
53
+ channel.onClose(event => reject(new Error(`channel is closed with '${event.code}' code and '${event.reason}' reason}`)));
54
+ if (path2 === path) {
55
+ resolve();
56
+ channel.close();
57
+ }
58
+ }, false);
59
+
60
+ });
61
+ });
62
+
63
+ });