@theia/process 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,121 +1,121 @@
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
- import * as chai from 'chai';
17
- import * as process from 'process';
18
- import * as stream from 'stream';
19
- import { createProcessTestContainer } from './test/process-test-container';
20
- import { TerminalProcessFactory } from './terminal-process';
21
- import { IProcessExitEvent, ProcessErrorEvent } from './process';
22
- import { isWindows } from '@theia/core/lib/common/os';
23
-
24
- /**
25
- * Globals
26
- */
27
-
28
- const expect = chai.expect;
29
-
30
- let terminalProcessFactory: TerminalProcessFactory;
31
-
32
- beforeEach(() => {
33
- terminalProcessFactory = createProcessTestContainer().get<TerminalProcessFactory>(TerminalProcessFactory);
34
- });
35
-
36
- describe('TerminalProcess', function (): void {
37
-
38
- this.timeout(20_000);
39
-
40
- it('test error on non existent path', async function (): Promise<void> {
41
- const error = await new Promise<ProcessErrorEvent>((resolve, reject) => {
42
- const proc = terminalProcessFactory({ command: '/non-existent' });
43
- proc.onStart(reject);
44
- proc.onError(resolve);
45
- proc.onExit(reject);
46
- });
47
-
48
- expect(error.code).eq('ENOENT');
49
- });
50
-
51
- it('test implicit .exe (Windows only)', async function (): Promise<void> {
52
- const match = /^(.+)\.exe$/.exec(process.execPath);
53
- if (!isWindows || !match) {
54
- this.skip();
55
- }
56
-
57
- const command = match[1];
58
- const args = ['--version'];
59
- const terminal = await new Promise<IProcessExitEvent>((resolve, reject) => {
60
- const proc = terminalProcessFactory({ command, args });
61
- proc.onExit(resolve);
62
- proc.onError(reject);
63
- });
64
-
65
- expect(terminal.code).to.exist;
66
- });
67
-
68
- it('test error on trying to execute a directory', async function (): Promise<void> {
69
- const error = await new Promise<ProcessErrorEvent>((resolve, reject) => {
70
- const proc = terminalProcessFactory({ command: __dirname });
71
- proc.onStart(reject);
72
- proc.onError(resolve);
73
- proc.onExit(reject);
74
- });
75
-
76
- if (isWindows) {
77
- // On Windows, node-pty returns us a "File not found" message, so we can't really differentiate this case
78
- // from trying to execute a non-existent file. node's child_process.spawn also returns ENOENT, so it's
79
- // probably the best we can get.
80
- expect(error.code).eq('ENOENT');
81
- } else {
82
- expect(error.code).eq('EACCES');
83
- }
84
- });
85
-
86
- it('test exit', async function (): Promise<void> {
87
- const args = ['--version'];
88
- const exit = await new Promise<IProcessExitEvent>((resolve, reject) => {
89
- const proc = terminalProcessFactory({ command: process.execPath, args });
90
- proc.onExit(resolve);
91
- proc.onError(reject);
92
- });
93
-
94
- expect(exit.code).eq(0);
95
- });
96
-
97
- it('test pipe stream', async function (): Promise<void> {
98
- const v = await new Promise<string>((resolve, reject) => {
99
- const args = ['--version'];
100
- const terminalProcess = terminalProcessFactory({ command: process.execPath, args });
101
- terminalProcess.onError(reject);
102
- const outStream = new stream.PassThrough();
103
-
104
- terminalProcess.createOutputStream().pipe(outStream);
105
-
106
- let version = '';
107
- outStream.on('data', data => {
108
- version += data.toString();
109
- });
110
- /* node-pty is not sending 'end' on the stream as it quits
111
- only 'exit' is sent on the terminal process. */
112
- terminalProcess.onExit(() => {
113
- resolve(version.trim());
114
- });
115
- });
116
-
117
- /* Avoid using equal since terminal characters can be inserted at the end. */
118
- expect(v).to.have.string(process.version);
119
- });
120
-
121
- });
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
+ import * as chai from 'chai';
17
+ import * as process from 'process';
18
+ import * as stream from 'stream';
19
+ import { createProcessTestContainer } from './test/process-test-container';
20
+ import { TerminalProcessFactory } from './terminal-process';
21
+ import { IProcessExitEvent, ProcessErrorEvent } from './process';
22
+ import { isWindows } from '@theia/core/lib/common/os';
23
+
24
+ /**
25
+ * Globals
26
+ */
27
+
28
+ const expect = chai.expect;
29
+
30
+ let terminalProcessFactory: TerminalProcessFactory;
31
+
32
+ beforeEach(() => {
33
+ terminalProcessFactory = createProcessTestContainer().get<TerminalProcessFactory>(TerminalProcessFactory);
34
+ });
35
+
36
+ describe('TerminalProcess', function (): void {
37
+
38
+ this.timeout(20_000);
39
+
40
+ it('test error on non existent path', async function (): Promise<void> {
41
+ const error = await new Promise<ProcessErrorEvent>((resolve, reject) => {
42
+ const proc = terminalProcessFactory({ command: '/non-existent' });
43
+ proc.onStart(reject);
44
+ proc.onError(resolve);
45
+ proc.onExit(reject);
46
+ });
47
+
48
+ expect(error.code).eq('ENOENT');
49
+ });
50
+
51
+ it('test implicit .exe (Windows only)', async function (): Promise<void> {
52
+ const match = /^(.+)\.exe$/.exec(process.execPath);
53
+ if (!isWindows || !match) {
54
+ this.skip();
55
+ }
56
+
57
+ const command = match[1];
58
+ const args = ['--version'];
59
+ const terminal = await new Promise<IProcessExitEvent>((resolve, reject) => {
60
+ const proc = terminalProcessFactory({ command, args });
61
+ proc.onExit(resolve);
62
+ proc.onError(reject);
63
+ });
64
+
65
+ expect(terminal.code).to.exist;
66
+ });
67
+
68
+ it('test error on trying to execute a directory', async function (): Promise<void> {
69
+ const error = await new Promise<ProcessErrorEvent>((resolve, reject) => {
70
+ const proc = terminalProcessFactory({ command: __dirname });
71
+ proc.onStart(reject);
72
+ proc.onError(resolve);
73
+ proc.onExit(reject);
74
+ });
75
+
76
+ if (isWindows) {
77
+ // On Windows, node-pty returns us a "File not found" message, so we can't really differentiate this case
78
+ // from trying to execute a non-existent file. node's child_process.spawn also returns ENOENT, so it's
79
+ // probably the best we can get.
80
+ expect(error.code).eq('ENOENT');
81
+ } else {
82
+ expect(error.code).eq('EACCES');
83
+ }
84
+ });
85
+
86
+ it('test exit', async function (): Promise<void> {
87
+ const args = ['--version'];
88
+ const exit = await new Promise<IProcessExitEvent>((resolve, reject) => {
89
+ const proc = terminalProcessFactory({ command: process.execPath, args });
90
+ proc.onExit(resolve);
91
+ proc.onError(reject);
92
+ });
93
+
94
+ expect(exit.code).eq(0);
95
+ });
96
+
97
+ it('test pipe stream', async function (): Promise<void> {
98
+ const v = await new Promise<string>((resolve, reject) => {
99
+ const args = ['--version'];
100
+ const terminalProcess = terminalProcessFactory({ command: process.execPath, args });
101
+ terminalProcess.onError(reject);
102
+ const outStream = new stream.PassThrough();
103
+
104
+ terminalProcess.createOutputStream().pipe(outStream);
105
+
106
+ let version = '';
107
+ outStream.on('data', data => {
108
+ version += data.toString();
109
+ });
110
+ /* node-pty is not sending 'end' on the stream as it quits
111
+ only 'exit' is sent on the terminal process. */
112
+ terminalProcess.onExit(() => {
113
+ resolve(version.trim());
114
+ });
115
+ });
116
+
117
+ /* Avoid using equal since terminal characters can be inserted at the end. */
118
+ expect(v).to.have.string(process.version);
119
+ });
120
+
121
+ });