Comparing version 0.11.0-beta28 to 0.11.0-beta29
@@ -12,2 +12,3 @@ "use strict"; | ||
var tty = require("tty"); | ||
var fs = require("fs"); | ||
var os_1 = require("os"); | ||
@@ -244,2 +245,65 @@ var testUtils_test_1 = require("./testUtils.test"); | ||
}); | ||
if (process.platform === 'linux') { | ||
it('should not close on exec when closeFDs is not defined', function (done) { | ||
var data = "\n var pty = require('./lib/index');\n var ptyProcess = pty.spawn('node', ['-e', 'setTimeout(() => console.log(\"hello from terminal\"), 300);']);\n ptyProcess.on('data', function (data) {\n console.log(data);\n });\n setTimeout(() => null, 500);\n console.log('ready', ptyProcess.pid);\n "; | ||
var buffer = []; | ||
var readFd = fs.openSync(FIXTURES_PATH, 'r'); | ||
var p = cp.spawn('node', ['-e', data], { | ||
stdio: ['ignore', 'pipe', 'pipe', readFd] | ||
}); | ||
var sub = ''; | ||
p.stdout.on('data', function (data) { | ||
if (!data.toString().indexOf('ready')) { | ||
sub = data.toString().split(' ')[1].slice(0, -1); | ||
try { | ||
fs.statSync("/proc/" + sub + "/fd/" + readFd); | ||
} | ||
catch (_) { | ||
done('not reachable'); | ||
} | ||
setTimeout(function () { | ||
process.kill(parseInt(sub), 'SIGINT'); // SIGINT to child | ||
p.kill('SIGINT'); // SIGINT to parent | ||
}, 200); | ||
} | ||
else { | ||
buffer.push(data.toString().replace(/^\s+|\s+$/g, '')); | ||
} | ||
}); | ||
p.on('close', function () { | ||
done(); | ||
}); | ||
}); | ||
it('should close on exec when closeFDs is true', function (done) { | ||
var data = "\n var pty = require('./lib/index');\n var ptyProcess = pty.spawn('node', ['-e', 'setTimeout(() => console.log(\"hello from terminal\"), 300);'], {\n closeFDs: true\n });\n ptyProcess.on('data', function (data) {\n console.log(data);\n });\n setTimeout(() => null, 500);\n console.log('ready', ptyProcess.pid);\n "; | ||
var buffer = []; | ||
var readFd = fs.openSync(FIXTURES_PATH, 'r'); | ||
var p = cp.spawn('node', ['-e', data], { | ||
stdio: ['ignore', 'pipe', 'pipe', readFd] | ||
}); | ||
var sub = ''; | ||
p.stdout.on('data', function (data) { | ||
if (!data.toString().indexOf('ready')) { | ||
sub = data.toString().split(' ')[1].slice(0, -1); | ||
try { | ||
fs.statSync("/proc/" + sub + "/fd/" + readFd); | ||
done('not reachable'); | ||
} | ||
catch (error) { | ||
assert.notStrictEqual(error.message.indexOf('ENOENT'), -1); | ||
} | ||
setTimeout(function () { | ||
process.kill(parseInt(sub), 'SIGINT'); // SIGINT to child | ||
p.kill('SIGINT'); // SIGINT to parent | ||
}, 200); | ||
} | ||
else { | ||
buffer.push(data.toString().replace(/^\s+|\s+$/g, '')); | ||
} | ||
}); | ||
p.on('close', function () { | ||
done(); | ||
}); | ||
}); | ||
} | ||
}); | ||
@@ -246,0 +310,0 @@ }); |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.11.0-beta28", | ||
"version": "0.11.0-beta29", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "main": "./lib/index.js", |
@@ -11,2 +11,3 @@ /** | ||
import * as tty from 'tty'; | ||
import * as fs from 'fs'; | ||
import { constants } from 'os'; | ||
@@ -284,4 +285,81 @@ import { pollUntil } from './testUtils.test'; | ||
}); | ||
if (process.platform === 'linux') { | ||
it('should not close on exec when closeFDs is not defined', (done) => { | ||
const data = ` | ||
var pty = require('./lib/index'); | ||
var ptyProcess = pty.spawn('node', ['-e', 'setTimeout(() => console.log("hello from terminal"), 300);']); | ||
ptyProcess.on('data', function (data) { | ||
console.log(data); | ||
}); | ||
setTimeout(() => null, 500); | ||
console.log('ready', ptyProcess.pid); | ||
`; | ||
const buffer: string[] = []; | ||
const readFd = fs.openSync(FIXTURES_PATH, 'r'); | ||
const p = cp.spawn('node', ['-e', data], { | ||
stdio: ['ignore', 'pipe', 'pipe', readFd] | ||
}); | ||
let sub = ''; | ||
p.stdout!.on('data', (data) => { | ||
if (!data.toString().indexOf('ready')) { | ||
sub = data.toString().split(' ')[1].slice(0, -1); | ||
try { | ||
fs.statSync(`/proc/${sub}/fd/${readFd}`); | ||
} catch (_) { | ||
done('not reachable'); | ||
} | ||
setTimeout(() => { | ||
process.kill(parseInt(sub), 'SIGINT'); // SIGINT to child | ||
p.kill('SIGINT'); // SIGINT to parent | ||
}, 200); | ||
} else { | ||
buffer.push(data.toString().replace(/^\s+|\s+$/g, '')); | ||
} | ||
}); | ||
p.on('close', () => { | ||
done(); | ||
}); | ||
}); | ||
it('should close on exec when closeFDs is true', (done) => { | ||
const data = ` | ||
var pty = require('./lib/index'); | ||
var ptyProcess = pty.spawn('node', ['-e', 'setTimeout(() => console.log("hello from terminal"), 300);'], { | ||
closeFDs: true | ||
}); | ||
ptyProcess.on('data', function (data) { | ||
console.log(data); | ||
}); | ||
setTimeout(() => null, 500); | ||
console.log('ready', ptyProcess.pid); | ||
`; | ||
const buffer: string[] = []; | ||
const readFd = fs.openSync(FIXTURES_PATH, 'r'); | ||
const p = cp.spawn('node', ['-e', data], { | ||
stdio: ['ignore', 'pipe', 'pipe', readFd] | ||
}); | ||
let sub = ''; | ||
p.stdout!.on('data', (data) => { | ||
if (!data.toString().indexOf('ready')) { | ||
sub = data.toString().split(' ')[1].slice(0, -1); | ||
try { | ||
fs.statSync(`/proc/${sub}/fd/${readFd}`); | ||
done('not reachable'); | ||
} catch (error) { | ||
assert.notStrictEqual(error.message.indexOf('ENOENT'), -1); | ||
} | ||
setTimeout(() => { | ||
process.kill(parseInt(sub), 'SIGINT'); // SIGINT to child | ||
p.kill('SIGINT'); // SIGINT to parent | ||
}, 200); | ||
} else { | ||
buffer.push(data.toString().replace(/^\s+|\s+$/g, '')); | ||
} | ||
}); | ||
p.on('close', () => { | ||
done(); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1141173
4446
12