mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Remove unused ChildProcess class
This commit is contained in:
@@ -1,144 +0,0 @@
|
||||
ChildProcess = require 'child-process'
|
||||
|
||||
describe 'Child Processes', ->
|
||||
describe ".exec(command, options)", ->
|
||||
[stderrHandler, stdoutHandler] = []
|
||||
|
||||
beforeEach ->
|
||||
stderrHandler = jasmine.createSpy "stderrHandler"
|
||||
stdoutHandler = jasmine.createSpy "stdoutHandler"
|
||||
|
||||
it "returns a promise that resolves to stdout and stderr", ->
|
||||
waitsForPromise ->
|
||||
cmd = "echo 'good' && echo 'bad' >&2"
|
||||
standardOutput = ''
|
||||
errorOutput = ''
|
||||
options =
|
||||
stdout: (data) ->
|
||||
standardOutput += data
|
||||
stderr: (data) ->
|
||||
errorOutput += data
|
||||
|
||||
ChildProcess.exec(cmd, options).done ->
|
||||
expect(standardOutput).toBe 'good\n'
|
||||
expect(errorOutput).toBe 'bad\n'
|
||||
|
||||
describe "when options are given", ->
|
||||
it "calls the options.stdout callback when new data is received on stdout", ->
|
||||
cmd = "echo 'first' && sleep .1 && echo 'second' && sleep .1 && echo 'third'"
|
||||
ChildProcess.exec(cmd, stdout: stdoutHandler)
|
||||
|
||||
waitsFor ->
|
||||
stdoutHandler.callCount > 2
|
||||
|
||||
runs ->
|
||||
expect(stdoutHandler.argsForCall[0][0]).toBe "first\n"
|
||||
expect(stdoutHandler.argsForCall[1][0]).toBe "second\n"
|
||||
expect(stdoutHandler.argsForCall[2][0]).toBe "third\n"
|
||||
|
||||
it "calls the options.stderr callback when new data is received on stderr", ->
|
||||
cmd = "echo '1111' >&2 && sleep .1 && echo '2222' >&2"
|
||||
ChildProcess.exec(cmd, stderr: stderrHandler)
|
||||
|
||||
waitsFor ->
|
||||
stderrHandler.callCount > 1
|
||||
|
||||
runs ->
|
||||
expect(stderrHandler.argsForCall[0][0]).toBe "1111\n"
|
||||
expect(stderrHandler.argsForCall[1][0]).toBe "2222\n"
|
||||
|
||||
describe "when the `bufferLines` option is true ", ->
|
||||
[simulateStdout, simulateStderr] = []
|
||||
|
||||
beforeEach ->
|
||||
spyOn($native, 'exec')
|
||||
ChildProcess.exec("print_the_things", bufferLines: true, stdout: stdoutHandler, stderr: stderrHandler)
|
||||
{ stdout, stderr } = $native.exec.argsForCall[0][1]
|
||||
simulateStdout = stdout
|
||||
simulateStderr = stderr
|
||||
|
||||
it "only triggers stdout callbacks with complete lines", ->
|
||||
simulateStdout """
|
||||
I am a full line
|
||||
I am part of """
|
||||
|
||||
expect(stdoutHandler).toHaveBeenCalledWith("I am a full line\n")
|
||||
stdoutHandler.reset()
|
||||
|
||||
simulateStdout """
|
||||
a line
|
||||
I am another full line\n
|
||||
"""
|
||||
|
||||
expect(stdoutHandler).toHaveBeenCalledWith """
|
||||
I am part of a line
|
||||
I am another full line\n
|
||||
"""
|
||||
|
||||
it "only triggers stderr callbacks with complete lines", ->
|
||||
simulateStderr """
|
||||
I am a full line
|
||||
I am part of """
|
||||
|
||||
expect(stderrHandler).toHaveBeenCalledWith("I am a full line\n")
|
||||
stdoutHandler.reset()
|
||||
|
||||
simulateStderr """
|
||||
a line
|
||||
I am another full line\n
|
||||
"""
|
||||
|
||||
expect(stderrHandler).toHaveBeenCalledWith """
|
||||
I am part of a line
|
||||
I am another full line\n
|
||||
"""
|
||||
|
||||
describe "when the command fails", ->
|
||||
it "executes the callback with error set to the exit status", ->
|
||||
waitsForPromise shouldReject: true, ->
|
||||
cmd = "echo 'bad' >&2 && exit 2"
|
||||
errorOutput = ''
|
||||
options =
|
||||
stderr: (data) ->
|
||||
errorOutput += data
|
||||
ChildProcess.exec(cmd, options).fail (error) ->
|
||||
expect(error.exitStatus).toBe 2
|
||||
expect(errorOutput).toBe "bad\n"
|
||||
|
||||
describe "when a command returns a large amount of data (over 10k)", ->
|
||||
originalTimeout = null
|
||||
beforeEach ->
|
||||
originalTimeout = jasmine.getEnv().defaultTimeoutInterval
|
||||
jasmine.getEnv().defaultTimeoutInterval = 1000
|
||||
|
||||
afterEach ->
|
||||
jasmine.getEnv().defaultTimeoutInterval = originalTimeout
|
||||
|
||||
it "does not block indefinitely on stdout or stderr callbacks (regression)", ->
|
||||
output = []
|
||||
|
||||
waitsForPromise ->
|
||||
cmd = "for i in {1..20000}; do echo $RANDOM; done"
|
||||
options =
|
||||
stdout: (data) -> output.push(data)
|
||||
stderr: (data) ->
|
||||
|
||||
ChildProcess.exec(cmd, options)
|
||||
|
||||
runs ->
|
||||
expect(output.length).toBeGreaterThan 1
|
||||
|
||||
describe "when the cwd option is set", ->
|
||||
it "runs the task from the specified current working directory", ->
|
||||
output = []
|
||||
|
||||
waitsForPromise ->
|
||||
options =
|
||||
cwd: "/Applications"
|
||||
stdout: (data) -> output.push(data)
|
||||
stderr: (data) ->
|
||||
|
||||
ChildProcess.exec("pwd", options)
|
||||
|
||||
runs ->
|
||||
expect(output.join('')).toBe "/Applications\n"
|
||||
@@ -1,37 +0,0 @@
|
||||
# node.js child-process
|
||||
# http://nodejs.org/docs/v0.6.3/api/child_processes.html
|
||||
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class ChildProccess
|
||||
@exec: (command, options={}) ->
|
||||
deferred = $.Deferred()
|
||||
|
||||
if options.bufferLines
|
||||
options.stdout = @bufferLines(options.stdout) if options.stdout
|
||||
options.stderr = @bufferLines(options.stderr) if options.stderr
|
||||
|
||||
$native.exec command, options, (exitStatus, stdout, stderr) ->
|
||||
options.stdout?(stdout)
|
||||
options.stderr?(stderr)
|
||||
try
|
||||
if exitStatus != 0
|
||||
deferred.reject({command, exitStatus})
|
||||
else
|
||||
deferred.resolve()
|
||||
catch e
|
||||
console.error "In ChildProccess termination callback: ", e.message
|
||||
console.error e.stack
|
||||
|
||||
deferred
|
||||
|
||||
@bufferLines: (callback) ->
|
||||
buffered = ""
|
||||
(data) ->
|
||||
buffered += data
|
||||
lastNewlineIndex = buffered.lastIndexOf('\n')
|
||||
if lastNewlineIndex >= 0
|
||||
callback(buffered.substring(0, lastNewlineIndex + 1))
|
||||
buffered = buffered.substring(lastNewlineIndex + 1)
|
||||
Reference in New Issue
Block a user