-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand-installer-spec.coffee
124 lines (92 loc) · 4.62 KB
/
command-installer-spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
path = require 'path'
fs = require 'fs-plus'
temp = require('temp').track()
CommandInstaller = require '../src/command-installer'
describe "CommandInstaller on #darwin", ->
[installer, resourcesPath, installationPath, atomBinPath, apmBinPath] = []
beforeEach ->
installationPath = temp.mkdirSync("atom-bin")
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')
spyOn(CommandInstaller::, 'getResourcesDirectory').andReturn(resourcesPath)
spyOn(CommandInstaller::, 'getInstallDirectory').andReturn(installationPath)
afterEach ->
temp.cleanupSync()
it "shows an error dialog when installing commands interactively fails", ->
appDelegate = jasmine.createSpyObj("appDelegate", ["confirm"])
installer = new CommandInstaller(appDelegate)
installer.initialize("2.0.2")
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"
})
it "shows a success dialog when installing commands interactively succeeds", ->
appDelegate = jasmine.createSpyObj("appDelegate", ["confirm"])
installer = new CommandInstaller(appDelegate)
installer.initialize("2.0.2")
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."
})
describe "when using a stable version of atom", ->
beforeEach ->
installer = new CommandInstaller()
installer.initialize("2.0.2")
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'", ->
installedApmPath = path.join(installationPath, 'apm')
expect(fs.isFileSync(installedApmPath)).toBeFalsy()
waitsFor (done) ->
installer.installApmCommand(false, done)
runs ->
expect(fs.realpathSync(installedApmPath)).toBe fs.realpathSync(apmBinPath)
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
expect(fs.isFileSync(path.join(installationPath, 'apm-beta'))).toBe false
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'", ->
installedAtomPath = path.join(installationPath, 'atom-beta')
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'))).toBe false
it "symlinks the apm command as 'apm-beta'", ->
installedApmPath = path.join(installationPath, 'apm-beta')
expect(fs.isFileSync(installedApmPath)).toBeFalsy()
waitsFor (done) ->
installer.installApmCommand(false, done)
runs ->
expect(fs.realpathSync(installedApmPath)).toBe fs.realpathSync(apmBinPath)
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
expect(fs.isFileSync(path.join(installationPath, 'apm'))).toBe false