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.
@@ -88,125 +88,127 @@ function pollForProcessTreeSize(pid: number, size: number, intervalMs: number =
88
88
  }
89
89
 
90
90
  if (process.platform === 'win32') {
91
- describe('WindowsTerminal', () => {
92
- describe('kill', () => {
93
- it('should not crash parent process', (done) => {
94
- const term = new WindowsTerminal('cmd.exe', [], {});
95
- term.kill();
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
- const desiredState: IProcessState = {};
113
- desiredState[list[0].pid] = false;
114
- desiredState[list[1].pid] = false;
115
- desiredState[list[2].pid] = true;
116
- desiredState[list[3].pid] = false;
117
- pollForProcessState(desiredState).then(() => {
118
- // Kill notepad before done
119
- process.kill(list[2].pid);
120
- done();
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
- describe('resize', () => {
127
- it('should throw a non-native exception when resizing an invalid value', () => {
128
- const term = new WindowsTerminal('cmd.exe', [], {});
129
- assert.throws(() => term.resize(-1, -1));
130
- assert.throws(() => term.resize(0, 0));
131
- assert.doesNotThrow(() => term.resize(1, 1));
132
- });
133
- it('should throw an non-native exception when resizing a killed terminal', (done) => {
134
- const term = new WindowsTerminal('cmd.exe', [], {});
135
- (<any>term)._defer(() => {
136
- term.on('exit', () => {
137
- assert.throws(() => term.resize(1, 1));
138
- done();
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
- describe('Args as CommandLine', () => {
146
- it('should not fail running a file containing a space in the path', (done) => {
147
- const spaceFolder = path.resolve(__dirname, '..', 'fixtures', 'space folder');
148
- if (!fs.existsSync(spaceFolder)) {
149
- fs.mkdirSync(spaceFolder);
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
- const cmdCopiedPath = path.resolve(spaceFolder, 'cmd.exe');
153
- const data = fs.readFileSync(`${process.env.windir}\\System32\\cmd.exe`);
154
- fs.writeFileSync(cmdCopiedPath, data);
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
- if (!fs.existsSync(cmdCopiedPath)) {
157
- // Skip test if git bash isn't installed
158
- return;
159
- }
160
- const term = new WindowsTerminal(cmdCopiedPath, '/c echo "hello world"', {});
161
- let result = '';
162
- term.on('data', (data) => {
163
- result += data;
164
- });
165
- term.on('exit', () => {
166
- assert.ok(result.indexOf('hello world') >= 1);
167
- done();
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
- describe('env', () => {
173
- it('should set environment variables of the shell', (done) => {
174
- const term = new WindowsTerminal('cmd.exe', '/C echo %FOO%', { env: { FOO: 'BAR' }});
175
- let result = '';
176
- term.on('data', (data) => {
177
- result += data;
178
- });
179
- term.on('exit', () => {
180
- assert.ok(result.indexOf('BAR') >= 0);
181
- done();
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
- describe('On close', () => {
187
- it('should return process zero exit codes', (done) => {
188
- const term = new WindowsTerminal('cmd.exe', '/C exit');
189
- term.on('exit', (code) => {
190
- assert.equal(code, 0);
191
- done();
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
- it('should return process non-zero exit codes', (done) => {
196
- const term = new WindowsTerminal('cmd.exe', '/C exit 2');
197
- term.on('exit', (code) => {
198
- assert.equal(code, 2);
199
- done();
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
- describe('winpty', () => {
205
- it('should accept input', (done) => {
206
- const term = new WindowsTerminal('cmd.exe', '', { useConpty: false });
207
- term.write('exit\r');
208
- term.on('exit', () => {
209
- done();
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
  });