Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ async function endAllSimulatorDaemons () {
log.debug('Ending all simulator daemons');
for (let servicePattern of ['com.apple.iphonesimulator', 'com.apple.CoreSimulator']) {
log.debug(`Killing any other ${servicePattern} daemons`);
let launchCtlCommand = `launchctl list | grep ${servicePattern} | cut -f 3 | xargs -n 1 launchctl`;
try {
let stopCmd = `launchctl list | grep ${servicePattern} | cut -f 3 | xargs -n 1 launchctl stop`;
let stopCmd = `${launchCtlCommand} stop`;
await exec('bash', ['-c', stopCmd]);
} catch (err) {
log.warn(`Could not stop ${servicePattern} daemons, carrying on anyway!`);
}
try {
let removeCmd = `launchctl list | grep ${servicePattern} | cut -f 3 | xargs -n 1 launchctl remove`;
let removeCmd = `${launchCtlCommand} remove`;
await exec('bash', ['-c', removeCmd]);
} catch (err) {
log.warn(`Could not remove ${servicePattern} daemons, carrying on anyway!`);
Expand Down
15 changes: 14 additions & 1 deletion test/unit/utils-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chaiAsPromised from 'chai-as-promised';
import sinon from 'sinon';
import * as TeenProcess from 'teen_process';
import xcode from 'appium-xcode';
import { killAllSimulators } from '../../lib/utils';
import { killAllSimulators, endAllSimulatorDaemons } from '../..';


chai.should();
Expand Down Expand Up @@ -59,4 +59,17 @@ describe('util', () => {
execStub.threw().should.be.true;
});
});

describe('endAllSimulatorDaemons', () => {
it('should call exec five times to stop and remove each service', async () => {
await endAllSimulatorDaemons();
execStub.callCount.should.equal(5);
});
it('should ignore all errors', async () => {
execStub.throws();
await endAllSimulatorDaemons().should.not.be.rejected;
execStub.callCount.should.equal(5);
execStub.threw().should.be.true;
});
});
});