forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand-installer-spec.js
217 lines (188 loc) · 6.83 KB
/
command-installer-spec.js
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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')
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.prototype, 'getResourcesDirectory').andReturn(
resourcesPath
)
spyOn(CommandInstaller.prototype, 'getInstallDirectory').andReturn(
installationPath
)
})
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')
spyOn(installer, 'installAtomCommand').andCallFake((__, callback) =>
callback(new Error('an error'))
)
installer.installShellCommandsInteractively()
expect(appDelegate.confirm.mostRecentCall.args[0]).toEqual({
message: 'Failed to install shell commands',
detail: '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.mostRecentCall.args[0]).toEqual({
message: 'Failed to install shell commands',
detail: 'another error'
})
})
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')
spyOn(installer, 'installAtomCommand').andCallFake((__, callback) =>
callback(undefined, 'atom')
)
spyOn(installer, 'installApmCommand').andCallFake((__, callback) =>
callback(undefined, 'apm')
)
installer.installShellCommandsInteractively()
expect(appDelegate.confirm.mostRecentCall.args[0]).toEqual({
message: 'Commands installed.',
detail: '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'", () => {
const installedAtomPath = path.join(installationPath, 'atom')
expect(fs.isFileSync(installedAtomPath)).toBeFalsy()
waitsFor(done => {
installer.installAtomCommand(false, error => {
expect(error).toBeNull()
expect(fs.realpathSync(installedAtomPath)).toBe(
fs.realpathSync(atomBinPath)
)
expect(fs.isExecutableSync(installedAtomPath)).toBe(true)
expect(fs.isFileSync(path.join(installationPath, 'atom-beta'))).toBe(
false
)
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()
expect(fs.realpathSync(installedApmPath)).toBe(
fs.realpathSync(apmBinPath)
)
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
expect(fs.isFileSync(path.join(installationPath, 'apm-beta'))).toBe(
false
)
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()
expect(fs.realpathSync(installedAtomPath)).toBe(
fs.realpathSync(atomBinPath)
)
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()
expect(fs.realpathSync(installedApmPath)).toBe(
fs.realpathSync(apmBinPath)
)
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
expect(fs.isFileSync(path.join(installationPath, 'apm'))).toBe(false)
done()
})
})
})
})
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()
expect(fs.realpathSync(installedAtomPath)).toBe(
fs.realpathSync(atomBinPath)
)
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()
expect(fs.realpathSync(installedApmPath)).toBe(
fs.realpathSync(apmBinPath)
)
expect(fs.isExecutableSync(installedApmPath)).toBeTruthy()
expect(fs.isFileSync(path.join(installationPath, 'nightly'))).toBe(
false
)
done()
})
})
})
})
})