node-pty 1.0.0 → 1.1.0-beta10
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.
- package/README.md +5 -5
- package/binding.gyp +6 -15
- package/lib/unixTerminal.js +2 -1
- package/lib/unixTerminal.js.map +1 -1
- package/lib/unixTerminal.test.js +23 -0
- package/lib/unixTerminal.test.js.map +1 -1
- package/lib/windowsPtyAgent.js +6 -7
- package/lib/windowsPtyAgent.js.map +1 -1
- package/lib/windowsTerminal.test.js +98 -96
- package/lib/windowsTerminal.test.js.map +1 -1
- package/package.json +3 -2
- package/src/native.d.ts +4 -6
- package/src/unix/pty.cc +245 -289
- package/src/unixTerminal.test.ts +35 -0
- package/src/unixTerminal.ts +2 -1
- package/src/win/conpty.cc +172 -173
- package/src/win/conpty_console_list.cc +18 -17
- package/src/win/path_util.cc +30 -7
- package/src/win/path_util.h +6 -2
- package/src/win/winpty.cc +162 -141
- package/src/windowsPtyAgent.ts +6 -7
- package/src/windowsTerminal.test.ts +99 -97
|
@@ -88,125 +88,127 @@ function pollForProcessTreeSize(pid: number, size: number, intervalMs: number =
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (process.platform === 'win32') {
|
|
91
|
-
|
|
92
|
-
describe(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// Add done call to deferred function queue to ensure the kill call has completed
|
|
97
|
-
(<any>term)._defer(done);
|
|
98
|
-
});
|
|
99
|
-
it('should kill the process tree', function (done: Mocha.Done): void {
|
|
100
|
-
this.timeout(5000);
|
|
101
|
-
const term = new WindowsTerminal('cmd.exe', [], {});
|
|
102
|
-
// Start sub-processes
|
|
103
|
-
term.write('powershell.exe\r');
|
|
104
|
-
term.write('notepad.exe\r');
|
|
105
|
-
term.write('node.exe\r');
|
|
106
|
-
pollForProcessTreeSize(term.pid, 4, 500, 5000).then(list => {
|
|
107
|
-
assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
|
|
108
|
-
assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
|
|
109
|
-
assert.strictEqual(list[2].name.toLowerCase(), 'notepad.exe');
|
|
110
|
-
assert.strictEqual(list[3].name.toLowerCase(), 'node.exe');
|
|
91
|
+
[true, false].forEach((useConpty) => {
|
|
92
|
+
describe(`WindowsTerminal (useConpty = ${useConpty})`, () => {
|
|
93
|
+
describe('kill', () => {
|
|
94
|
+
it('should not crash parent process', (done) => {
|
|
95
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
111
96
|
term.kill();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
97
|
+
// Add done call to deferred function queue to ensure the kill call has completed
|
|
98
|
+
(<any>term)._defer(done);
|
|
99
|
+
});
|
|
100
|
+
it('should kill the process tree', function (done: Mocha.Done): void {
|
|
101
|
+
this.timeout(5000);
|
|
102
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
103
|
+
// Start sub-processes
|
|
104
|
+
term.write('powershell.exe\r');
|
|
105
|
+
term.write('notepad.exe\r');
|
|
106
|
+
term.write('node.exe\r');
|
|
107
|
+
pollForProcessTreeSize(term.pid, 4, 500, 5000).then(list => {
|
|
108
|
+
assert.strictEqual(list[0].name.toLowerCase(), 'cmd.exe');
|
|
109
|
+
assert.strictEqual(list[1].name.toLowerCase(), 'powershell.exe');
|
|
110
|
+
assert.strictEqual(list[2].name.toLowerCase(), 'notepad.exe');
|
|
111
|
+
assert.strictEqual(list[3].name.toLowerCase(), 'node.exe');
|
|
112
|
+
term.kill();
|
|
113
|
+
const desiredState: IProcessState = {};
|
|
114
|
+
desiredState[list[0].pid] = false;
|
|
115
|
+
desiredState[list[1].pid] = false;
|
|
116
|
+
desiredState[list[2].pid] = true;
|
|
117
|
+
desiredState[list[3].pid] = false;
|
|
118
|
+
pollForProcessState(desiredState).then(() => {
|
|
119
|
+
// Kill notepad before done
|
|
120
|
+
process.kill(list[2].pid);
|
|
121
|
+
done();
|
|
122
|
+
});
|
|
121
123
|
});
|
|
122
124
|
});
|
|
123
125
|
});
|
|
124
|
-
});
|
|
125
126
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
127
|
+
describe('resize', () => {
|
|
128
|
+
it('should throw a non-native exception when resizing an invalid value', () => {
|
|
129
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
130
|
+
assert.throws(() => term.resize(-1, -1));
|
|
131
|
+
assert.throws(() => term.resize(0, 0));
|
|
132
|
+
assert.doesNotThrow(() => term.resize(1, 1));
|
|
133
|
+
});
|
|
134
|
+
it('should throw a non-native exception when resizing a killed terminal', (done) => {
|
|
135
|
+
const term = new WindowsTerminal('cmd.exe', [], { useConpty });
|
|
136
|
+
(<any>term)._defer(() => {
|
|
137
|
+
term.on('exit', () => {
|
|
138
|
+
assert.throws(() => term.resize(1, 1));
|
|
139
|
+
done();
|
|
140
|
+
});
|
|
141
|
+
term.destroy();
|
|
139
142
|
});
|
|
140
|
-
term.destroy();
|
|
141
143
|
});
|
|
142
144
|
});
|
|
143
|
-
});
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
146
|
+
describe('Args as CommandLine', () => {
|
|
147
|
+
it('should not fail running a file containing a space in the path', (done) => {
|
|
148
|
+
const spaceFolder = path.resolve(__dirname, '..', 'fixtures', 'space folder');
|
|
149
|
+
if (!fs.existsSync(spaceFolder)) {
|
|
150
|
+
fs.mkdirSync(spaceFolder);
|
|
151
|
+
}
|
|
151
152
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
const cmdCopiedPath = path.resolve(spaceFolder, 'cmd.exe');
|
|
154
|
+
const data = fs.readFileSync(`${process.env.windir}\\System32\\cmd.exe`);
|
|
155
|
+
fs.writeFileSync(cmdCopiedPath, data);
|
|
155
156
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
if (!fs.existsSync(cmdCopiedPath)) {
|
|
158
|
+
// Skip test if git bash isn't installed
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const term = new WindowsTerminal(cmdCopiedPath, '/c echo "hello world"', { useConpty });
|
|
162
|
+
let result = '';
|
|
163
|
+
term.on('data', (data) => {
|
|
164
|
+
result += data;
|
|
165
|
+
});
|
|
166
|
+
term.on('exit', () => {
|
|
167
|
+
assert.ok(result.indexOf('hello world') >= 1);
|
|
168
|
+
done();
|
|
169
|
+
});
|
|
168
170
|
});
|
|
169
171
|
});
|
|
170
|
-
});
|
|
171
172
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
173
|
+
describe('env', () => {
|
|
174
|
+
it('should set environment variables of the shell', (done) => {
|
|
175
|
+
const term = new WindowsTerminal('cmd.exe', '/C echo %FOO%', { env: { FOO: 'BAR' }});
|
|
176
|
+
let result = '';
|
|
177
|
+
term.on('data', (data) => {
|
|
178
|
+
result += data;
|
|
179
|
+
});
|
|
180
|
+
term.on('exit', () => {
|
|
181
|
+
assert.ok(result.indexOf('BAR') >= 0);
|
|
182
|
+
done();
|
|
183
|
+
});
|
|
182
184
|
});
|
|
183
185
|
});
|
|
184
|
-
});
|
|
185
186
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
187
|
+
describe('On close', () => {
|
|
188
|
+
it('should return process zero exit codes', (done) => {
|
|
189
|
+
const term = new WindowsTerminal('cmd.exe', '/C exit', { useConpty });
|
|
190
|
+
term.on('exit', (code) => {
|
|
191
|
+
assert.strictEqual(code, 0);
|
|
192
|
+
done();
|
|
193
|
+
});
|
|
192
194
|
});
|
|
193
|
-
});
|
|
194
195
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
it('should return process non-zero exit codes', (done) => {
|
|
197
|
+
const term = new WindowsTerminal('cmd.exe', '/C exit 2', { useConpty });
|
|
198
|
+
term.on('exit', (code) => {
|
|
199
|
+
assert.strictEqual(code, 2);
|
|
200
|
+
done();
|
|
201
|
+
});
|
|
200
202
|
});
|
|
201
203
|
});
|
|
202
|
-
});
|
|
203
204
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
describe('Write', () => {
|
|
206
|
+
it('should accept input', (done) => {
|
|
207
|
+
const term = new WindowsTerminal('cmd.exe', '', { useConpty });
|
|
208
|
+
term.write('exit\r');
|
|
209
|
+
term.on('exit', () => {
|
|
210
|
+
done();
|
|
211
|
+
});
|
|
210
212
|
});
|
|
211
213
|
});
|
|
212
214
|
});
|