Add hidden --socket-path flag

This will allow integration tests to control which atom application
instance they use when creating atom windows
This commit is contained in:
Max Brunsfeld 2015-02-03 15:16:22 -08:00
parent 01bf346d0f
commit ab43b08739
2 changed files with 13 additions and 8 deletions

View File

@ -14,7 +14,7 @@ url = require 'url'
{EventEmitter} = require 'events'
_ = require 'underscore-plus'
socketPath =
DEFAULT_SOCKET_PATH =
if process.platform is 'win32'
'\\\\.\\pipe\\atom-sock'
else
@ -31,17 +31,20 @@ class AtomApplication
# Public: The entry point into the Atom application.
@open: (options) ->
options.socketPath ?= DEFAULT_SOCKET_PATH
createAtomApplication = -> new AtomApplication(options)
# FIXME: Sometimes when socketPath doesn't exist, net.connect would strangely
# take a few seconds to trigger 'error' event, it could be a bug of node
# or atom-shell, before it's fixed we check the existence of socketPath to
# speedup startup.
if (process.platform isnt 'win32' and not fs.existsSync socketPath) or options.test
if (process.platform isnt 'win32' and not fs.existsSync options.socketPath) or options.test
createAtomApplication()
return
client = net.connect {path: socketPath}, ->
client = net.connect {path: options.socketPath}, ->
client.write JSON.stringify(options), ->
client.end()
app.terminate()
@ -57,7 +60,7 @@ class AtomApplication
exit: (status) -> app.exit(status)
constructor: (options) ->
{@resourcePath, @version, @devMode, @safeMode} = options
{@resourcePath, @version, @devMode, @safeMode, @socketPath} = options
# Normalize to make sure drive letter case is consistent on Windows
@resourcePath = path.normalize(@resourcePath) if @resourcePath
@ -119,15 +122,15 @@ class AtomApplication
connection.on 'data', (data) =>
@openWithOptions(JSON.parse(data))
server.listen socketPath
server.listen @socketPath
server.on 'error', (error) -> console.error 'Application server failed', error
deleteSocketFile: ->
return if process.platform is 'win32'
if fs.existsSync(socketPath)
if fs.existsSync(@socketPath)
try
fs.unlinkSync(socketPath)
fs.unlinkSync(@socketPath)
catch error
# Ignore ENOENT errors in case the file was deleted between the exists
# check and the call to unlink sync. This occurred occasionally on CI

View File

@ -120,6 +120,7 @@ parseCommandLine = ->
options.alias('t', 'test').boolean('t').describe('t', 'Run the specified specs and exit with error code on failures.')
options.alias('v', 'version').boolean('v').describe('v', 'Print the version.')
options.alias('w', 'wait').boolean('w').describe('w', 'Wait for window to be closed before returning.')
options.string('socket-path')
args = options.argv
if args.help
@ -140,6 +141,7 @@ parseCommandLine = ->
newWindow = args['new-window']
pidToKillWhenClosed = args['pid'] if args['wait']
logFile = args['log-file']
socketPath = args['socket-path']
if args['resource-path']
devMode = true
@ -164,6 +166,6 @@ parseCommandLine = ->
# explicitly pass it by command line, see http://git.io/YC8_Ew.
process.env.PATH = args['path-environment'] if args['path-environment']
{resourcePath, pathsToOpen, executedFrom, test, version, pidToKillWhenClosed, devMode, safeMode, newWindow, specDirectory, logFile}
{resourcePath, pathsToOpen, executedFrom, test, version, pidToKillWhenClosed, devMode, safeMode, newWindow, specDirectory, logFile, socketPath}
start()