@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,69 +1,69 @@
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 { injectable } from '@theia/core/shared/inversify';
18
- import { Emitter, Event } from '@theia/core/lib/common/event';
19
- import {
20
- IBaseTerminalClient,
21
- IBaseTerminalExitEvent,
22
- IBaseTerminalErrorEvent
23
- } from './base-terminal-protocol';
24
-
25
- @injectable()
26
- export class TerminalWatcher {
27
-
28
- getTerminalClient(): IBaseTerminalClient {
29
- const exitEmitter = this.onTerminalExitEmitter;
30
- const errorEmitter = this.onTerminalErrorEmitter;
31
- const storeTerminalEnvVariablesEmitter = this.onStoreTerminalEnvVariablesRequestedEmitter;
32
- const updateTerminalEnvVariablesEmitter = this.onUpdateTerminalEnvVariablesRequestedEmitter;
33
- return {
34
- storeTerminalEnvVariables(data: string): void {
35
- storeTerminalEnvVariablesEmitter.fire(data);
36
- },
37
- updateTerminalEnvVariables(): void {
38
- updateTerminalEnvVariablesEmitter.fire(undefined);
39
- },
40
- onTerminalExitChanged(event: IBaseTerminalExitEvent): void {
41
- exitEmitter.fire(event);
42
- },
43
- onTerminalError(event: IBaseTerminalErrorEvent): void {
44
- errorEmitter.fire(event);
45
- }
46
- };
47
- }
48
-
49
- private onTerminalExitEmitter = new Emitter<IBaseTerminalExitEvent>();
50
- private onTerminalErrorEmitter = new Emitter<IBaseTerminalErrorEvent>();
51
- private onStoreTerminalEnvVariablesRequestedEmitter = new Emitter<string>();
52
- private onUpdateTerminalEnvVariablesRequestedEmitter = new Emitter<undefined>();
53
-
54
- get onTerminalExit(): Event<IBaseTerminalExitEvent> {
55
- return this.onTerminalExitEmitter.event;
56
- }
57
-
58
- get onTerminalError(): Event<IBaseTerminalErrorEvent> {
59
- return this.onTerminalErrorEmitter.event;
60
- }
61
-
62
- get onStoreTerminalEnvVariablesRequested(): Event<string> {
63
- return this.onStoreTerminalEnvVariablesRequestedEmitter.event;
64
- }
65
-
66
- get onUpdateTerminalEnvVariablesRequested(): Event<undefined> {
67
- return this.onUpdateTerminalEnvVariablesRequestedEmitter.event;
68
- }
69
- }
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 { injectable } from '@theia/core/shared/inversify';
18
+ import { Emitter, Event } from '@theia/core/lib/common/event';
19
+ import {
20
+ IBaseTerminalClient,
21
+ IBaseTerminalExitEvent,
22
+ IBaseTerminalErrorEvent
23
+ } from './base-terminal-protocol';
24
+
25
+ @injectable()
26
+ export class TerminalWatcher {
27
+
28
+ getTerminalClient(): IBaseTerminalClient {
29
+ const exitEmitter = this.onTerminalExitEmitter;
30
+ const errorEmitter = this.onTerminalErrorEmitter;
31
+ const storeTerminalEnvVariablesEmitter = this.onStoreTerminalEnvVariablesRequestedEmitter;
32
+ const updateTerminalEnvVariablesEmitter = this.onUpdateTerminalEnvVariablesRequestedEmitter;
33
+ return {
34
+ storeTerminalEnvVariables(data: string): void {
35
+ storeTerminalEnvVariablesEmitter.fire(data);
36
+ },
37
+ updateTerminalEnvVariables(): void {
38
+ updateTerminalEnvVariablesEmitter.fire(undefined);
39
+ },
40
+ onTerminalExitChanged(event: IBaseTerminalExitEvent): void {
41
+ exitEmitter.fire(event);
42
+ },
43
+ onTerminalError(event: IBaseTerminalErrorEvent): void {
44
+ errorEmitter.fire(event);
45
+ }
46
+ };
47
+ }
48
+
49
+ private onTerminalExitEmitter = new Emitter<IBaseTerminalExitEvent>();
50
+ private onTerminalErrorEmitter = new Emitter<IBaseTerminalErrorEvent>();
51
+ private onStoreTerminalEnvVariablesRequestedEmitter = new Emitter<string>();
52
+ private onUpdateTerminalEnvVariablesRequestedEmitter = new Emitter<undefined>();
53
+
54
+ get onTerminalExit(): Event<IBaseTerminalExitEvent> {
55
+ return this.onTerminalExitEmitter.event;
56
+ }
57
+
58
+ get onTerminalError(): Event<IBaseTerminalErrorEvent> {
59
+ return this.onTerminalErrorEmitter.event;
60
+ }
61
+
62
+ get onStoreTerminalEnvVariablesRequested(): Event<string> {
63
+ return this.onStoreTerminalEnvVariablesRequestedEmitter.event;
64
+ }
65
+
66
+ get onUpdateTerminalEnvVariablesRequested(): Event<undefined> {
67
+ return this.onUpdateTerminalEnvVariablesRequestedEmitter.event;
68
+ }
69
+ }
@@ -1,173 +1,173 @@
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, DisposableCollection } from '@theia/core/lib/common';
19
- import {
20
- IBaseTerminalServer,
21
- IBaseTerminalServerOptions,
22
- IBaseTerminalClient,
23
- TerminalProcessInfo,
24
- TerminalExitReason
25
- } from '../common/base-terminal-protocol';
26
- import { TerminalProcess, ProcessManager, TaskTerminalProcess } from '@theia/process/lib/node';
27
- import { ShellProcess } from './shell-process';
28
-
29
- @injectable()
30
- export abstract class BaseTerminalServer implements IBaseTerminalServer {
31
- protected client: IBaseTerminalClient | undefined = undefined;
32
- protected terminalToDispose = new Map<number, DisposableCollection>();
33
-
34
- constructor(
35
- @inject(ProcessManager) protected readonly processManager: ProcessManager,
36
- @inject(ILogger) @named('terminal') protected readonly logger: ILogger
37
- ) {
38
- processManager.onDelete(id => {
39
- const toDispose = this.terminalToDispose.get(id);
40
- if (toDispose !== undefined) {
41
- toDispose.dispose();
42
- this.terminalToDispose.delete(id);
43
- }
44
- });
45
- }
46
-
47
- abstract create(options: IBaseTerminalServerOptions): Promise<number>;
48
-
49
- async attach(id: number): Promise<number> {
50
- const term = this.processManager.get(id);
51
-
52
- if (term && term instanceof TerminalProcess) {
53
- return term.id;
54
- } else {
55
- this.logger.warn(`Couldn't attach - can't find terminal with id: ${id} `);
56
- return -1;
57
- }
58
- }
59
-
60
- async onAttachAttempted(id: number): Promise<void> {
61
- const terminal = this.processManager.get(id);
62
- if (terminal instanceof TaskTerminalProcess) {
63
- terminal.attachmentAttempted = true;
64
- if (terminal.exited) {
65
- // Didn't execute `unregisterProcess` on terminal `exit` event to enable attaching task output to terminal,
66
- // Fixes https://github.com/eclipse-theia/theia/issues/2961
67
- terminal.unregisterProcess();
68
- } else {
69
- this.postAttachAttempted(terminal);
70
- }
71
- }
72
- }
73
-
74
- async getProcessId(id: number): Promise<number> {
75
- const terminal = this.processManager.get(id);
76
- if (!(terminal instanceof TerminalProcess)) {
77
- throw new Error(`terminal "${id}" does not exist`);
78
- }
79
- return terminal.pid;
80
- }
81
-
82
- async getProcessInfo(id: number): Promise<TerminalProcessInfo> {
83
- const terminal = this.processManager.get(id);
84
- if (!(terminal instanceof TerminalProcess)) {
85
- throw new Error(`terminal "${id}" does not exist`);
86
- }
87
- return {
88
- executable: terminal.executable,
89
- arguments: terminal.arguments,
90
- };
91
- }
92
-
93
- async getCwdURI(id: number): Promise<string> {
94
- const terminal = this.processManager.get(id);
95
- if (!(terminal instanceof TerminalProcess)) {
96
- throw new Error(`terminal "${id}" does not exist`);
97
- }
98
- return terminal.getCwdURI();
99
- }
100
-
101
- async close(id: number): Promise<void> {
102
- const term = this.processManager.get(id);
103
-
104
- if (term instanceof TerminalProcess) {
105
- term.kill();
106
- }
107
- }
108
-
109
- async getDefaultShell(): Promise<string> {
110
- return ShellProcess.getShellExecutablePath();
111
- }
112
-
113
- dispose(): void {
114
- // noop
115
- }
116
-
117
- async resize(id: number, cols: number, rows: number): Promise<void> {
118
- const term = this.processManager.get(id);
119
- if (term && term instanceof TerminalProcess) {
120
- term.resize(cols, rows);
121
- } else {
122
- console.warn("Couldn't resize terminal " + id + ", because it doesn't exist.");
123
- }
124
- }
125
-
126
- /* Set the client to receive notifications on. */
127
- setClient(client: IBaseTerminalClient | undefined): void {
128
- this.client = client;
129
- if (!this.client) {
130
- return;
131
- }
132
- this.client.updateTerminalEnvVariables();
133
- }
134
-
135
- protected notifyClientOnExit(term: TerminalProcess): DisposableCollection {
136
- const toDispose = new DisposableCollection();
137
-
138
- toDispose.push(term.onError(error => {
139
- this.logger.error(`Terminal pid: ${term.pid} error: ${error}, closing it.`);
140
-
141
- if (this.client !== undefined) {
142
- this.client.onTerminalError({
143
- terminalId: term.id,
144
- error: new Error(`Failed to execute terminal process (${error.code})`),
145
- attached: term instanceof TaskTerminalProcess && term.attachmentAttempted
146
- });
147
- }
148
- }));
149
-
150
- toDispose.push(term.onExit(event => {
151
- if (this.client !== undefined) {
152
- this.client.onTerminalExitChanged({
153
- terminalId: term.id,
154
- code: event.code,
155
- reason: TerminalExitReason.Process,
156
- signal: event.signal,
157
- attached: term instanceof TaskTerminalProcess && term.attachmentAttempted
158
- });
159
- }
160
- }));
161
- return toDispose;
162
- }
163
-
164
- protected postCreate(term: TerminalProcess): void {
165
- const toDispose = this.notifyClientOnExit(term);
166
- this.terminalToDispose.set(term.id, toDispose);
167
- }
168
-
169
- protected postAttachAttempted(term: TaskTerminalProcess): void {
170
- const toDispose = this.notifyClientOnExit(term);
171
- this.terminalToDispose.set(term.id, toDispose);
172
- }
173
- }
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, DisposableCollection } from '@theia/core/lib/common';
19
+ import {
20
+ IBaseTerminalServer,
21
+ IBaseTerminalServerOptions,
22
+ IBaseTerminalClient,
23
+ TerminalProcessInfo,
24
+ TerminalExitReason
25
+ } from '../common/base-terminal-protocol';
26
+ import { TerminalProcess, ProcessManager, TaskTerminalProcess } from '@theia/process/lib/node';
27
+ import { ShellProcess } from './shell-process';
28
+
29
+ @injectable()
30
+ export abstract class BaseTerminalServer implements IBaseTerminalServer {
31
+ protected client: IBaseTerminalClient | undefined = undefined;
32
+ protected terminalToDispose = new Map<number, DisposableCollection>();
33
+
34
+ constructor(
35
+ @inject(ProcessManager) protected readonly processManager: ProcessManager,
36
+ @inject(ILogger) @named('terminal') protected readonly logger: ILogger
37
+ ) {
38
+ processManager.onDelete(id => {
39
+ const toDispose = this.terminalToDispose.get(id);
40
+ if (toDispose !== undefined) {
41
+ toDispose.dispose();
42
+ this.terminalToDispose.delete(id);
43
+ }
44
+ });
45
+ }
46
+
47
+ abstract create(options: IBaseTerminalServerOptions): Promise<number>;
48
+
49
+ async attach(id: number): Promise<number> {
50
+ const term = this.processManager.get(id);
51
+
52
+ if (term && term instanceof TerminalProcess) {
53
+ return term.id;
54
+ } else {
55
+ this.logger.warn(`Couldn't attach - can't find terminal with id: ${id} `);
56
+ return -1;
57
+ }
58
+ }
59
+
60
+ async onAttachAttempted(id: number): Promise<void> {
61
+ const terminal = this.processManager.get(id);
62
+ if (terminal instanceof TaskTerminalProcess) {
63
+ terminal.attachmentAttempted = true;
64
+ if (terminal.exited) {
65
+ // Didn't execute `unregisterProcess` on terminal `exit` event to enable attaching task output to terminal,
66
+ // Fixes https://github.com/eclipse-theia/theia/issues/2961
67
+ terminal.unregisterProcess();
68
+ } else {
69
+ this.postAttachAttempted(terminal);
70
+ }
71
+ }
72
+ }
73
+
74
+ async getProcessId(id: number): Promise<number> {
75
+ const terminal = this.processManager.get(id);
76
+ if (!(terminal instanceof TerminalProcess)) {
77
+ throw new Error(`terminal "${id}" does not exist`);
78
+ }
79
+ return terminal.pid;
80
+ }
81
+
82
+ async getProcessInfo(id: number): Promise<TerminalProcessInfo> {
83
+ const terminal = this.processManager.get(id);
84
+ if (!(terminal instanceof TerminalProcess)) {
85
+ throw new Error(`terminal "${id}" does not exist`);
86
+ }
87
+ return {
88
+ executable: terminal.executable,
89
+ arguments: terminal.arguments,
90
+ };
91
+ }
92
+
93
+ async getCwdURI(id: number): Promise<string> {
94
+ const terminal = this.processManager.get(id);
95
+ if (!(terminal instanceof TerminalProcess)) {
96
+ throw new Error(`terminal "${id}" does not exist`);
97
+ }
98
+ return terminal.getCwdURI();
99
+ }
100
+
101
+ async close(id: number): Promise<void> {
102
+ const term = this.processManager.get(id);
103
+
104
+ if (term instanceof TerminalProcess) {
105
+ term.kill();
106
+ }
107
+ }
108
+
109
+ async getDefaultShell(): Promise<string> {
110
+ return ShellProcess.getShellExecutablePath();
111
+ }
112
+
113
+ dispose(): void {
114
+ // noop
115
+ }
116
+
117
+ async resize(id: number, cols: number, rows: number): Promise<void> {
118
+ const term = this.processManager.get(id);
119
+ if (term && term instanceof TerminalProcess) {
120
+ term.resize(cols, rows);
121
+ } else {
122
+ console.warn("Couldn't resize terminal " + id + ", because it doesn't exist.");
123
+ }
124
+ }
125
+
126
+ /* Set the client to receive notifications on. */
127
+ setClient(client: IBaseTerminalClient | undefined): void {
128
+ this.client = client;
129
+ if (!this.client) {
130
+ return;
131
+ }
132
+ this.client.updateTerminalEnvVariables();
133
+ }
134
+
135
+ protected notifyClientOnExit(term: TerminalProcess): DisposableCollection {
136
+ const toDispose = new DisposableCollection();
137
+
138
+ toDispose.push(term.onError(error => {
139
+ this.logger.error(`Terminal pid: ${term.pid} error: ${error}, closing it.`);
140
+
141
+ if (this.client !== undefined) {
142
+ this.client.onTerminalError({
143
+ terminalId: term.id,
144
+ error: new Error(`Failed to execute terminal process (${error.code})`),
145
+ attached: term instanceof TaskTerminalProcess && term.attachmentAttempted
146
+ });
147
+ }
148
+ }));
149
+
150
+ toDispose.push(term.onExit(event => {
151
+ if (this.client !== undefined) {
152
+ this.client.onTerminalExitChanged({
153
+ terminalId: term.id,
154
+ code: event.code,
155
+ reason: TerminalExitReason.Process,
156
+ signal: event.signal,
157
+ attached: term instanceof TaskTerminalProcess && term.attachmentAttempted
158
+ });
159
+ }
160
+ }));
161
+ return toDispose;
162
+ }
163
+
164
+ protected postCreate(term: TerminalProcess): void {
165
+ const toDispose = this.notifyClientOnExit(term);
166
+ this.terminalToDispose.set(term.id, toDispose);
167
+ }
168
+
169
+ protected postAttachAttempted(term: TaskTerminalProcess): void {
170
+ const toDispose = this.notifyClientOnExit(term);
171
+ this.terminalToDispose.set(term.id, toDispose);
172
+ }
173
+ }
@@ -1,46 +1,46 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 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 { wait } from '@theia/core/lib/common/promise-util';
18
- import { expect } from 'chai';
19
- import { BufferBufferingStream } from './buffering-stream';
20
-
21
- describe('BufferringStream', () => {
22
-
23
- it('should emit whatever data was buffered before the timeout', async () => {
24
- const buffer = new BufferBufferingStream({ emitInterval: 1000 });
25
- const chunkPromise = waitForChunk(buffer);
26
- buffer.push(Buffer.from([0]));
27
- await wait(100);
28
- buffer.push(Buffer.from([1]));
29
- await wait(100);
30
- buffer.push(Buffer.from([2, 3, 4]));
31
- const chunk = await chunkPromise;
32
- expect(chunk).deep.eq(Buffer.from([0, 1, 2, 3, 4]));
33
- });
34
-
35
- it('should not emit chunks bigger than maxChunkSize', async () => {
36
- const buffer = new BufferBufferingStream({ maxChunkSize: 2 });
37
- buffer.push(Buffer.from([0, 1, 2, 3, 4, 5]));
38
- expect(await waitForChunk(buffer)).deep.eq(Buffer.from([0, 1]));
39
- expect(await waitForChunk(buffer)).deep.eq(Buffer.from([2, 3]));
40
- expect(await waitForChunk(buffer)).deep.eq(Buffer.from([4, 5]));
41
- });
42
-
43
- function waitForChunk(buffer: BufferBufferingStream): Promise<Buffer> {
44
- return new Promise(resolve => buffer.onData(resolve));
45
- }
46
- });
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 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 { wait } from '@theia/core/lib/common/promise-util';
18
+ import { expect } from 'chai';
19
+ import { BufferBufferingStream } from './buffering-stream';
20
+
21
+ describe('BufferringStream', () => {
22
+
23
+ it('should emit whatever data was buffered before the timeout', async () => {
24
+ const buffer = new BufferBufferingStream({ emitInterval: 1000 });
25
+ const chunkPromise = waitForChunk(buffer);
26
+ buffer.push(Buffer.from([0]));
27
+ await wait(100);
28
+ buffer.push(Buffer.from([1]));
29
+ await wait(100);
30
+ buffer.push(Buffer.from([2, 3, 4]));
31
+ const chunk = await chunkPromise;
32
+ expect(chunk).deep.eq(Buffer.from([0, 1, 2, 3, 4]));
33
+ });
34
+
35
+ it('should not emit chunks bigger than maxChunkSize', async () => {
36
+ const buffer = new BufferBufferingStream({ maxChunkSize: 2 });
37
+ buffer.push(Buffer.from([0, 1, 2, 3, 4, 5]));
38
+ expect(await waitForChunk(buffer)).deep.eq(Buffer.from([0, 1]));
39
+ expect(await waitForChunk(buffer)).deep.eq(Buffer.from([2, 3]));
40
+ expect(await waitForChunk(buffer)).deep.eq(Buffer.from([4, 5]));
41
+ });
42
+
43
+ function waitForChunk(buffer: BufferBufferingStream): Promise<Buffer> {
44
+ return new Promise(resolve => buffer.onData(resolve));
45
+ }
46
+ });