2013-10-21 18:23:22 +04:00
|
|
|
path = require 'path'
|
2014-02-24 05:19:00 +04:00
|
|
|
fs = require 'fs-plus'
|
2016-12-01 05:41:58 +03:00
|
|
|
temp = require('temp').track()
|
2015-09-21 20:04:01 +03:00
|
|
|
CommandInstaller = require '../src/command-installer'
|
2013-05-15 21:28:31 +04:00
|
|
|
|
2015-09-21 20:04:01 +03:00
|
|
|
describe "CommandInstaller on #darwin", ->
|
2015-09-22 01:32:14 +03:00
|
|
|
[installer, resourcesPath, installationPath, atomBinPath, apmBinPath] = []
|
2013-05-15 21:28:31 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2015-09-21 20:04:01 +03:00
|
|
|
installationPath = temp.mkdirSync("atom-bin")
|
2013-05-15 21:28:31 +04:00
|
|
|
|
2015-09-21 20:04:01 +03:00
|
|
|
resourcesPath = temp.mkdirSync('atom-app')
|
|
|
|
atomBinPath = path.join(resourcesPath, 'app', 'atom.sh')
|
|
|
|
apmBinPath = path.join(resourcesPath, 'app', 'apm', 'node_modules', '.bin', 'apm')
|
|
|
|
fs.writeFileSync(atomBinPath, "")
|
|
|
|
fs.writeFileSync(apmBinPath, "")
|
|
|
|
fs.chmodSync(atomBinPath, '755')
|
|
|
|
fs.chmodSync(apmBinPath, '755')
|
2013-05-15 21:28:31 +04:00
|
|
|
|
2015-09-21 20:04:01 +03:00
|
|
|
spyOn(CommandInstaller::, 'getResourcesDirectory').andReturn(resourcesPath)
|
|
|
|
spyOn(CommandInstaller::, 'getInstallDirectory').andReturn(installationPath)
|
2013-05-15 21:28:31 +04:00
|
|
|
|
2016-12-01 05:41:58 +03:00
|
|
|
afterEach ->
|
|
|
|
temp.cleanupSync()
|
|
|
|
|
2015-11-11 20:18:55 +03:00
|
|
|
it "shows an error dialog when installing commands interactively fails", ->
|
|
|
|
appDelegate = jasmine.createSpyObj("appDelegate", ["confirm"])
|
2017-03-11 21:05:28 +03:00
|
|
|
installer = new CommandInstaller(appDelegate)
|
|
|
|
installer.initialize("2.0.2")
|
2015-11-11 20:18:55 +03:00
|
|
|
spyOn(installer, "installAtomCommand").andCallFake (__, callback) -> callback(new Error("an error"))
|
|
|
|
|
|
|
|
installer.installShellCommandsInteractively()
|
|
|
|
|
|
|
|
expect(appDelegate.confirm).toHaveBeenCalledWith({
|
|
|
|
message: "Failed to install shell commands"
|
|
|
|
detailedMessage: "an error"
|
|
|
|
})
|
|
|
|
|
|
|
|
appDelegate.confirm.reset()
|
|
|
|
installer.installAtomCommand.andCallFake (__, callback) -> callback()
|
|
|
|
spyOn(installer, "installApmCommand").andCallFake (__, callback) -> callback(new Error("another error"))
|
|
|
|
|
|
|
|
installer.installShellCommandsInteractively()
|
|
|
|
|
|
|
|
expect(appDelegate.confirm).toHaveBeenCalledWith({
|
|
|
|
message: "Failed to install shell commands"
|
|
|
|
detailedMessage: "another error"
|
|
|
|
})
|
|
|
|
|
2015-11-11 20:19:32 +03:00
|
|
|
it "shows a success dialog when installing commands interactively succeeds", ->
|
|
|
|
appDelegate = jasmine.createSpyObj("appDelegate", ["confirm"])
|
2017-03-11 21:05:28 +03:00
|
|
|
installer = new CommandInstaller(appDelegate)
|
|
|
|
installer.initialize("2.0.2")
|
2015-11-11 20:19:32 +03:00
|
|
|
spyOn(installer, "installAtomCommand").andCallFake (__, callback) -> callback()
|
|
|
|
spyOn(installer, "installApmCommand").andCallFake (__, callback) -> callback()
|
|
|
|
|
|
|
|
installer.installShellCommandsInteractively()
|
|
|
|
|
|
|
|
expect(appDelegate.confirm).toHaveBeenCalledWith({
|
|
|
|
message: "Commands installed."
|
|
|
|
detailedMessage: "The shell commands `atom` and `apm` are installed."
|
|
|
|
})
|
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
describe "when using a stable version of atom", ->
|
|
|
|
beforeEach ->
|
2017-03-11 21:05:28 +03:00
|
|
|
installer = new CommandInstaller()
|
|
|
|
installer.initialize("2.0.2")
|
2015-09-22 01:32:14 +03:00
|
|
|
|
|
|
|
it "symlinks the atom command as 'atom'", ->
|
|
|
|
installedAtomPath = path.join(installationPath, 'atom')
|
|
|
|
|
|
|
|
expect(fs.isFileSync(installedAtomPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor (done) ->
|
|
|
|
installer.installAtomCommand(false, done)
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
expect(fs.realpathSync(installedAtomPath)).toBe fs.realpathSync(atomBinPath)
|
|
|
|
expect(fs.isExecutableSync(installedAtomPath)).toBe true
|
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'atom-beta'))).toBe false
|
|
|
|
|
|
|
|
it "symlinks the apm command as 'apm'", ->
|
2015-09-21 20:04:01 +03:00
|
|
|
installedApmPath = path.join(installationPath, 'apm')
|
|
|
|
|
|
|
|
expect(fs.isFileSync(installedApmPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor (done) ->
|
|
|
|
installer.installApmCommand(false, done)
|
2013-05-15 21:28:31 +04:00
|
|
|
|
2013-11-06 04:44:03 +04:00
|
|
|
runs ->
|
2015-09-21 20:04:01 +03:00
|
|
|
expect(fs.realpathSync(installedApmPath)).toBe fs.realpathSync(apmBinPath)
|
|
|
|
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
|
2015-09-22 01:32:14 +03:00
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'apm-beta'))).toBe false
|
|
|
|
|
|
|
|
describe "when using a beta version of atom", ->
|
|
|
|
beforeEach ->
|
2017-03-11 21:05:28 +03:00
|
|
|
installer = new CommandInstaller()
|
|
|
|
installer.initialize("2.2.0-beta.0")
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
it "symlinks the atom command as 'atom-beta'", ->
|
|
|
|
installedAtomPath = path.join(installationPath, 'atom-beta')
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
expect(fs.isFileSync(installedAtomPath)).toBeFalsy()
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
waitsFor (done) ->
|
|
|
|
installer.installAtomCommand(false, done)
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
runs ->
|
|
|
|
expect(fs.realpathSync(installedAtomPath)).toBe fs.realpathSync(atomBinPath)
|
|
|
|
expect(fs.isExecutableSync(installedAtomPath)).toBe true
|
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'atom'))).toBe false
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
it "symlinks the apm command as 'apm-beta'", ->
|
|
|
|
installedApmPath = path.join(installationPath, 'apm-beta')
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
expect(fs.isFileSync(installedApmPath)).toBeFalsy()
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
waitsFor (done) ->
|
|
|
|
installer.installApmCommand(false, done)
|
2015-09-21 20:04:01 +03:00
|
|
|
|
2015-09-22 01:32:14 +03:00
|
|
|
runs ->
|
|
|
|
expect(fs.realpathSync(installedApmPath)).toBe fs.realpathSync(apmBinPath)
|
|
|
|
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
|
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'apm'))).toBe false
|