Skip to content

Commit d617574

Browse files
committed
Fix unit tests errors on macos
1 parent ef00314 commit d617574

3 files changed

Lines changed: 154 additions & 111 deletions

File tree

test/unit/model/jbds-test.js

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import path from 'path';
99
import JbdsInstall from 'browser/model/jbds';
1010
import JdkInstall from 'browser/model/jdk-install';
1111
import Logger from 'browser/services/logger';
12+
import Platform from 'browser/services/platform';
1213
import Downloader from 'browser/model/helpers/downloader';
1314
import Installer from 'browser/model/helpers/installer';
1415
import Hash from 'browser/model/helpers/hash';
@@ -28,16 +29,21 @@ describe('devstudio installer', function() {
2829
let success = () => {};
2930
let failure = () => {};
3031

31-
installerDataSvc = sinon.stub(new InstallerDataService());
32-
installerDataSvc.getRequirementByName.restore();
33-
installerDataSvc.tempDir.returns('tempDirectory');
34-
installerDataSvc.installDir.returns('installationFolder');
35-
installerDataSvc.jdkDir.returns('install/jdk8');
36-
installerDataSvc.jbdsDir.returns('installationFolder/developer-studio');
37-
installerDataSvc.cdkVagrantfileDir.returns('installationFolder/cdk/vagrant');
38-
installerDataSvc.getInstallable.returns(fakeInstall);
39-
installerDataSvc.getUsername.returns('user');
40-
installerDataSvc.getPassword.returns('passwd');
32+
function stubDataService() {
33+
let ds = sinon.stub(new InstallerDataService());
34+
ds.getRequirementByName.restore();
35+
ds.tempDir.returns('tempDirectory');
36+
ds.installDir.returns('installationFolder');
37+
ds.jdkDir.returns('install/jdk8');
38+
ds.jbdsDir.returns('installationFolder/developer-studio');
39+
ds.cdkVagrantfileDir.returns('installationFolder/cdk/vagrant');
40+
ds.getInstallable.returns(fakeInstall);
41+
ds.getUsername.returns('user');
42+
ds.getPassword.returns('passwd');
43+
return ds;
44+
}
45+
46+
installerDataSvc = stubDataService();
4147

4248
let fakeProgress;
4349

@@ -145,16 +151,25 @@ describe('devstudio installer', function() {
145151
let downloadedFile = path.join(installerDataSvc.tempDir(), 'jbds.jar');
146152
let fsextra = require('fs-extra');
147153

148-
it('should not start until JDK has finished installing', function() {
149-
let installSpy = sandbox.spy(installer, 'installAfterRequirements');
150-
let item2 = new InstallableItem('jdk', 1000, 'url', 'installFile', 'targetFolderName', installerDataSvc);
151-
item2.thenInstall(installer);
152-
153-
installer.install(fakeProgress, success, failure);
154-
155-
expect(installSpy).not.called;
156-
expect(fakeProgress.setStatus).to.have.been.calledOnce;
157-
expect(fakeProgress.setStatus).to.have.been.calledWith('Waiting for OpenJDK to finish installation');
154+
describe('on windows', function() {
155+
beforeEach(function() {
156+
sandbox.stub(Platform, 'getOS').returns('win32');
157+
})
158+
159+
it('should not start until JDK has finished installing', function() {
160+
let installerDataSvc = stubDataService();
161+
let installer = new JbdsInstall(installerDataSvc, downloadUrl, null);
162+
installer.ipcRenderer = { on: function() {} };
163+
let installSpy = sandbox.spy(installer, 'installAfterRequirements');
164+
let item2 = new InstallableItem('jdk', 1000, 'url', 'installFile', 'targetFolderName', installerDataSvc);
165+
item2.thenInstall(installer);
166+
167+
installer.install(fakeProgress, success, failure);
168+
169+
expect(installSpy).not.called;
170+
expect(fakeProgress.setStatus).to.have.been.calledOnce;
171+
expect(fakeProgress.setStatus).to.have.been.calledWith('Waiting for OpenJDK to finish installation');
172+
});
158173
});
159174

160175
it('should install once JDK has finished', function() {

test/unit/model/vagrant-test.js

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import mockfs from 'mock-fs';
77
import fs from 'fs-extra';
88
import path from 'path';
99
import VagrantInstall from 'browser/model/vagrant';
10+
import {VagrantInstallWindows} from 'browser/model/vagrant';
1011
import Logger from 'browser/services/logger';
12+
import Platform from 'browser/services/platform';
1113
import Downloader from 'browser/model/helpers/downloader';
1214
import Installer from 'browser/model/helpers/installer';
1315
import Hash from 'browser/model/helpers/hash';
@@ -27,12 +29,17 @@ describe('Vagrant installer', function() {
2729
isInstalled: function() { return false; }
2830
};
2931

30-
installerDataSvc = sinon.stub(new InstallerDataService());
31-
installerDataSvc.getRequirementByName.restore();
32-
installerDataSvc.tempDir.returns('tempDirectory');
33-
installerDataSvc.installDir.returns('installationFolder');
34-
installerDataSvc.vagrantDir.returns(path.join('installationFolder','vagrant'));
35-
installerDataSvc.getInstallable.returns(fakeInstallable);
32+
function stubDataService() {
33+
let ds = sinon.stub(new InstallerDataService());
34+
ds.getRequirementByName.restore();
35+
ds.tempDir.returns('tempDirectory');
36+
ds.installDir.returns('installationFolder');
37+
ds.vagrantDir.returns(path.join('installationFolder','vagrant'));
38+
ds.getInstallable.returns(fakeInstallable);
39+
return ds;
40+
}
41+
42+
installerDataSvc = stubDataService();
3643

3744
let fakeProgress;
3845

@@ -164,27 +171,36 @@ describe('Vagrant installer', function() {
164171

165172
it('should set progress to "Installing"', function() {
166173
sandbox.stub(Installer.prototype, 'execFile').rejects('done');
174+
sandbox.stub(Installer.prototype, 'exec').rejects('done');
167175

168176
installer.installAfterRequirements(fakeProgress, success, failure);
169177

170178
expect(fakeProgress.setStatus).to.have.been.calledOnce;
171179
expect(fakeProgress.setStatus).to.have.been.calledWith('Installing');
172180
});
173181

174-
it('should exec the downloaded file with temporary folder as target destination', function() {
175-
sandbox.stub(child_process, 'execFile').yields('done');
176-
let spy = sandbox.spy(Installer.prototype, 'execFile');
177-
installer.installAfterRequirements(fakeProgress, success, failure);
182+
describe('on windows',function() {
183+
it('should exec the downloaded file with temporary folder as target destination', function() {
184+
sandbox.stub(Platform,'getOS').returns('win32');
185+
let installer = new VagrantInstallWindows(stubDataService(), downloadUrl, null);
186+
installer.ipcRenderer = { on: function() {} };
178187

179-
expect(spy).to.have.been.called;
180-
expect(spy).calledWith('msiexec', [
181-
'/i', path.join('tempDirectory','vagrant.msi'),
182-
'VAGRANTAPPDIR=' + path.join('installationFolder','vagrant'), '/qn', '/norestart', '/Liwe',
183-
path.join('installationFolder','vagrant.log')]);
184-
});
188+
sandbox.stub(child_process, 'execFile').yields('done');
189+
let spy = sandbox.spy(Installer.prototype, 'execFile');
190+
installer.installAfterRequirements(fakeProgress, success, failure);
191+
192+
expect(spy).to.have.been.called;
193+
expect(spy).calledWith('msiexec', [
194+
'/i', path.join('tempDirectory','vagrant.msi'),
195+
'VAGRANTAPPDIR=' + path.join('installationFolder','vagrant'), '/qn', '/norestart', '/Liwe',
196+
path.join('installationFolder','vagrant.log')]);
197+
});
198+
})
185199

186200
it('should catch errors during the installation', function(done) {
187201
sandbox.stub(require('unzip'), 'Extract').throws(new Error('critical error'));
202+
sandbox.stub(child_process, 'exec').yields('done');
203+
sandbox.stub(child_process, 'execFile').yields('done');
188204

189205
try {
190206
installer.installAfterRequirements(fakeProgress, success, failure);

test/unit/model/virtualbox-test.js

Lines changed: 87 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import mockfs from 'mock-fs';
77
import fs from 'fs-extra';
88
import path from 'path';
99
import VirtualBoxInstall from 'browser/model/virtualbox';
10+
import {VirtualBoxInstallWindows} from 'browser/model/virtualbox';
1011
import Logger from 'browser/services/logger';
12+
import Platform from 'browser/services/platform';
1113
import Downloader from 'browser/model/helpers/downloader';
1214
import Installer from 'browser/model/helpers/installer';
1315
import Hash from 'browser/model/helpers/hash';
@@ -139,40 +141,101 @@ describe('Virtualbox installer', function() {
139141
describe('installation', function() {
140142
let downloadedFile = path.join('tempDirectory', 'virtualbox.exe');
141143

142-
it('should execute the silent extract', function() {
143-
sandbox.stub(child_process, 'execFile').yields('done');
144+
describe('on windows', function() {
145+
let installer;
146+
beforeEach(function() {
147+
sandbox.stub(Platform, 'getOS').returns('win32');
148+
installer = new VirtualBoxInstallWindows(version, revision, installerDataSvc, downloadUrl, null);
149+
installer.ipcRenderer = { on: function() {} };
150+
})
151+
152+
it('should execute the silent extract', function() {
153+
sandbox.stub(child_process, 'execFile').yields('done');
154+
155+
let data = [
156+
'--extract',
157+
'-path',
158+
installerDataSvc.tempDir(),
159+
'--silent'
160+
];
144161

145-
let data = [
146-
'--extract',
147-
'-path',
148-
installerDataSvc.tempDir(),
149-
'--silent'
150-
];
162+
let spy = sandbox.spy(Installer.prototype, 'execFile');
163+
let item2 = new InstallableItem('jdk', 1000, 'url', 'installFile', 'targetFolderName', installerDataSvc);
164+
item2.setInstallComplete();
165+
item2.thenInstall(installer);
166+
installer.install(fakeProgress, success, failure);
151167

152-
let spy = sandbox.spy(Installer.prototype, 'execFile');
153-
let item2 = new InstallableItem('jdk', 1000, 'url', 'installFile', 'targetFolderName', installerDataSvc);
154-
item2.setInstallComplete();
155-
item2.thenInstall(installer);
156-
installer.install(fakeProgress, success, failure);
168+
expect(spy).to.have.been.called;
169+
expect(spy).calledWith(downloadedFile, data);
170+
});
157171

158-
expect(spy).to.have.been.called;
159-
expect(spy).calledWith(downloadedFile, data);
160-
});
172+
it('setup should wait for all downloads to complete', function() {
173+
let helper = new Installer('virtualbox', fakeProgress);
174+
let spy = sandbox.spy(installer, 'installMsi');
175+
176+
installerDataSvc.downloading = true;
161177

162-
it('setup should wait for all downloads to complete', function() {
163-
let helper = new Installer('virtualbox', fakeProgress);
164-
let spy = sandbox.spy(installer, 'installMsi');
178+
installer.configure(helper);
165179

166-
installerDataSvc.downloading = true;
180+
expect(fakeProgress.setStatus).calledWith('Waiting for all downloads to finish');
181+
expect(spy).not.called;
182+
});
167183

168-
installer.configure(helper);
184+
describe('configure', function() {
185+
it('should call installMsi if all downloads have finished', function() {
186+
let helper = new Installer('virtualbox', fakeProgress);
187+
let spy = sandbox.spy(installer, 'installMsi');
188+
sandbox.stub(child_process, 'execFile').yields();
169189

170-
expect(fakeProgress.setStatus).calledWith('Waiting for all downloads to finish');
171-
expect(spy).not.called;
172-
});
190+
installerDataSvc.downloading = false;
191+
192+
installer.configure(helper);
193+
expect(spy).calledOnce;
194+
});
195+
});
196+
197+
describe('installMsi', function() {
198+
let helper, resolve, reject;
199+
200+
beforeEach(function() {
201+
helper = new Installer('virtualbox', fakeProgress, success, failure);
202+
sandbox.stub(child_process, 'execFile').yields();
203+
resolve = (argument) => { Promise.resolve(argument); };
204+
reject = (argument) => { Promise.reject(argument); };
205+
});
206+
207+
it('should set progress to "Installing"', function() {
208+
installer.installMsi(helper, resolve, reject);
209+
210+
expect(fakeProgress.setStatus).to.have.been.calledOnce;
211+
expect(fakeProgress.setStatus).to.have.been.calledWith('Installing');
212+
});
213+
214+
it('should execute the msi installer', function() {
215+
let spy = sandbox.spy(Installer.prototype, 'execFile');
216+
217+
let msiFile = path.join(installerDataSvc.tempDir(), 'VirtualBox-' + version + '-r' + revision + '-MultiArch_amd64.msi');
218+
let opts = [
219+
'/i',
220+
msiFile,
221+
'INSTALLDIR=' + installerDataSvc.virtualBoxDir(),
222+
'/qn',
223+
'/norestart',
224+
'/Liwe',
225+
path.join(installerDataSvc.installDir(), 'vbox.log')
226+
];
227+
228+
installer.installMsi(helper, resolve, reject);
229+
230+
expect(spy).to.have.been.calledOnce;
231+
expect(spy).to.have.been.calledWith('msiexec', opts);
232+
});
233+
});
234+
})
173235

174236
it('should catch errors during the installation', function(done) {
175237
sandbox.stub(child_process, 'execFile').yields(new Error('critical error'));
238+
sandbox.stub(child_process, 'exec').yields(new Error('critical error'));
176239
let item2 = new InstallableItem('jdk', 1000, 'url', 'installFile', 'targetFolderName', installerDataSvc);
177240
item2.setInstallComplete();
178241
item2.thenInstall(installer);
@@ -195,57 +258,6 @@ describe('Virtualbox installer', function() {
195258

196259
expect(spy).to.have.not.been.called;
197260
});
198-
199-
describe('configure', function() {
200-
it('should call installMsi if all downloads have finished', function() {
201-
let helper = new Installer('virtualbox', fakeProgress);
202-
let spy = sandbox.spy(installer, 'installMsi');
203-
sandbox.stub(child_process, 'execFile').yields();
204-
205-
installerDataSvc.downloading = false;
206-
207-
installer.configure(helper);
208-
expect(spy).calledOnce;
209-
});
210-
});
211-
212-
describe('installMsi', function() {
213-
let helper, resolve, reject;
214-
215-
beforeEach(function() {
216-
helper = new Installer('virtualbox', fakeProgress, success, failure);
217-
sandbox.stub(child_process, 'execFile').yields();
218-
resolve = (argument) => { Promise.resolve(argument); };
219-
reject = (argument) => { Promise.reject(argument); };
220-
});
221-
222-
it('should set progress to "Installing"', function() {
223-
installer.installMsi(helper, resolve, reject);
224-
225-
expect(fakeProgress.setStatus).to.have.been.calledOnce;
226-
expect(fakeProgress.setStatus).to.have.been.calledWith('Installing');
227-
});
228-
229-
it('should execute the msi installer', function() {
230-
let spy = sandbox.spy(Installer.prototype, 'execFile');
231-
232-
let msiFile = path.join(installerDataSvc.tempDir(), 'VirtualBox-' + version + '-r' + revision + '-MultiArch_amd64.msi');
233-
let opts = [
234-
'/i',
235-
msiFile,
236-
'INSTALLDIR=' + installerDataSvc.virtualBoxDir(),
237-
'/qn',
238-
'/norestart',
239-
'/Liwe',
240-
path.join(installerDataSvc.installDir(), 'vbox.log')
241-
];
242-
243-
installer.installMsi(helper, resolve, reject);
244-
245-
expect(spy).to.have.been.calledOnce;
246-
expect(spy).to.have.been.calledWith('msiexec', opts);
247-
});
248-
});
249261
});
250262

251263
describe('detection', function() {

0 commit comments

Comments
 (0)