2017-08-18 23:10:05 +03:00
|
|
|
const path = require('path')
|
|
|
|
const fs = require('fs-plus')
|
|
|
|
const temp = require('temp').track()
|
|
|
|
const CommandInstaller = require('../src/command-installer')
|
|
|
|
|
|
|
|
describe('CommandInstaller on #darwin', () => {
|
|
|
|
let installer, resourcesPath, installationPath, atomBinPath, apmBinPath
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
installationPath = temp.mkdirSync('atom-bin')
|
|
|
|
|
|
|
|
resourcesPath = temp.mkdirSync('atom-app')
|
|
|
|
atomBinPath = path.join(resourcesPath, 'app', 'atom.sh')
|
2019-02-22 10:55:17 +03:00
|
|
|
apmBinPath = path.join(
|
|
|
|
resourcesPath,
|
|
|
|
'app',
|
|
|
|
'apm',
|
|
|
|
'node_modules',
|
|
|
|
'.bin',
|
|
|
|
'apm'
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
fs.writeFileSync(atomBinPath, '')
|
|
|
|
fs.writeFileSync(apmBinPath, '')
|
|
|
|
fs.chmodSync(atomBinPath, '755')
|
|
|
|
fs.chmodSync(apmBinPath, '755')
|
|
|
|
|
2019-02-22 10:55:17 +03:00
|
|
|
spyOn(CommandInstaller.prototype, 'getResourcesDirectory').andReturn(
|
|
|
|
resourcesPath
|
|
|
|
)
|
|
|
|
spyOn(CommandInstaller.prototype, 'getInstallDirectory').andReturn(
|
|
|
|
installationPath
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
try {
|
|
|
|
temp.cleanupSync()
|
|
|
|
} catch (error) {}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows an error dialog when installing commands interactively fails', () => {
|
|
|
|
const appDelegate = jasmine.createSpyObj('appDelegate', ['confirm'])
|
|
|
|
installer = new CommandInstaller(appDelegate)
|
|
|
|
installer.initialize('2.0.2')
|
2019-02-22 10:55:17 +03:00
|
|
|
spyOn(installer, 'installAtomCommand').andCallFake((__, callback) =>
|
|
|
|
callback(new Error('an error'))
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
|
|
|
|
installer.installShellCommandsInteractively()
|
|
|
|
|
2017-11-19 03:02:23 +03:00
|
|
|
expect(appDelegate.confirm.mostRecentCall.args[0]).toEqual({
|
2017-08-18 23:10:05 +03:00
|
|
|
message: 'Failed to install shell commands',
|
2017-11-19 03:02:23 +03:00
|
|
|
detail: 'an error'
|
2017-08-18 23:10:05 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
appDelegate.confirm.reset()
|
|
|
|
installer.installAtomCommand.andCallFake((__, callback) => callback())
|
2019-02-22 10:55:17 +03:00
|
|
|
spyOn(installer, 'installApmCommand').andCallFake((__, callback) =>
|
|
|
|
callback(new Error('another error'))
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
|
|
|
|
installer.installShellCommandsInteractively()
|
|
|
|
|
2017-11-19 03:02:23 +03:00
|
|
|
expect(appDelegate.confirm.mostRecentCall.args[0]).toEqual({
|
2017-08-18 23:10:05 +03:00
|
|
|
message: 'Failed to install shell commands',
|
2017-11-19 03:02:23 +03:00
|
|
|
detail: 'another error'
|
2017-08-18 23:10:05 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('shows a success dialog when installing commands interactively succeeds', () => {
|
|
|
|
const appDelegate = jasmine.createSpyObj('appDelegate', ['confirm'])
|
|
|
|
installer = new CommandInstaller(appDelegate)
|
|
|
|
installer.initialize('2.0.2')
|
2019-02-22 10:55:17 +03:00
|
|
|
spyOn(installer, 'installAtomCommand').andCallFake((__, callback) =>
|
|
|
|
callback(undefined, 'atom')
|
|
|
|
)
|
|
|
|
spyOn(installer, 'installApmCommand').andCallFake((__, callback) =>
|
|
|
|
callback(undefined, 'apm')
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
|
|
|
|
installer.installShellCommandsInteractively()
|
|
|
|
|
2017-11-19 03:02:23 +03:00
|
|
|
expect(appDelegate.confirm.mostRecentCall.args[0]).toEqual({
|
2017-08-18 23:10:05 +03:00
|
|
|
message: 'Commands installed.',
|
2017-11-19 03:02:23 +03:00
|
|
|
detail: 'The shell commands `atom` and `apm` are installed.'
|
2017-08-18 23:10:05 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when using a stable version of atom', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
installer = new CommandInstaller()
|
|
|
|
installer.initialize('2.0.2')
|
|
|
|
})
|
|
|
|
|
|
|
|
it("symlinks the atom command as 'atom'", () => {
|
|
|
|
const installedAtomPath = path.join(installationPath, 'atom')
|
|
|
|
expect(fs.isFileSync(installedAtomPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor(done => {
|
|
|
|
installer.installAtomCommand(false, error => {
|
|
|
|
expect(error).toBeNull()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.realpathSync(installedAtomPath)).toBe(
|
|
|
|
fs.realpathSync(atomBinPath)
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
expect(fs.isExecutableSync(installedAtomPath)).toBe(true)
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'atom-beta'))).toBe(
|
|
|
|
false
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("symlinks the apm command as 'apm'", () => {
|
|
|
|
const installedApmPath = path.join(installationPath, 'apm')
|
|
|
|
expect(fs.isFileSync(installedApmPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor(done => {
|
|
|
|
installer.installApmCommand(false, error => {
|
|
|
|
expect(error).toBeNull()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.realpathSync(installedApmPath)).toBe(
|
|
|
|
fs.realpathSync(apmBinPath)
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'apm-beta'))).toBe(
|
|
|
|
false
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when using a beta version of atom', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
installer = new CommandInstaller()
|
|
|
|
installer.initialize('2.2.0-beta.0')
|
|
|
|
})
|
|
|
|
|
|
|
|
it("symlinks the atom command as 'atom-beta'", () => {
|
|
|
|
const installedAtomPath = path.join(installationPath, 'atom-beta')
|
|
|
|
expect(fs.isFileSync(installedAtomPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor(done => {
|
|
|
|
installer.installAtomCommand(false, error => {
|
|
|
|
expect(error).toBeNull()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.realpathSync(installedAtomPath)).toBe(
|
|
|
|
fs.realpathSync(atomBinPath)
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
expect(fs.isExecutableSync(installedAtomPath)).toBe(true)
|
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'atom'))).toBe(false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("symlinks the apm command as 'apm-beta'", () => {
|
|
|
|
const installedApmPath = path.join(installationPath, 'apm-beta')
|
|
|
|
expect(fs.isFileSync(installedApmPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor(done => {
|
|
|
|
installer.installApmCommand(false, error => {
|
|
|
|
expect(error).toBeNull()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.realpathSync(installedApmPath)).toBe(
|
|
|
|
fs.realpathSync(apmBinPath)
|
|
|
|
)
|
2017-08-18 23:10:05 +03:00
|
|
|
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
|
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'apm'))).toBe(false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2018-06-30 01:32:29 +03:00
|
|
|
|
|
|
|
describe('when using a nightly version of atom', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
installer = new CommandInstaller()
|
|
|
|
installer.initialize('2.2.0-nightly0')
|
|
|
|
})
|
|
|
|
|
|
|
|
it("symlinks the atom command as 'atom-nightly'", () => {
|
|
|
|
const installedAtomPath = path.join(installationPath, 'atom-nightly')
|
|
|
|
expect(fs.isFileSync(installedAtomPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor(done => {
|
|
|
|
installer.installAtomCommand(false, error => {
|
|
|
|
expect(error).toBeNull()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.realpathSync(installedAtomPath)).toBe(
|
|
|
|
fs.realpathSync(atomBinPath)
|
|
|
|
)
|
2018-06-30 01:32:29 +03:00
|
|
|
expect(fs.isExecutableSync(installedAtomPath)).toBe(true)
|
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'atom'))).toBe(false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("symlinks the apm command as 'apm-nightly'", () => {
|
|
|
|
const installedApmPath = path.join(installationPath, 'apm-nightly')
|
|
|
|
expect(fs.isFileSync(installedApmPath)).toBeFalsy()
|
|
|
|
|
|
|
|
waitsFor(done => {
|
|
|
|
installer.installApmCommand(false, error => {
|
|
|
|
expect(error).toBeNull()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.realpathSync(installedApmPath)).toBe(
|
|
|
|
fs.realpathSync(apmBinPath)
|
|
|
|
)
|
2018-06-30 01:32:29 +03:00
|
|
|
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
|
2019-02-22 10:55:17 +03:00
|
|
|
expect(fs.isFileSync(path.join(installationPath, 'nightly'))).toBe(
|
|
|
|
false
|
|
|
|
)
|
2018-06-30 01:32:29 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-08-18 23:10:05 +03:00
|
|
|
})
|